deep-combination
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

deep-combination

codecov

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.

/deep-combination/

    Package Sidebar

    Install

    npm i deep-combination

    Weekly Downloads

    2

    Version

    0.0.2

    License

    MIT

    Unpacked Size

    220 kB

    Total Files

    17

    Last publish

    Collaborators

    • lekoleko