Skip to content

jamen/combin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

combin

Create an array of string combinations

Create string combinations. Optionally given a set of characters and rule. It is useful for creating fake data or finding package names

var combin = require('combin')

// All 3 letter combinations with vowel in center:
combin(3, function (item) {
  return 'aeiou'.indexOf(item[1]) !== -1
})

Installation

$ npm install --save combin

Usage

combin(length, [set, rule])

Create a an array of string combinations, from the characters in set, and filtered by a rule function

  • length (Number): The length of each item. e.g., 2 would produce ['aa', 'ab', ...]
  • set (String): A set of characters that make up the combinations
  • rule (Function): A function that filters the combinations
combin(3)
// [ 'aaa', 'aab', 'aac', ..., 'zzx', 'zzy', 'zzz' ]

combin(2, '01')
// [ '00', '01', '10', '11' ]

combin(2, 'abc', x => x[0] !== 'a')
// [ 'ba', 'bb', 'bc', 'ca', 'cb', 'cc' ]

License

MIT © Jamen Marz


[version][package] travis [downloads/month][package] [downloads][package] [license][package] support me follow [package]: https://npmjs.com/package/combin

About

Create an array of string combinations

Resources

License

Stars

Watchers

Forks

Packages

No packages published