An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# json-combine

### Generate every possible combination of values

[![Build Status](https://img.shields.io/circleci/project/FGRibreau/json-combine.svg)](https://circleci.com/gh/FGRibreau/json-combine/) [![Coverage Status](https://img.shields.io/coveralls/FGRibreau/json-combine/master.svg)](https://coveralls.io/github/FGRibreau/json-combine?branch=master) [![Deps]( https://img.shields.io/david/FGRibreau/json-combine.svg)](https://david-dm.org/FGRibreau/json-combine) [![NPM version](https://img.shields.io/npm/v/json-combine.svg)](http://badge.fury.io/js/json-combine)

[![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/francois-guillaume-ribreau?utm_source=github&utm_medium=button&utm_term=francois-guillaume-ribreau&utm_campaign=github) [![available-for-advisory](https://img.shields.io/badge/available%20for%20advising-yes-ff69b4.svg?)](http://bit.ly/2c7uFJq) ![extra](https://img.shields.io/badge/actively%20maintained-yes-ff69b4.svg?) [![Slack](https://img.shields.io/badge/Slack-Join%20our%20tech%20community-17202A?logo=slack)](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
```