You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

4 years ago
  1. # regjsgen [![Build status][travis-ci-img]][travis-ci] [![Code coverage status][codecov-img]][codecov]
  2. Generate regular expressions from [regjsparser][regjsparser]’s AST.
  3. ## Installation
  4. ```bash
  5. npm i regjsgen
  6. ```
  7. ## API
  8. ### `regjsgen.generate(ast)`
  9. This function accepts an abstract syntax tree representing a regular expression (see [regjsparser][regjsparser]), and returns the generated regular expression string.
  10. ```js
  11. var regjsparser = require('regjsparser');
  12. var regjsgen = require('regjsgen');
  13. // Generate an AST with `regjsparser`.
  14. var ast = regjsparser.parse(regex);
  15. // Modify AST
  16. // …
  17. // Generate `RegExp` string with `regjsgen`.
  18. regex = regjsgen.generate(ast);
  19. ```
  20. ## Support
  21. Tested in Node.js 0.10, 0.12, 4, 6, 8, 10 and 12.
  22. [travis-ci]: https://travis-ci.org/bnjmnt4n/regjsgen
  23. [travis-ci-img]: https://travis-ci.org/bnjmnt4n/regjsgen.svg?branch=master
  24. [codecov]: https://codecov.io/gh/bnjmnt4n/regjsgen
  25. [codecov-img]: https://codecov.io/gh/bnjmnt4n/regjsgen/branch/master/graph/badge.svg
  26. [regjsparser]: https://github.com/jviereck/regjsparser