Generated regex is cached based on the provided string and options. As a result, runtime compilation only happens once per pattern (as long as options are also the same), which can result in dramatic speed improvements.
This also helps with debugging, since adding options and pattern are added to the generated regex.
Disable caching
toRegex('foo', {cache: false});
options.safe
Type: Boolean
Default: undefined
Check the generated regular expression with safe-regex and throw an error if the regex is potentially unsafe.
Examples
console.log(toRegex('(x+x+)+y'));//=> /^(?:(x+x+)+y)$/// The following would throw an errortoRegex('(x+x+)+y', {safe: true});
About
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running Tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command: