Skip to content

Commit

Permalink
fix(utils): permutation helper (#7355)
Browse files Browse the repository at this point in the history
* fix permutation helper

* fix typo
  • Loading branch information
mtrezza committed Apr 16, 2021
1 parent 484dc12 commit 91be6bb
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Utils.js
Expand Up @@ -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.
Expand All @@ -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);
Expand Down Expand Up @@ -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}`;
}
}
Expand Down

0 comments on commit 91be6bb

Please sign in to comment.