租房小程序前端代码
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.

177 lines
5.5 KiB

2 months ago
  1. # @eslint-community/regexpp
  2. [![npm version](https://img.shields.io/npm/v/@eslint-community/regexpp.svg)](https://www.npmjs.com/package/@eslint-community/regexpp)
  3. [![Downloads/month](https://img.shields.io/npm/dm/@eslint-community/regexpp.svg)](http://www.npmtrends.com/@eslint-community/regexpp)
  4. [![Build Status](https://github.com/eslint-community/regexpp/workflows/CI/badge.svg)](https://github.com/eslint-community/regexpp/actions)
  5. [![codecov](https://codecov.io/gh/eslint-community/regexpp/branch/main/graph/badge.svg)](https://codecov.io/gh/eslint-community/regexpp)
  6. A regular expression parser for ECMAScript.
  7. ## 💿 Installation
  8. ```bash
  9. $ npm install @eslint-community/regexpp
  10. ```
  11. - require Node@^12.0.0 || ^14.0.0 || >=16.0.0.
  12. ## 📖 Usage
  13. ```ts
  14. import {
  15. AST,
  16. RegExpParser,
  17. RegExpValidator,
  18. RegExpVisitor,
  19. parseRegExpLiteral,
  20. validateRegExpLiteral,
  21. visitRegExpAST
  22. } from "@eslint-community/regexpp"
  23. ```
  24. ### parseRegExpLiteral(source, options?)
  25. Parse a given regular expression literal then make AST object.
  26. This is equivalent to `new RegExpParser(options).parseLiteral(source)`.
  27. - **Parameters:**
  28. - `source` (`string | RegExp`) The source code to parse.
  29. - `options?` ([`RegExpParser.Options`]) The options to parse.
  30. - **Return:**
  31. - The AST of the regular expression.
  32. ### validateRegExpLiteral(source, options?)
  33. Validate a given regular expression literal.
  34. This is equivalent to `new RegExpValidator(options).validateLiteral(source)`.
  35. - **Parameters:**
  36. - `source` (`string`) The source code to validate.
  37. - `options?` ([`RegExpValidator.Options`]) The options to validate.
  38. ### visitRegExpAST(ast, handlers)
  39. Visit each node of a given AST.
  40. This is equivalent to `new RegExpVisitor(handlers).visit(ast)`.
  41. - **Parameters:**
  42. - `ast` ([`AST.Node`]) The AST to visit.
  43. - `handlers` ([`RegExpVisitor.Handlers`]) The callbacks.
  44. ### RegExpParser
  45. #### new RegExpParser(options?)
  46. - **Parameters:**
  47. - `options?` ([`RegExpParser.Options`]) The options to parse.
  48. #### parser.parseLiteral(source, start?, end?)
  49. Parse a regular expression literal.
  50. - **Parameters:**
  51. - `source` (`string`) The source code to parse. E.g. `"/abc/g"`.
  52. - `start?` (`number`) The start index in the source code. Default is `0`.
  53. - `end?` (`number`) The end index in the source code. Default is `source.length`.
  54. - **Return:**
  55. - The AST of the regular expression.
  56. #### parser.parsePattern(source, start?, end?, flags?)
  57. Parse a regular expression pattern.
  58. - **Parameters:**
  59. - `source` (`string`) The source code to parse. E.g. `"abc"`.
  60. - `start?` (`number`) The start index in the source code. Default is `0`.
  61. - `end?` (`number`) The end index in the source code. Default is `source.length`.
  62. - `flags?` (`{ unicode?: boolean, unicodeSets?: boolean }`) The flags to enable Unicode mode, and Unicode Set mode.
  63. - **Return:**
  64. - The AST of the regular expression pattern.
  65. #### parser.parseFlags(source, start?, end?)
  66. Parse a regular expression flags.
  67. - **Parameters:**
  68. - `source` (`string`) The source code to parse. E.g. `"gim"`.
  69. - `start?` (`number`) The start index in the source code. Default is `0`.
  70. - `end?` (`number`) The end index in the source code. Default is `source.length`.
  71. - **Return:**
  72. - The AST of the regular expression flags.
  73. ### RegExpValidator
  74. #### new RegExpValidator(options)
  75. - **Parameters:**
  76. - `options` ([`RegExpValidator.Options`]) The options to validate.
  77. #### validator.validateLiteral(source, start, end)
  78. Validate a regular expression literal.
  79. - **Parameters:**
  80. - `source` (`string`) The source code to validate.
  81. - `start?` (`number`) The start index in the source code. Default is `0`.
  82. - `end?` (`number`) The end index in the source code. Default is `source.length`.
  83. #### validator.validatePattern(source, start, end, flags)
  84. Validate a regular expression pattern.
  85. - **Parameters:**
  86. - `source` (`string`) The source code to validate.
  87. - `start?` (`number`) The start index in the source code. Default is `0`.
  88. - `end?` (`number`) The end index in the source code. Default is `source.length`.
  89. - `flags?` (`{ unicode?: boolean, unicodeSets?: boolean }`) The flags to enable Unicode mode, and Unicode Set mode.
  90. #### validator.validateFlags(source, start, end)
  91. Validate a regular expression flags.
  92. - **Parameters:**
  93. - `source` (`string`) The source code to validate.
  94. - `start?` (`number`) The start index in the source code. Default is `0`.
  95. - `end?` (`number`) The end index in the source code. Default is `source.length`.
  96. ### RegExpVisitor
  97. #### new RegExpVisitor(handlers)
  98. - **Parameters:**
  99. - `handlers` ([`RegExpVisitor.Handlers`]) The callbacks.
  100. #### visitor.visit(ast)
  101. Validate a regular expression literal.
  102. - **Parameters:**
  103. - `ast` ([`AST.Node`]) The AST to visit.
  104. ## 📰 Changelog
  105. - [GitHub Releases](https://github.com/eslint-community/regexpp/releases)
  106. ## 🍻 Contributing
  107. Welcome contributing!
  108. Please use GitHub's Issues/PRs.
  109. ### Development Tools
  110. - `npm test` runs tests and measures coverage.
  111. - `npm run build` compiles TypeScript source code to `index.js`, `index.js.map`, and `index.d.ts`.
  112. - `npm run clean` removes the temporary files which are created by `npm test` and `npm run build`.
  113. - `npm run lint` runs ESLint.
  114. - `npm run update:test` updates test fixtures.
  115. - `npm run update:ids` updates `src/unicode/ids.ts`.
  116. - `npm run watch` runs tests with `--watch` option.
  117. [`AST.Node`]: src/ast.ts#L4
  118. [`RegExpParser.Options`]: src/parser.ts#L743
  119. [`RegExpValidator.Options`]: src/validator.ts#L220
  120. [`RegExpVisitor.Handlers`]: src/visitor.ts#L291