Skip to content

Latest commit

 

History

History
133 lines (114 loc) · 5.21 KB

README.md

File metadata and controls

133 lines (114 loc) · 5.21 KB

Setation (ES)

⚖️ MIT

GitHub: hugoalh/setation-es JSR: @hugoalh/setation NPM: @hugoalh/setation

An ES (JavaScript & TypeScript) module to list permutations or combinations from the collection or set.

🔰 Begin

🎯 Targets

Remote JSR NPM
Bun >= v1.1.0 ✔️
Cloudflare Workers ✔️
Deno >= v1.42.0 ✔️ ✔️ ✔️
NodeJS >= v16.13.0 ✔️

Note

  • It is possible to use this module in other methods/ways which not listed in here, however those methods/ways are not officially supported, and should beware maybe cause security issues.

#️⃣ Resources Identifier

  • Remote - GitHub Raw:
    https://raw.githubusercontent.com/hugoalh/setation-es/{Tag}/mod.ts
    
  • JSR:
    [jsr:]@hugoalh/setation[@{Tag}]
    
  • NPM:
    [npm:]@hugoalh/setation[@{Tag}]
    

Note

  • For usage of remote resources, it is recommended to import the entire module with the main path mod.ts, however it is also able to import part of the module with sub path if available, but do not import if:

    • it's path has an underscore prefix (e.g.: _foo.ts, _util/bar.ts), or
    • it is a benchmark or test file (e.g.: foo.bench.ts, foo.test.ts), or
    • it's symbol has an underscore prefix (e.g.: _bar, _foo).

    These elements are not considered part of the public API, thus no stability is guaranteed for them.

  • For usage of JSR or NPM resources, it is recommended to import the entire module with the main entrypoint, however it is also able to import part of the module with sub entrypoint if available, please visit the file jsr.jsonc property exports for available sub entrypoints.

  • It is recommended to use this module with tag for immutability.

🛡️ Runtime Permissions

This module does not request any runtime permission.

🧩 APIs

  • function combinationCollection<V>(item: { [x: string]: V[]; }): Generator<{ [x: string]: V; }>;
    function combinationCollection<K, V>(item: Map<K, V[]>): Generator<Map<K, V>>;
    function combinationCollection<V>(item: Record<string, V[]>): Generator<Record<string, V>>;
  • function combinationSet<T>(set: readonly T[] | Set<T>, size: number | number[] | SetationSetSizeRange, options?: SetationSetOptions): Generator<T[]>
  • function permutationSet<T>(set: readonly T[] | Set<T>, size: number | number[] | SetationSetSizeRange, options?: SetationSetOptions): Generator<T[]>

Note

✍️ Examples

  • const item = ["a", "b", "c", "d", "e", "f"];
    
    Array.from(combinationSet(item, 3));
    /*=>
    [
      [ "a", "b", "c" ], [ "a", "b", "d" ],
      [ "a", "b", "e" ], [ "a", "b", "f" ],
      [ "a", "c", "d" ], [ "a", "c", "e" ],
      [ "a", "c", "f" ], [ "a", "d", "e" ],
      [ "a", "d", "f" ], [ "a", "e", "f" ],
      [ "b", "c", "d" ], [ "b", "c", "e" ],
      [ "b", "c", "f" ], [ "b", "d", "e" ],
      [ "b", "d", "f" ], [ "b", "e", "f" ],
      [ "c", "d", "e" ], [ "c", "d", "f" ],
      [ "c", "e", "f" ], [ "d", "e", "f" ]
    ]
    */
    
    Array.from(permutationSet(item, 3));
    /*=>
    [
      [ "a", "b", "c" ], [ "a", "b", "d" ],
      [ "a", "b", "e" ], [ "a", "b", "f" ],
      [ "a", "c", "b" ], [ "a", "c", "d" ],
      [ "a", "c", "e" ], [ "a", "c", "f" ],
      [ "a", "d", "b" ], [ "a", "d", "c" ],
      [ "a", "d", "e" ], [ "a", "d", "f" ],
      [ "a", "e", "b" ], [ "a", "e", "c" ],
      [ "a", "e", "d" ], [ "a", "e", "f" ],
      [ "a", "f", "b" ], [ "a", "f", "c" ],
      [ "a", "f", "d" ], [ "a", "f", "e" ],
      [ "b", "a", "c" ], [ "b", "a", "d" ],
      [ "b", "a", "e" ], [ "b", "a", "f" ],
      [ "b", "c", "a" ], [ "b", "c", "d" ],
      [ "b", "c", "e" ], [ "b", "c", "f" ],
      [ "b", "d", "a" ], [ "b", "d", "c" ],
      [ "b", "d", "e" ], [ "b", "d", "f" ],
      [ "b", "e", "a" ], [ "b", "e", "c" ],
      [ "b", "e", "d" ], [ "b", "e", "f" ],
      [ "b", "f", "a" ], [ "b", "f", "c" ],
      [ "b", "f", "d" ], [ "b", "f", "e" ],
      ... +80
    ]
    */
  • Array.from(combinationCollection({ foo: [1, 2, 3], bar: [4, 5, 6] }));
    /*=>
    [
      { foo: 1, bar: 4 }, { foo: 1, bar: 5 },
      { foo: 1, bar: 6 }, { foo: 2, bar: 4 },
      { foo: 2, bar: 5 }, { foo: 2, bar: 6 },
      { foo: 3, bar: 4 }, { foo: 3, bar: 5 },
      { foo: 3, bar: 6 }
    ]
    */