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.

41 lines
1.1 KiB

6 months ago
  1. # regjsgen [![Build status][ci-img]][ci] [![Code coverage status][codecov-img]][codecov]
  2. Generate regular expressions from [regjsparser][regjsparser]’s AST.
  3. ## Installation
  4. ```sh
  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. const regjsparser = require('regjsparser');
  12. const regjsgen = require('regjsgen');
  13. // Generate an AST with `regjsparser`.
  14. let ast = regjsparser.parse(regex);
  15. // Modify AST
  16. // …
  17. // Generate `RegExp` string with `regjsgen`.
  18. let regex = regjsgen.generate(ast);
  19. ```
  20. ## Support
  21. Tested on Node.js 16 and 18.<br>
  22. Compatible with regjsparser v0.10.0’s AST.
  23. [ci]: https://github.com/bnjmnt4n/regjsgen/actions
  24. [ci-img]: https://github.com/bnjmnt4n/regjsgen/workflows/Node.js%20CI/badge.svg
  25. [codecov]: https://codecov.io/gh/bnjmnt4n/regjsgen
  26. [codecov-img]: https://codecov.io/gh/bnjmnt4n/regjsgen/branch/main/graph/badge.svg
  27. [regjsparser]: https://github.com/jviereck/regjsparser