From 7eb840d410ce8e71ccdaf61daae1782abff34452 Mon Sep 17 00:00:00 2001 From: Manuel Trezza <5673677+mtrezza@users.noreply.github.com> Date: Fri, 16 Apr 2021 22:44:13 +0200 Subject: [PATCH 1/2] fix permutation helper --- src/Utils.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Utils.js b/src/Utils.js index a7833f5727..9c30d0ae08 100644 --- a/src/Utils.js +++ b/src/Utils.js @@ -130,6 +130,23 @@ class Utils { /** * Creates an object with all permutations of the original keys. + * For example, this definition: + * ``` + * { + * a: [true, false], + * b: [1, 2], + * c: ["x"] + * } + * ``` + * permutates to: + * ``` + * [ + * { a: true, b: 1, c: x }, + * { a: true, b: 2, c: x }, + * { a: false, b: 1, c: x }, + * { a: false, b: 2, c: x } + * ] + * ``` * @param {Object} object The object to permutate. * @param {Integer} [index=0] The current key index. * @param {Object} [current={}] The current result entry being composed. @@ -145,7 +162,7 @@ class Utils { const nextIndex = index + 1; if (nextIndex < keys.length) { - this.getObjectKeyPermutations(object, nextIndex, current, results); + Utils.getObjectKeyPermutations(object, nextIndex, current, results); } else { const result = Object.assign({}, current); results.push(result); @@ -178,7 +195,7 @@ class Utils { const type = types[key]; const isOptional = !!type.o; const param = params[key]; - if (!(isOptional && param == null) && (!type.v(param))) { + if (!(isOptional && param == null) && !type.v(param)) { throw `Invalid parameter ${key} must be of type ${type.t} but is ${typeof param}`; } } From 7b7efa760a3ac28daa71b9d75a31fad815450fbf Mon Sep 17 00:00:00 2001 From: Manuel Trezza <5673677+mtrezza@users.noreply.github.com> Date: Fri, 16 Apr 2021 22:47:28 +0200 Subject: [PATCH 2/2] fix typo --- src/Utils.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Utils.js b/src/Utils.js index 9c30d0ae08..e78d7ddd6c 100644 --- a/src/Utils.js +++ b/src/Utils.js @@ -135,16 +135,16 @@ class Utils { * { * a: [true, false], * b: [1, 2], - * c: ["x"] + * c: ['x'] * } * ``` * permutates to: * ``` * [ - * { a: true, b: 1, c: x }, - * { a: true, b: 2, c: x }, - * { a: false, b: 1, c: x }, - * { a: false, b: 2, c: x } + * { a: true, b: 1, c: 'x' }, + * { a: true, b: 2, c: 'x' }, + * { a: false, b: 1, c: 'x' }, + * { a: false, b: 2, c: 'x' } * ] * ``` * @param {Object} object The object to permutate.