json-combine

2.0.0 • Public • Published

json-combine

Generate every possible combination of values

Build Status Deps NPM version Downloads

Get help on Codementor available-for-advisory extra

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

Readme

Keywords

none

Package Sidebar

Install

npm i json-combine

Weekly Downloads

0

Version

2.0.0

License

MIT

Last publish

Collaborators

  • fgribreau