b9abb81d8e39554f3741109bfcdea39cc384b4569565d1b587306276e5b7262046e8fec2dcfda75a88072ccc4d78b16c578a2bdec6c364fd7a9ffd90d1e48f 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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