1.1.0 • Published 5 years ago

genex v1.1.0

Weekly downloads
34
License
MIT
Repository
github
Last release
5 years ago

genex

genex Donate

Counts and expands any given regular expression into all the possible strings that it would be able to match.

Install

npm i genex --save

Usage

const genex = require('genex');
const pattern = genex(/(foo|bar|baz){1,2}|snafu/);

// 13
console.log(pattern.count());

/*
[
  'foo', 'foofoo', 'foobar', 'foobaz',
  'bar', 'barfoo', 'barbar', 'barbaz',
  'baz', 'bazfoo', 'bazbar', 'bazbaz',
  'snafu'
]
*/
console.log(pattern.generate());

The generate() method also accepts an optional callback:

pattern.generate((value) => {
  if (value.startsWith('foo') !== true) {
    return false; // breaks iteration
  }

  console.log(value); // 'foo', 'foofoo', 'foobar', 'foobaz',
});

License

MIT

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.1.3

9 years ago

0.1.1

10 years ago

0.1.0

10 years ago