2.0.0 • Published 7 years ago

json-combine v2.0.0

Weekly downloads
2
License
MIT
Repository
-
Last release
7 years ago

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