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 🙏

© 2026 – Pkg Stats / Ryan Hefner

power-cartesian-product

v0.0.6

Published

powerful cartesian product

Downloads

90

Readme

power-cartesian-product

powerful cartesian product

this module was named fast-cartesian-product before v0.0.3, now it's split into to two modules:

Examples

import PowerCartesianProduct from 'power-cartesian-product'

const inputs = [
  [0, 1],
  ['A', 'B'],
]

for (const combination of new PowerCartesianProduct(inputs)) {
  console.log(combination)
}

more examples

git clone https://github.com/fisker/power-cartesian-product.git
cd fast-cartesian-product
yarn
node -r esm examples/standard-52-card-deck.js
node -r esm examples/any-iterable-type.js
node -r esm examples/big-combinations.js

Files

dist/
├─ index.common.js  ( CommonJS )
├─ index.js         ( UMD )
├─ index.min.js     ( UMD, compressed )
├─ index.mjs        ( ES Module )
└─ index.min.mjs    ( ES Module, compressed )

API

combinations = new PowerCartesianProduct(sets)

Returns: combinations

sets

type: iterable | arrayLike | GeneratorFunction

*notice: GeneratorFunction is supported, not generator yet, #57

combinations

instance of PowerCartesianProduct

it's not Array, also no length

to get Array

[...combinations]

// OR

Array.from(...combinations)

// OR

const array = []

let (const combination of combinations) {
  array.push(combination)
}

// es5

var array = []
var iterator = combinations[PowerCartesianProduct.SYMBOL_ITERATOR]()
var data
while (!(data = iterator.next()).done) {
  array.push(data.value)
}

to get Set

new Set(combinations)

PowerCartesianProduct#get(index)

get nth combination

Returns: array

// 3rd combination
new PowerCartesianProduct([
  [0, 1],
  ['A', 'B'],
]).get(2)
// -> [1, 'A']

PowerCartesianProduct#getIndexes(index)

get nth combination indexes

Returns: array<number>

// 3rd combination indexes
new PowerCartesianProduct([
  [0, 1],
  ['A', 'B'],
]).getIndexes(2)
// -> [1, 0]

PowerCartesianProduct#size

a getter to get size of combinations, this might be Infinity for big combinations.

Returns: int | infinity

new PowerCartesianProduct([
  [0, 1],
  ['A', 'B'],
]).size
// -> 4

new PowerCartesianProduct(new Array(256).fill(new Array(16))).size
// -> Infinity

PowerCartesianProduct#bigSize

a getter to get BigInt size of combinations.

Returns: BigInt

new PowerCartesianProduct([
  [0, 1],
  ['A', 'B'],
]).bigSize
// -> 4n

new PowerCartesianProduct(new Array(33).fill(new Array(2 ** 32 - 1))).bigSize
// -> 772103316315349105706014416063813378269318666861765024749836830511609335567106186231578700102953323105081739246412669785553431723085370935750037827673052894357512235463946499050426982824119747058048805090828544034771248058426863536672304703225363101118206353134873876903786099067350665495893380022607743740081787109375n

PowerCartesianProduct.SYMBOL_ITERATOR

symbol to get Iterator, for environment without Symbol, it's string @@iterator, otherwise it's Symbol.iterator

if you are not sure, you should always use combinations[PowerCartesianProduct.SYMBOL_ITERATOR]()

var iterator = combinations[PowerCartesianProduct.SYMBOL_ITERATOR]()
iterator.next() // {value: [0, 1], done: false}