https://github.com/fgribreau/json-combine
Generate every possible combination of values
https://github.com/fgribreau/json-combine
combinations json
Last synced: 4 months ago
JSON representation
Generate every possible combination of values
- Host: GitHub
- URL: https://github.com/fgribreau/json-combine
- Owner: FGRibreau
- Created: 2017-10-17T21:30:55.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-12T08:23:42.000Z (over 3 years ago)
- Last Synced: 2025-08-04T21:10:40.700Z (11 months ago)
- Topics: combinations, json
- Language: JavaScript
- Homepage: https://twitter.com/FGRibreau
- Size: 124 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# json-combine
### Generate every possible combination of values
[](https://circleci.com/gh/FGRibreau/json-combine/) [](https://coveralls.io/github/FGRibreau/json-combine?branch=master) [](https://david-dm.org/FGRibreau/json-combine) [](http://badge.fury.io/js/json-combine)
[](https://www.codementor.io/francois-guillaume-ribreau?utm_source=github&utm_medium=button&utm_term=francois-guillaume-ribreau&utm_campaign=github) [](http://bit.ly/2c7uFJq)  [](https://join.slack.com/t/fgribreau/shared_invite/zt-edpjwt2t-Zh39mDUMNQ0QOr9qOj~jrg)
## npm
```
npm install json-combine --save
```
## usage
```js
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 :
```js
[
{
"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
```