npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hugoalh/setation

v1.2.0

Published

A module to list permutation and combination from a set.

Downloads

1

Readme

Setation (NodeJS)

License GitHub Repository GitHub Stars GitHub Contributors GitHub Issues GitHub Pull Requests GitHub Discussions CodeFactor Grade

| Releases | Latest (GitHub Latest Release Date) | Pre (GitHub Latest Pre-Release Date) | |:-:|:-:|:-:| | GitHub GitHub Total Downloads | GitHub Latest Release Version | GitHub Latest Pre-Release Version | | NPM NPM Total Downloads | NPM Latest Release Version | NPM Latest Pre-Release Version |

📝 Description

A NodeJS module to list permutations and combinations from a set.

📚 Documentation

Getting Started

  • NodeJS ^ v12.20.0 || ^ v14.15.0 || >= v16.13.0
npm install @hugoalh/setation
/* Either */
import { ... } from "@hugoalh/setation";// Named Import
import * as setation from "@hugoalh/setation";// Namespace Import

API

Generator Function

  • combination<T>(set: T[] | Set<T>, size: number | number[]): Generator<T[], void, unknown>;
    combination<T>(set: T[] | Set<T>, sizeMinimum: number, sizeMaximum: number): Generator<T[], void, unknown>;
    combination<T>(set: T[] | Set<T>, options: CombinationOptions = {}): Generator<T[], void, unknown>;
  • /* >= v1.2.0 */
    combinationMatrix<V>(set: { [x: string]: V | V[]; } | Map<string, V | V[]>): Generator<{ [x: string]: V; }, void, unknown>;
  • permutation<T>(set: T[] | Set<T>, size: number | number[]): Generator<T[], void, unknown>;
    permutation<T>(set: T[] | Set<T>, sizeMinimum: number, sizeMaximum: number): Generator<T[], void, unknown>;
    permutation<T>(set: T[] | Set<T>, options: PermutationOptions = {}): Generator<T[], void, unknown>;

Interface / Type

  • interface CombinationOptions {
      allowRepeat: boolean = false;// Whether to allow the same element repeat appear in the same subset.
      size?: number | number[];// Size of the subset.
      sizeMaximum?: number;// Maximum size of the subset.
      sizeMinimum?: number;// Minimum size of the subset.
    }
  • interface PermutationOptions {
      allowRepeat: boolean = false;// Whether to allow the same element repeat appear in the same subset.
      size?: number | number[];// Size of the subset.
      sizeMaximum?: number;// Maximum size of the subset.
      sizeMinimum?: number;// Minimum size of the subset.
    }

Example

let item = ["a", "b", "c", "d", "e", "f"];
Array.from(combination(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(permutation(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(combinationMatrix({ 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 }
]
*/