0.0.2 • Published 4 years ago

deep-combination v0.0.2

Weekly downloads
71
License
MIT
Repository
-
Last release
4 years ago

deep-combination

npm.io codecov npm.io npm.io

Generate pair of all combination with type-safe.

Install

npm install deep-combination

Usage

import { createCombinator } from "deep-combination";

const browsers = ["chrome", "firefox", "webkit"];
const devices = ["laptop", "mobile"];
const locales = ["en-US", "ja-JP"];

const combinator = createCombinator()
  .addDimention(browsers)
  .addDimention(devices)
  .addDimention(locales);

// You can get pairs via for-of statement
for (let [browser, device, locale] of combinator) {
  console.log([browser, device, locale]);
  // => ['chrome', 'laptop', 'en-US'], ['chrome', 'laptop', 'ja-JP']...
}

// Or you can get list of pairs from Array.from
const pairs = Array.from(combinator);
// => [['chrome', 'laptop', 'en-US'], ['chrome', 'laptop', 'ja-JP'], ...]

TypeScript Playground

Limitation

Currently, type definition supports less than 20 dimentions.
Runtime is OK but type is not recognized.

Contribution

  1. Fork this repository
  2. Write your code
  3. Run tests
  4. Create pull request to master branch

Development

git clone git@github.com:Leko/deep-combination.git
cd deep-combination
npm i

License

This package under MIT license.