Skip to content

Commit 8d2227b

Browse files
committed
fix boolean assignment
1 parent 2e9a207 commit 8d2227b

File tree

3 files changed

+43
-19
lines changed

3 files changed

+43
-19
lines changed

src/config.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,9 @@ export default class Config {
123123
}
124124
break;
125125
case "landscape":
126-
if (
127-
typeof params[param] === "string" ||
128-
typeof params[param] === "boolean"
129-
) {
126+
if (typeof params[param] === "string") {
127+
this.landscape = ["true", "1"].includes(params[param]);
128+
} else if (typeof params[param] === "boolean") {
130129
this.landscape = params[param];
131130
}
132131
break;
@@ -150,10 +149,9 @@ export default class Config {
150149
}
151150
break;
152151
case "base64":
153-
if (
154-
typeof params[param] === "string" ||
155-
typeof params[param] === "boolean"
156-
) {
152+
if (typeof params[param] === "string") {
153+
this.base64 = ["true", "1"].includes(params[param]);
154+
} else if (typeof params[param] === "boolean") {
157155
this.base64 = params[param];
158156
}
159157
break;

test/config.boolean.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import assert from "assert";
2+
import Config from "../src/config";
3+
4+
describe("Boolean parameters", function () {
5+
describe("javascript", function () {
6+
it("Passing a boolean", function () {
7+
const config = new Config({ javascript: true });
8+
assert.equal(config.javascript, true);
9+
});
10+
it("Passing a string", function () {
11+
const config = new Config({ javascript: "true" });
12+
assert.equal(config.javascript, true);
13+
});
14+
});
15+
16+
describe("landscape", function () {
17+
it("Passing a boolean", function () {
18+
const config = new Config({ landscape: true });
19+
assert.equal(config.landscape, true);
20+
});
21+
it("Passing a string", function () {
22+
const config = new Config({ landscape: "true" });
23+
assert.equal(config.landscape, true);
24+
});
25+
});
26+
27+
describe("base64", function () {
28+
it("Passing a boolean", function () {
29+
const config = new Config({ base64: true });
30+
assert.equal(config.base64, true);
31+
});
32+
it("Passing a string", function () {
33+
const config = new Config({ base64: "true" });
34+
assert.equal(config.base64, true);
35+
});
36+
});
37+
});

test/config.others.test.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,6 @@ describe("Others", function () {
2424
});
2525
});
2626

27-
describe("javascript", function () {
28-
it("Passing a boolean", function () {
29-
const config = new Config({ javascript: true });
30-
assert.equal(config.javascript, true);
31-
});
32-
it("Passing a string", function () {
33-
const config = new Config({ javascript: "true" });
34-
assert.equal(config.javascript, true);
35-
});
36-
});
37-
3827
describe("format", function () {
3928
it("Should accept lowercase", function () {
4029
const config = new Config({ format: "tabloid" });

0 commit comments

Comments
 (0)