Skip to content

Commit 7aa08d8

Browse files
committed
Simplify coerce functions for boolean and subplotId
1 parent 51fc434 commit 7aa08d8

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

src/lib/coerce.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,8 @@ exports.valObjectMeta = {
8888
requiredOpts: [],
8989
otherOpts: ['dflt', 'arrayOk'],
9090
coerceFunction: function(v, propOut, dflt, opts) {
91-
function isBoolean(value) {
92-
return value === true || value === false;
93-
}
94-
95-
if (opts.arrayOk && isArrayOrTypedArray(v) && v.length > 0 && v.every(isBoolean)) {
96-
propOut.set(v);
97-
} else if(isBoolean(v)) {
91+
const isBoolean = value => value === true || value === false;
92+
if (isBoolean(v) || (opts.arrayOk && Array.isArray(v) && v.length > 0 && v.every(isBoolean))) {
9893
propOut.set(v);
9994
} else {
10095
propOut.set(dflt);
@@ -238,9 +233,7 @@ exports.valObjectMeta = {
238233
coerceFunction: function(v, propOut, dflt, opts) {
239234
var regex = opts.regex || counterRegex(dflt);
240235
const isSubplotId = value => typeof value === 'string' && regex.test(value);
241-
if (opts.arrayOk && isArrayOrTypedArray(v) && v.length > 0 && v.every(isSubplotId)) {
242-
propOut.set(v);
243-
} else if(isSubplotId(v)) {
236+
if (isSubplotId(v) || (opts.arrayOk && isArrayOrTypedArray(v) && v.length > 0 && v.every(isSubplotId))) {
244237
propOut.set(v);
245238
} else {
246239
propOut.set(dflt);

0 commit comments

Comments
 (0)