|
1 | 1 | # regexpp
|
2 |
| -RegExp parser. |
| 2 | + |
| 3 | +[](https://www.npmjs.com/package/regexpp) |
| 4 | +[](http://www.npmtrends.com/regexpp) |
| 5 | +[](https://travis-ci.org/mysticatea/regexpp) |
| 6 | +[](https://david-dm.org/mysticatea/regexpp) |
| 7 | + |
| 8 | +The regular expression parser for ECMAScript. |
| 9 | + |
| 10 | +## 💿 Installation |
| 11 | + |
| 12 | +```bash |
| 13 | +$ npm install regexpp |
| 14 | +``` |
| 15 | + |
| 16 | +- require Node.js 4.0.0 or newer. |
| 17 | + |
| 18 | +## 📖 Usage |
| 19 | + |
| 20 | +```ts |
| 21 | +import { |
| 22 | + AST, |
| 23 | + RegExpParser, |
| 24 | + RegExpValidator, |
| 25 | + parseRegExpLiteral, |
| 26 | + validateRegExpLiteral, |
| 27 | +} from "regexpp" |
| 28 | +``` |
| 29 | + |
| 30 | +### parseRegExpLiteral(source, options?) |
| 31 | + |
| 32 | +Parse a given regular expression literal then make AST object. |
| 33 | + |
| 34 | +This is equivalent to `new RegExpParser(options).parseLiteral(source)`. |
| 35 | + |
| 36 | +- **Parameters:** |
| 37 | + - `source` (`string`) The source code to parse. |
| 38 | + - `options?` ([`RegExpParser.Options`]) The options to parse. |
| 39 | +- **Return:** |
| 40 | + - The AST of the regular expression. |
| 41 | + |
| 42 | +### validateRegExpLiteral(source, options?) |
| 43 | + |
| 44 | +Validate a given regular expression literal. |
| 45 | + |
| 46 | +This is equivalent to `new RegExpValidator(options).validateLiteral(source)`. |
| 47 | + |
| 48 | +- **Parameters:** |
| 49 | + - `source` (`string`) The source code to validate. |
| 50 | + - `options?` ([`RegExpValidator.Options`]) The options to validate. |
| 51 | + |
| 52 | +### RegExpParser |
| 53 | + |
| 54 | +#### new RegExpParser(options?) |
| 55 | + |
| 56 | +- **Parameters:** |
| 57 | + - `options?` ([`RegExpParser.Options`]) The options to parse. |
| 58 | + |
| 59 | +#### parser.parseLiteral(source, start?, end?) |
| 60 | + |
| 61 | +Parse a regular expression literal. |
| 62 | + |
| 63 | +- **Parameters:** |
| 64 | + - `source` (`string`) The source code to parse. E.g. `"/abc/g"`. |
| 65 | + - `start?` (`number`) The start index in the source code. Default is `0`. |
| 66 | + - `end?` (`number`) The end index in the source code. Default is `source.length`. |
| 67 | +- **Return:** |
| 68 | + - The AST of the regular expression. |
| 69 | + |
| 70 | +#### parser.parsePattern(source, start?, end?, uFlag?) |
| 71 | + |
| 72 | +Parse a regular expression pattern. |
| 73 | + |
| 74 | +- **Parameters:** |
| 75 | + - `source` (`string`) The source code to parse. E.g. `"abc"`. |
| 76 | + - `start?` (`number`) The start index in the source code. Default is `0`. |
| 77 | + - `end?` (`number`) The end index in the source code. Default is `source.length`. |
| 78 | + - `uFlag?` (`boolean`) The flag to enable Unicode mode. |
| 79 | +- **Return:** |
| 80 | + - The AST of the regular expression pattern. |
| 81 | + |
| 82 | +#### parser.parseFlags(source, start?, end?) |
| 83 | + |
| 84 | +Parse a regular expression flags. |
| 85 | + |
| 86 | +- **Parameters:** |
| 87 | + - `source` (`string`) The source code to parse. E.g. `"gim"`. |
| 88 | + - `start?` (`number`) The start index in the source code. Default is `0`. |
| 89 | + - `end?` (`number`) The end index in the source code. Default is `source.length`. |
| 90 | +- **Return:** |
| 91 | + - The AST of the regular expression flags. |
| 92 | + |
| 93 | +### RegExpValidator |
| 94 | + |
| 95 | +#### new RegExpValidator(options) |
| 96 | + |
| 97 | +- **Parameters:** |
| 98 | + - `options` ([`RegExpValidator.Options`]) The options to validate. |
| 99 | + |
| 100 | +#### validator.validateLiteral(source, start, end) |
| 101 | + |
| 102 | +Validate a regular expression literal. |
| 103 | + |
| 104 | +- **Parameters:** |
| 105 | + - `source` (`string`) The source code to validate. |
| 106 | + - `start?` (`number`) The start index in the source code. Default is `0`. |
| 107 | + - `end?` (`number`) The end index in the source code. Default is `source.length`. |
| 108 | + |
| 109 | +#### validator.validatePattern(source, start, end, uFlag) |
| 110 | + |
| 111 | +Validate a regular expression pattern. |
| 112 | + |
| 113 | +- **Parameters:** |
| 114 | + - `source` (`string`) The source code to validate. |
| 115 | + - `start?` (`number`) The start index in the source code. Default is `0`. |
| 116 | + - `end?` (`number`) The end index in the source code. Default is `source.length`. |
| 117 | + - `uFlag?` (`boolean`) The flag to enable Unicode mode. |
| 118 | + |
| 119 | +#### validator.validateFlags(source, start, end) |
| 120 | + |
| 121 | +Validate a regular expression flags. |
| 122 | + |
| 123 | +- **Parameters:** |
| 124 | + - `source` (`string`) The source code to validate. |
| 125 | + - `start?` (`number`) The start index in the source code. Default is `0`. |
| 126 | + - `end?` (`number`) The end index in the source code. Default is `source.length`. |
| 127 | + |
| 128 | +## 📰 Changelog |
| 129 | + |
| 130 | +- [GitHub Releases](https://github.com/mysticatea/regexpp/releases) |
| 131 | + |
| 132 | +## 🍻 Contributing |
| 133 | + |
| 134 | +Welcome contributing! |
| 135 | + |
| 136 | +Please use GitHub's Issues/PRs. |
| 137 | + |
| 138 | +### Development Tools |
| 139 | + |
| 140 | +- `npm test` runs tests and measures coverage. |
| 141 | +- `npm run build` compiles TypeScript source code to `index.js`, `index.js.map`, and `index.d.ts`. |
| 142 | +- `npm run clean` removes the temporary files which are created by `npm test` and `npm run build`. |
| 143 | +- `npm run lint` runs ESLint. |
| 144 | +- `npm run update:test` updates test fixtures. |
| 145 | +- `npm run update:ids` updates `src/unicode/ids.ts`. |
| 146 | +- `npm run watch` runs tests with `--watch` option. |
| 147 | + |
| 148 | +[`RegExpParser.Options`]: src/parser.ts#L527 |
| 149 | +[`RegExpValidator.Options`]: src/validator.ts#L127 |
0 commit comments