{"name":"regexpu-core","version":"4.3.0","description":"regexpu’s core functionality (i.e. `rewritePattern(pattern, flag)`), capable of translating ES6 Unicode regular expressions to ES5.","homepage":"https://mths.be/regexpu","main":"rewrite-pattern.js","engines":{"node":">=4"},"keywords":["codegen","desugaring","ecmascript","es5","es6","harmony","javascript","refactoring","regex","regexp","regular expressions","rewriting","syntax","transformation","transpile","transpiler","unicode"],"license":"MIT","author":{"name":"Mathias Bynens","url":"https://mathiasbynens.be/"},"repository":{"type":"git","url":"git+https://github.com/mathiasbynens/regexpu-core.git"},"bugs":{"url":"https://github.com/mathiasbynens/regexpu-core/issues"},"scripts":{"build":"node scripts/iu-mappings.js && node scripts/character-class-escape-sets.js","test":"mocha tests","cover":"istanbul cover --report html node_modules/.bin/_mocha tests -- -u exports -R spec"},"dependencies":{"regenerate":"^1.4.0","regenerate-unicode-properties":"^7.0.0","regjsgen":"^0.5.0","regjsparser":"^0.6.0","unicode-match-property-ecmascript":"^1.0.4","unicode-match-property-value-ecmascript":"^1.0.2"},"devDependencies":{"codecov":"^3.0.2","istanbul":"^0.4.5","jsesc":"^2.5.1","lodash":"^4.17.10","mocha":"^5.2.0","regexpu-fixtures":"^2.1.2","unicode-11.0.0":"^0.7.7"},"gitHead":"3026682b8f2f97f3e0acb5db55b80d3173f8c251","_id":"regexpu-core@4.3.0","_npmVersion":"6.4.1","_nodeVersion":"10.14.1","_npmUser":{"name":"mathias","email":"mathias@qiwi.be"},"dist":{"integrity":"sha512-pniBuFHJMDy9P8jnXGBvfLQsQqzGsZuhT0KezuTWn1vMdJxuhsHauNdIvzMsiORmYPgLbPGwWbq3czCKa5RsWA==","shasum":"256cd550eadea9c9f37933c8a60ca966c8c1bc95","tarball":"http://registry-npm.ywwl.com/regexpu-core/download/regexpu-core-4.3.0.tgz","fileCount":6,"unpackedSize":37338,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcB522CRA9TVsSAnZWagAAcggP/3+yNh7ttPyzzVdw8a4v\nBsVUhXgXGFxhv8lE9cwwJ4Ln9FnLOM9sOpYwIbuJrlI3RJ+2ZYy6V3MvYjzu\npgHU6yWiCzUfyz1EtD/33GSAK2+nqwIUUb+LLV9kds+25EuNKOK/QV1M4p8u\nTmsB9ddZbMrpLZhr9sxRwYuYyvwa7uVrBQOyQwg+W+6zsMiRCc+XKQS/0aO4\ncLIVa8X55yMIgzZqGEjzt6rRoHcTJ9rZtDACtCZfhgRipb3gt7/XjORMfc7N\nsxoDazWiap9zyNC59YMdJ6Cy9QdhaHrR9TqZALrL1SCPnx6r5OTec/U3fbDW\nPhyEVPB4QU4LsjhgrFTwRGm00zrKe+OKfSsUemZ5cusw35AqZpRSB57/naI2\nMjRQ0ahZz+u2hV17itEZllCHmVs4i7C7mW+7uu6Xo59EGci97Yy5ePSV/I2+\nepECzSszP69iz558UOOTWxktkdJXqhHSJJo35W61Iyp+F3yvAHlQG08dX9yH\n2E2TBi5w9alPgc940he2IUsAOsSdSTgcNtsFFfqBNV6wHoQUsrC2ARb025+d\ngxgogvxmMfTD6gi2XWv3Abeg9GM8YPjpICdKQlCO3VoB/5nLauj8FAJkZ4eN\nzwD+7AB3RxwQbKkESzIjVQ6Ix3U3npKV/dkyZuJsEbCVkRZLL2oD69WAQau4\nGWMY\r\n=Y/p5\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFsg3D2DPuoBpjQeTuahWolHBfL1fE0rvtbHXYIFpj/JAiBUeW7E/MD++IAbid2c7Y5TGXtPyMO6tqdCHPdh/V+Qhw=="}],"size":10901,"noattachment":false,"key":"/regexpu-core/-/regexpu-core-4.3.0.tgz"},"maintainers":[{"name":"mathias","email":"mathias@qiwi.be"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/regexpu-core_4.3.0_1544002998178_0.6804099314582548"},"_hasShrinkwrap":false,"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#### 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- `modifiers` - [Inline `m`/`s`/`i` 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#### 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":1544002998334,"_cnpm_publish_time":1544002998334,"dist-tags":{"latest":"6.5.4"}}