https://github.com/corentinth/kombi
Simple object and array cartesian combination generator (for node, typescript and the browser)
https://github.com/corentinth/kombi
Last synced: 9 months ago
JSON representation
Simple object and array cartesian combination generator (for node, typescript and the browser)
- Host: GitHub
- URL: https://github.com/corentinth/kombi
- Owner: CorentinTh
- License: mit
- Created: 2021-03-26T10:26:17.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-03-26T22:12:20.000Z (almost 5 years ago)
- Last Synced: 2025-03-13T13:19:29.377Z (10 months ago)
- Language: TypeScript
- Homepage:
- Size: 152 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README

[](https://www.npmjs.com/package/kombi)
[](https://github.com/CorentinTh/kombi/actions?query=workflow%3A%22Node+CI%22)
[](https://codecov.io/gh/CorentinTh/kombi)
[](https://www.npmjs.com/package/kombi)
[](https://github.com/CorentinTh/kombi/blob/master/package.json)
[](https://www.npmjs.com/package/kombi)
[](LICENSE)
Simple object and array cartesian combination generator (for node, typescript and the browser). Kombi will generate every combination between the sets of value given as parameters.
## Installation
### JS / Typescript / Node JS
**Kombi** can be installed using yarn or npm.
```bash
npm install kombi
# or
yarn add kombi
```
And import :
```javascript
// EMAScript import
import {kombi} from 'kombi';
// Or Common JS:
const {kombi} = require('kombi');
// and used...
const obj = {
a: [1, 2, 3],
b: ['a', 'b']
}
const mergedObj = kombi(obj)
console.log(mergedObj)
/*
[
{a: 1, b: 'a'},
{a: 1, b: 'b'},
{a: 2, b: 'a'},
{a: 2, b: 'b'},
{a: 3, b: 'a'},
{a: 3, b: 'b'},
]
*/
```
### Browser
You can use the CDN:
```html
```
And everything is globally accessible and **prefixed with `Kombi`**:
```javascript
const kombi = new Kombi.kombi(obj)
```
## Usage
### Combinate object with array properties
```javascript
const result = kombi({
a: [1, 2, 3, 4],
b: ['a', 'b', 'c', 'd'],
})
/*
result = [
{a: 1, b: 'a'}, {a: 1, b: 'b'}, {a: 1, b: 'c'}, {a: 1, b: 'd'},
{a: 2, b: 'a'}, {a: 2, b: 'b'}, {a: 2, b: 'c'}, {a: 2, b: 'd'},
{a: 3, b: 'a'}, {a: 3, b: 'b'}, {a: 3, b: 'c'}, {a: 3, b: 'd'},
{a: 4, b: 'a'}, {a: 4, b: 'b'}, {a: 4, b: 'c'}, {a: 4, b: 'd'}
]
*/
```
### Combinate array of arrays
```javascript
const result = kombi([
[1, 2, 3, 4],
['a', 'b', 'c'],
])
/*
result = [
[1, 'a'], [1, 'b'], [1, 'c'],
[2, 'a'], [2, 'b'], [2, 'c'],
[3, 'a'], [3, 'b'], [3, 'c'],
[4, 'a'], [4, 'b'], [4, 'c']
]
*/
```
## Roadmap
* Improve documentation
* Add more unit test
* Allow single parameters as input, like :
```javascript
const result = kombi({
a: [1, 2, 3, 4],
b: ['a', 'b', 'c', 'd'],
c: 'foo'
})
```
* Create benchmark
## Contribute
**Pull requests are welcome !** Feel free to contribute.
## Credits
Coded with ❤️ by [Corentin Thomasset](//corentin-thomasset.fr).
## License
This project is under the [MIT license](LICENSE).