Skip to content

arichardsmith/all-permutations

Repository files navigation

All Variations

A tagged template literal that compiles all variations of array contents.

Usage

import all from 'all-variations'

const foo = ['foo', 'bar', 'baz']
const num = [1, 2, 3]
const jandals = 'jandals'

const allVariations = all`${num}: ${foo}bar ${jandals}`
/*
[
  '1: foobar jandals',
  '1: barbar jandals',
  '1: bazbar jandals',
  '2: foobar jandals',
  etc...
]
*/

There is also a generator implementation that avoids loading all the variations into memory at once.

import all from 'all-variations/generator'

const foo = ['foo', 'bar', 'baz']
const num = [1, 2, 3]
const jandals = 'jandals'

const allVariations = all`${num}: ${foo}bar ${jandals}`
for (let variation of allVariations) {
  console.log(variation)
}
/*
Logs:
'1: foobar jandals',
'1: barbar jandals',
'1: bazbar jandals',
'2: foobar jandals',
etc...
*/

About

Tagged template literal that takes arrays and produces all possible permutations of string

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •