json-combine
v2.0.0
Published
Generate every possible combination
Downloads
6
Readme
json-combine
Generate every possible combination of values
npm
npm install json-combine --save
usage
const {flatten, combine} = require('json-combine');
// mutation to apply
const mutations = [
{
key: 'a.b.c',
values:[true, false]
},
{
key: 'a.b.d.e',
values:[1, 2, 3]
},
];
// base object
const template = {
a:{
b:{
c: false,
d:{
e: 0
}
}
}
};
console.log(combine(flatten(mutations), template));
Outputs an array of every possible combinations :
[
{
"a": {
"b": {
"c": true,
"d": {
"e": 1
}
}
}
},
{
"a": {
"b": {
"c": true,
"d": {
"e": 2
}
}
}
},
{
"a": {
"b": {
"c": true,
"d": {
"e": 3
}
}
}
},
{
"a": {
"b": {
"c": false,
"d": {
"e": 1
}
}
}
},
{
"a": {
"b": {
"c": false,
"d": {
"e": 2
}
}
}
},
{
"a": {
"b": {
"c": false,
"d": {
"e": 3
}
}
}
}
]
test
npm test