https://github.com/jamen/combin
Create an array of string combinations
https://github.com/jamen/combin
Last synced: about 1 year ago
JSON representation
Create an array of string combinations
- Host: GitHub
- URL: https://github.com/jamen/combin
- Owner: jamen
- License: mit
- Created: 2017-02-03T08:30:20.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-03T08:47:37.000Z (over 9 years ago)
- Last Synced: 2024-04-26T14:45:47.923Z (about 2 years ago)
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# combin
> Create an array of string combinations
Create string [combinations](https://en.wikipedia.org/wiki/Combination). Optionally given a set of characters and rule. It is useful for creating fake data or finding package names
```js
var combin = require('combin')
// All 3 letter combinations with vowel in center:
combin(3, function (item) {
return 'aeiou'.indexOf(item[1]) !== -1
})
```
## Installation
```sh
$ npm install --save combin
```
## Usage
### `combin(length, [set, rule])`
Create a an array of string [combinations](https://en.wikipedia.org/wiki/Combination), 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
```js
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](https://git.io/jamen)
---
[][package] [](https://travis-ci.org/combin/jamen) [][package] [][package] [][package] [](https://www.paypal.me/jamenmarz/5usd) [](https://github.com/jamen)
[package]: https://npmjs.com/package/combin