{"name":"regexpu-core","version":"6.3.1","keywords":["codegen","desugaring","ecmascript","es5","es6","harmony","javascript","refactoring","regex","regexp","regular expressions","rewriting","syntax","transformation","transpile","transpiler","unicode"],"author":{"url":"https://mathiasbynens.be/","name":"Mathias Bynens"},"license":"MIT","_id":"regexpu-core@6.3.1","maintainers":[{"name":"mathias","email":"mathias@qiwi.be"},{"name":"jridgewell","email":"justin+npm@ridgewell.name"},{"name":"nicolo-ribaudo","email":"nicolo.ribaudo@gmail.com"},{"name":"google-wombot","email":"node-team-npm+wombot@google.com"}],"homepage":"https://mths.be/regexpu","bugs":{"url":"https://github.com/mathiasbynens/regexpu-core/issues"},"dist":{"shasum":"fb8b707d0efe18e9464d3ae76ae1e3c96c8467ae","tarball":"http://registry-npm.ywwl.com/regexpu-core/download/regexpu-core-6.3.1.tgz","fileCount":10,"integrity":"sha512-DzcswPr252wEr7Qz8AyAVbfyBDKLoYp6eRA1We2Fa9qirRFSdtkP5sHr3yglDKy2BbA0fd2T+j/CUSKes3FeVQ==","signatures":[{"sig":"MEUCIQCbgZpjfOL+5tdGazr5LSqhR026qVqvfXSR4g8zzlOObAIgf1f18jhXkXaeHml17HIzJBrpn6MdyqxuklSN7bULw60=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":137902,"size":35104,"noattachment":false,"key":"/regexpu-core/-/regexpu-core-6.3.1.tgz"},"main":"rewrite-pattern.js","types":"./rewrite-pattern.d.ts","engines":{"node":">=4"},"gitHead":"5526a5c96343fede35995824a0d55993106597b0","scripts":{"test":"node --test tests/tests.js","build":"node scripts/index.js","cover":"NODE_V8_COVERAGE=coverage node --test  --experimental-test-coverage tests/tests.js","test-node6":"mocha tests"},"_npmUser":{"name":"google-wombot","email":"node-team-npm+wombot@google.com"},"repository":{"url":"git+https://github.com/mathiasbynens/regexpu-core.git","type":"git"},"_npmVersion":"10.9.3","description":"regexpu’s core functionality (i.e. `rewritePattern(pattern, flag)`), capable of translating ES6 Unicode regular expressions to ES5.","directories":{},"_nodeVersion":"22.19.0","dependencies":{"regjsgen":"^0.8.0","regenerate":"^1.4.2","regjsparser":"^0.12.0","regenerate-unicode-properties":"^10.2.2","unicode-match-property-ecmascript":"^2.0.0","unicode-match-property-value-ecmascript":"^2.2.1"},"_hasShrinkwrap":false,"devDependencies":{"jsesc":"^3.0.2","@unicode/unicode-17.0.0":"^1.6.12"},"_npmOperationalInternal":{"tmp":"tmp/regexpu-core_6.3.1_1757517541974_0.33188608645819584","host":"s3://npm-registry-packages-npm-production"},"readme":"# regexpu-core [![Build status](https://github.com/mathiasbynens/regexpu-core/workflows/run-checks/badge.svg)](https://github.com/mathiasbynens/regexpu-core/actions?query=workflow%3Arun-checks) [![regexpu-core on npm](https://img.shields.io/npm/v/regexpu-core)](https://www.npmjs.com/package/regexpu-core)\n\n_regexpu_ is a source code transpiler that enables the use of ES2015 Unicode regular expressions in JavaScript-of-today (ES5).\n\n_regexpu-core_ contains _regexpu_’s core functionality, i.e. `rewritePattern(pattern, flag)`, which enables rewriting regular expressions that make use of [the ES2015 `u` flag](https://mathiasbynens.be/notes/es6-unicode-regex) into equivalent ES5-compatible regular expression patterns.\n\n## Installation\n\nTo use _regexpu-core_ programmatically, install it as a dependency via [npm](https://www.npmjs.com/):\n\n```bash\nnpm install regexpu-core --save\n```\n\nThen, `require` it:\n\n```js\nconst rewritePattern = require('regexpu-core');\n```\n\n## API\n\nThis module exports a single function named `rewritePattern`.\n\n### `rewritePattern(pattern, flags, options)`\n\nThis function takes a string that represents a regular expression pattern as well as a string representing its flags, and returns an ES5-compatible version of the pattern.\n\n```js\nrewritePattern('foo.bar', 'u', { unicodeFlag: \"transform\" });\n// → 'foo(?:[\\\\0-\\\\t\\\\x0B\\\\f\\\\x0E-\\\\u2027\\\\u202A-\\\\uD7FF\\\\uDC00-\\\\uFFFF]|[\\\\uD800-\\\\uDBFF][\\\\uDC00-\\\\uDFFF]|[\\\\uD800-\\\\uDBFF])bar'\n\nrewritePattern('[\\\\u{1D306}-\\\\u{1D308}a-z]', 'u', { unicodeFlag: \"transform\" });\n// → '(?:[a-z]|\\\\uD834[\\\\uDF06-\\\\uDF08])'\n\nrewritePattern('[\\\\u{1D306}-\\\\u{1D308}a-z]', 'ui', { unicodeFlag: \"transform\" });\n// → '(?:[a-z\\\\u017F\\\\u212A]|\\\\uD834[\\\\uDF06-\\\\uDF08])'\n```\n\n_regexpu-core_ can rewrite non-ES6 regular expressions too, which is useful to demonstrate how their behavior changes once the `u` and `i` flags are added:\n\n```js\n// In ES5, the dot operator only matches BMP symbols:\nrewritePattern('foo.bar', '', { unicodeFlag: \"transform\" });\n// → 'foo(?:[\\\\0-\\\\t\\\\x0B\\\\f\\\\x0E-\\\\u2027\\\\u202A-\\\\uFFFF])bar'\n\n// But with the ES2015 `u` flag, it matches astral symbols too:\nrewritePattern('foo.bar', 'u', { unicodeFlag: \"transform\" });\n// → 'foo(?:[\\\\0-\\\\t\\\\x0B\\\\f\\\\x0E-\\\\u2027\\\\u202A-\\\\uD7FF\\\\uDC00-\\\\uFFFF]|[\\\\uD800-\\\\uDBFF][\\\\uDC00-\\\\uDFFF]|[\\\\uD800-\\\\uDBFF])bar'\n```\n\nThe optional `options` argument recognizes the following properties:\n\n#### Stable regular expression features\n\nThese options can be set to `false` or `'transform'`. When using `'transform'`, the corresponding features are compiled to older syntax that can run in older browsers. When using `false` (the default), they are not compiled and they can be relied upon to compile more modern features.\n\n- `unicodeFlag` - The `u` flag, enabling support for Unicode code point escapes in the form `\\u{...}`.\n\n  ```js\n  rewritePattern('\\\\u{ab}', '', {\n    unicodeFlag: 'transform'\n  });\n  // → '\\\\u{ab}'\n\n  rewritePattern('\\\\u{ab}', 'u', {\n    unicodeFlag: 'transform'\n  });\n  // → '\\\\xAB'\n  ```\n\n- `dotAllFlag` - The [`s` (`dotAll`) flag](https://github.com/mathiasbynens/es-regexp-dotall-flag).\n\n  ```js\n  rewritePattern('.', '', {\n    dotAllFlag: 'transform'\n  });\n  // → '[\\\\0-\\\\t\\\\x0B\\\\f\\\\x0E-\\\\u2027\\\\u202A-\\\\uFFFF]'\n\n  rewritePattern('.', 's', {\n    dotAllFlag: 'transform'\n  });\n  // → '[\\\\0-\\\\uFFFF]'\n\n  rewritePattern('.', 'su', {\n    dotAllFlag: 'transform'\n  });\n  // → '(?:[\\\\0-\\\\uD7FF\\\\uE000-\\\\uFFFF]|[\\\\uD800-\\\\uDBFF][\\\\uDC00-\\\\uDFFF]|[\\\\uD800-\\\\uDBFF](?![\\\\uDC00-\\\\uDFFF])|(?:[^\\\\uD800-\\\\uDBFF]|^)[\\\\uDC00-\\\\uDFFF])'\n  ```\n\n- `unicodePropertyEscapes` - [Unicode property escapes](property-escapes.md).\n\n  By default they are compiled to Unicode code point escapes of the form `\\u{...}`. If the `unicodeFlag` option is set to `'transform'` they often result in larger output, although there are cases (such as `\\p{Lu}`) where it actually _decreases_ the output size.\n\n  ```js\n  rewritePattern('\\\\p{Script_Extensions=Anatolian_Hieroglyphs}', 'u', {\n    unicodePropertyEscapes: 'transform'\n  });\n  // → '[\\\\u{14400}-\\\\u{14646}]'\n\n  rewritePattern('\\\\p{Script_Extensions=Anatolian_Hieroglyphs}', 'u', {\n    unicodeFlag: 'transform',\n    unicodePropertyEscapes: 'transform'\n  });\n  // → '(?:\\\\uD811[\\\\uDC00-\\\\uDE46])'\n  ```\n\n- `namedGroups` - [Named capture groups](https://github.com/tc39/proposal-regexp-named-groups).\n\n  ```js\n  rewritePattern('(?<name>.)\\\\k<name>', '', {\n    namedGroups: 'transform'\n  });\n  // → '(.)\\1'\n  ```\n\n- `unicodeSetsFlag` - [The `v` (`unicodeSets`) flag](https://github.com/tc39/proposal-regexp-set-notation)\n\n  ```js\n  rewritePattern('[\\\\p{Emoji}&&\\\\p{ASCII}]', 'v', {\n    unicodeSetsFlag: 'transform'\n  });\n  // → '[#\\\\*0-9]'\n  ```\n\n  By default, patterns with the `v` flag are transformed to patterns with the `u` flag. If you want to downlevel them more you can set the `unicodeFlag: 'transform'` option.\n\n  ```js\n  rewritePattern('[^[a-h]&&[f-z]]', 'v', {\n    unicodeSetsFlag: 'transform'\n  });\n  // → '[^f-h]' (to be used with /u)\n  ```\n\n  ```js\n  rewritePattern('[^[a-h]&&[f-z]]', 'v', {\n    unicodeSetsFlag: 'transform',\n    unicodeFlag: 'transform'\n  });\n  // → '(?:(?![f-h])[\\s\\S])' (to be used without /u)\n  ```\n\n- `modifiers` - [Inline `i`/`m`/`s` modifiers](https://github.com/tc39/proposal-regexp-modifiers)\n\n  ```js\n  rewritePattern('(?i:[a-z])[a-z]', '', {\n    modifiers: 'transform'\n  });\n  // → '(?:[a-zA-Z])([a-z])'\n  ```\n\n#### Experimental regular expression features\n\nThese options can be set to `false`, `'parse'` and `'transform'`. When using `'transform'`, the corresponding features are compiled to older syntax that can run in older browsers. When using `'parse'`, they are parsed and left as-is in the output pattern. When using `false` (the default), they result in a syntax error if used.\n\nOnce these features become stable (when the proposals are accepted as part of ECMAScript), they will be parsed by default and thus `'parse'` will behave like `false`.\n\n#### Miscellaneous options\n\n- `onNamedGroup`\n\n  This option is a function that gets called when a named capture group is found. It receives two parameters:\n  the name of the group, and its index.\n\n  ```js\n  rewritePattern('(?<name>.)\\\\k<name>', '', {\n    onNamedGroup(name, index) {\n      console.log(name, index);\n      // → 'name', 1\n    }\n  });\n  ```\n\n- `onNewFlags`\n\n  This option is a function that gets called to pass the flags that the resulting pattern must be interpreted with.\n\n  ```js\n  rewritePattern('abc', 'um', '', {\n    unicodeFlag: 'transform',\n    onNewFlags(flags) {\n      console.log(flags);\n      // → 'm'\n    }\n  })\n  ```\n\n### Caveats\n\n- [Lookbehind assertions](https://github.com/tc39/proposal-regexp-lookbehind) cannot be transformed to older syntax.\n- When using `namedGroups: 'transform'`, _regexpu-core_ only takes care of the _syntax_: you will still need a runtime wrapper around the regular expression to populate the `.groups` property of `RegExp.prototype.match()`'s result. If you are using _regexpu-core_ via Babel, it's handled automatically.\n\n## For maintainers\n\n### How to publish a new release\n\n1. On the `main` branch, bump the version number in `package.json`:\n\n    ```sh\n    npm version patch -m 'Release v%s'\n    ```\n\n    Instead of `patch`, use `minor` or `major` [as needed](https://semver.org/).\n\n    Note that this produces a Git commit + tag.\n\n1. Push the release commit and tag:\n\n    ```sh\n    git push --follow-tags\n    ```\n\n    Our CI then automatically publishes the new release to npm.\n\n1. Once the release has been published to npm, update [`regexpu`](https://github.com/mathiasbynens/regexpu) to make use of it, and [cut a new release of `regexpu` as well](https://github.com/mathiasbynens/regexpu#how-to-publish-a-new-release).\n\n\n## Author\n\n| [![twitter/mathias](https://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias \"Follow @mathias on Twitter\") |\n|---|\n| [Mathias Bynens](https://mathiasbynens.be/) |\n\n## License\n\n_regexpu-core_ is available under the [MIT](https://mths.be/mit) license.\n","publish_time":1757517542188,"_cnpm_publish_time":1757517542188,"dist-tags":{"latest":"6.5.4"}}