{"_id":"regenerate@1.5.0","bugs":{"url":"https://github.com/mathiasbynens/regenerate/issues"},"dist":{"shasum":"d84f6e20e9990aa2d381fd28a7674f5d707049a3","tarball":"http://registry-npm.ywwl.com/regenerate/download/regenerate-1.5.0.tgz","fileCount":4,"integrity":"sha512-1s+CxXjJ71i7LNVy8nYwg47XV4y6lAnOEhsMtSKq3WpmPfhl9LuKlTqKIn/3yUpE8lBz+W+TT88Bxyhnr0U4yw==","signatures":[{"sig":"MEQCID7CrgMlvyMAPTlmlmS73k0LAwqwz9zdRMyxOj5s/arWAiBAalSky2nj+owwzPd9A4JzavrFuq+XwtjN8Uq2nVjABw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCKRJ7O7Vv8QHwdhyWpR7627qhetkWoV4UxHiJGaw6yawIhAOyWxzs67jydVq4x50Qr40DIvEaYTSDQJCiqBx9eof7p"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/regenerate@1.5.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":51481,"size":13620,"noattachment":false,"key":"/regenerate/-/regenerate-1.5.0.tgz"},"main":"regenerate.js","name":"regenerate","author":{"url":"https://mathiasbynens.be/","name":"Mathias Bynens"},"gitHead":"32bfb6147ac8061897cc9f19126c3783b6cf7d31","license":"MIT","scripts":{"test":"node --test tests/tests.js","bench":"node --experimental-bench --bench benchmark.mjs","cover":"NODE_V8_COVERAGE=coverage node --test --experimental-test-coverage tests/tests.js","test-node6":"mocha tests"},"version":"1.5.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"c5522a98-b6fd-4041-81fe-e0d189544323"}},"homepage":"https://mths.be/regenerate","keywords":["regex","regexp","javascript","unicode","generator","tool"],"repository":{"url":"git+https://github.com/mathiasbynens/regenerate.git","type":"git"},"_npmVersion":"11.19.1","description":"Generate JavaScript-compatible regular expressions based on a given set of Unicode symbols or code points.","directories":{},"maintainers":[{"name":"mathias","email":"mathias@qiwi.be"}],"_nodeVersion":"26.10.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/regenerate_1.5.0_1791126126397_0.40426660199941855"},"readme":"# Regenerate [![Build status](https://github.com/mathiasbynens/regenerate/workflows/run-checks/badge.svg)](https://github.com/mathiasbynens/regenerate/actions?query=workflow%3Arun-checks) [![Coverage status](https://coveralls.io/repos/github/mathiasbynens/regenerate/badge.svg?branch=main)](https://coveralls.io/github/mathiasbynens/regenerate?branch=main) [![regenerate on npm](https://img.shields.io/npm/v/regenerate)](https://www.npmjs.com/package/regenerate)\n\n_Regenerate_ is a Unicode-aware regex generator for JavaScript. It allows you to easily generate ES5-compatible regular expressions based on a given set of Unicode symbols or code points. (This is trickier than you might think, because of [how JavaScript deals with astral symbols](https://mathiasbynens.be/notes/javascript-unicode).)\n\n## Installation\n\nVia [npm](https://npmjs.org/):\n\n```bash\nnpm install regenerate\n```\n\nVia [Bower](http://bower.io/):\n\n```bash\nbower install regenerate\n```\n\nIn a browser:\n\n```html\n<script src=\"regenerate.js\"></script>\n```\n\nIn [Node.js](https://nodejs.org/), [io.js](https://iojs.org/), and [RingoJS ≥ v0.8.0](http://ringojs.org/):\n\n```js\nvar regenerate = require('regenerate');\n```\n\nIn [Narwhal](http://narwhaljs.org/) and [RingoJS ≤ v0.7.0](http://ringojs.org/):\n\n```js\nvar regenerate = require('regenerate').regenerate;\n```\n\nIn [Rhino](http://www.mozilla.org/rhino/):\n\n```js\nload('regenerate.js');\n```\n\nUsing an AMD loader like [RequireJS](http://requirejs.org/):\n\n```js\nrequire(\n  {\n    'paths': {\n      'regenerate': 'path/to/regenerate'\n    }\n  },\n  ['regenerate'],\n  function(regenerate) {\n    console.log(regenerate);\n  }\n);\n```\n\n## API\n\n### `regenerate(value1, value2, value3, ...)`\n\nThe main Regenerate function. Calling this function creates a new set that gets a chainable API.\n\n```js\nvar set = regenerate()\n  .addRange(0x60, 0x69) // add U+0060 to U+0069\n  .remove(0x62, 0x64) // remove U+0062 and U+0064\n  .add(0x1D306); // add U+1D306\nset.valueOf();\n// → [0x60, 0x61, 0x63, 0x65, 0x66, 0x67, 0x68, 0x69, 0x1D306]\nset.toString();\n// → '[`ace-i]|\\\\uD834\\\\uDF06'\nset.toRegExp();\n// → /[`ace-i]|\\uD834\\uDF06/\n```\n\nAny arguments passed to `regenerate()` will be added to the set right away. Both code points (numbers) and symbols (strings consisting of a single Unicode symbol) are accepted, as well as arrays containing values of these types.\n\n```js\nregenerate(0x1D306, 'A', '©', 0x2603).toString();\n// → '[A\\\\xA9\\\\u2603]|\\\\uD834\\\\uDF06'\n\nvar items = [0x1D306, 'A', '©', 0x2603];\nregenerate(items).toString();\n// → '[A\\\\xA9\\\\u2603]|\\\\uD834\\\\uDF06'\n```\n\n### `regenerate.prototype.add(value1, value2, value3, ...)`\n\nAny arguments passed to `add()` are added to the set. Both code points (numbers) and symbols (strings consisting of a single Unicode symbol) are accepted, as well as arrays containing values of these types.\n\n```js\nregenerate().add(0x1D306, 'A', '©', 0x2603).toString();\n// → '[A\\\\xA9\\\\u2603]|\\\\uD834\\\\uDF06'\n\nvar items = [0x1D306, 'A', '©', 0x2603];\nregenerate().add(items).toString();\n// → '[A\\\\xA9\\\\u2603]|\\\\uD834\\\\uDF06'\n```\n\nIt’s also possible to pass in a Regenerate instance. Doing so adds all code points in that instance to the current set.\n\n```js\nvar set = regenerate(0x1D306, 'A');\nregenerate().add('©', 0x2603).add(set).toString();\n// → '[A\\\\xA9\\\\u2603]|\\\\uD834\\\\uDF06'\n```\n\nNote that the initial call to `regenerate()` acts like `add()`. This allows you to create a new Regenerate instance and add some code points to it in one go:\n\n```js\nregenerate(0x1D306, 'A', '©', 0x2603).toString();\n// → '[A\\\\xA9\\\\u2603]|\\\\uD834\\\\uDF06'\n```\n\n### `regenerate.prototype.remove(value1, value2, value3, ...)`\n\nAny arguments passed to `remove()` are removed from the set. Both code points (numbers) and symbols (strings consisting of a single Unicode symbol) are accepted, as well as arrays containing values of these types.\n\n```js\nregenerate(0x1D306, 'A', '©', 0x2603).remove('☃').toString();\n// → '[A\\\\xA9]|\\\\uD834\\\\uDF06'\n```\n\nIt’s also possible to pass in a Regenerate instance. Doing so removes all code points in that instance from the current set.\n\n```js\nvar set = regenerate('☃');\nregenerate(0x1D306, 'A', '©', 0x2603).remove(set).toString();\n// → '[A\\\\xA9]|\\\\uD834\\\\uDF06'\n```\n\n### `regenerate.prototype.addRange(start, end)`\n\nAdds a range of code points from `start` to `end` (inclusive) to the set. Both code points (numbers) and symbols (strings consisting of a single Unicode symbol) are accepted.\n\n```js\nregenerate(0x1D306).addRange(0x00, 0xFF).toString(16);\n// → '[\\\\0-\\\\xFF]|\\\\uD834\\\\uDF06'\n\nregenerate().addRange('A', 'z').toString();\n// → '[A-z]'\n```\n\n### `regenerate.prototype.removeRange(start, end)`\n\nRemoves a range of code points from `start` to `end` (inclusive) from the set. Both code points (numbers) and symbols (strings consisting of a single Unicode symbol) are accepted.\n\n```js\nregenerate()\n  .addRange(0x000000, 0x10FFFF) // add all Unicode code points\n  .removeRange('A', 'z') // remove all symbols from `A` to `z`\n  .toString();\n// → '[\\\\0-@\\\\{-\\\\uD7FF\\\\uE000-\\\\uFFFF]|[\\\\uD800-\\\\uDBFF][\\\\uDC00-\\\\uDFFF]|[\\\\uD800-\\\\uDBFF](?![\\\\uDC00-\\\\uDFFF])|(?:[^\\\\uD800-\\\\uDBFF]|^)[\\\\uDC00-\\\\uDFFF]'\n\nregenerate()\n  .addRange(0x000000, 0x10FFFF) // add all Unicode code points\n  .removeRange(0x0041, 0x007A) // remove all code points from U+0041 to U+007A\n  .toString();\n// → '[\\\\0-@\\\\{-\\\\uD7FF\\\\uE000-\\\\uFFFF]|[\\\\uD800-\\\\uDBFF][\\\\uDC00-\\\\uDFFF]|[\\\\uD800-\\\\uDBFF](?![\\\\uDC00-\\\\uDFFF])|(?:[^\\\\uD800-\\\\uDBFF]|^)[\\\\uDC00-\\\\uDFFF]'\n```\n\n### `regenerate.prototype.intersection(codePoints)`\n\nRemoves any code points from the set that are not present in both the set and the given `codePoints` array. `codePoints` must be an array of numeric code point values, i.e. numbers.\n\n```js\nregenerate()\n  .addRange(0x00, 0xFF) // add extended ASCII code points\n  .intersection([0x61, 0x69]) // remove all code points from the set except for these\n  .toString();\n// → '[ai]'\n```\n\nInstead of the `codePoints` array, it’s also possible to pass in a Regenerate instance.\n\n```js\nvar whitelist = regenerate(0x61, 0x69);\n\nregenerate()\n  .addRange(0x00, 0xFF) // add extended ASCII code points\n  .intersection(whitelist) // remove all code points from the set except for those in the `whitelist` set\n  .toString();\n// → '[ai]'\n```\n\n### `regenerate.prototype.contains(value)`\n\nReturns `true` if the given value is part of the set, and `false` otherwise. Both code points (numbers) and symbols (strings consisting of a single Unicode symbol) are accepted.\n\n```js\nvar set = regenerate().addRange(0x00, 0xFF);\nset.contains('A');\n// → true\nset.contains(0x1D306);\n// → false\n```\n\n### `regenerate.prototype.clone()`\n\nReturns a clone of the current code point set. Any actions performed on the clone won’t mutate the original set.\n\n```js\nvar setA = regenerate(0x1D306);\nvar setB = setA.clone().add(0x1F4A9);\nsetA.toArray();\n// → [0x1D306]\nsetB.toArray();\n// → [0x1D306, 0x1F4A9]\n```\n\n### `regenerate.prototype.toString(options)`\n\nReturns a string representing (part of) a regular expression that matches all the symbols mapped to the code points within the set.\n\n```js\nregenerate(0x1D306, 0x1F4A9).toString();\n// → '\\\\uD834\\\\uDF06|\\\\uD83D\\\\uDCA9'\n```\n\nIf the `bmpOnly` property of the optional `options` object is set to `true`, the output matches surrogates individually, regardless of whether they’re lone surrogates or just part of a surrogate pair. This simplifies the output, but it can only be used in case you’re certain the strings it will be used on don’t contain any astral symbols.\n\n```js\nvar highSurrogates = regenerate().addRange(0xD800, 0xDBFF);\nhighSurrogates.toString();\n// → '[\\\\uD800-\\\\uDBFF](?![\\\\uDC00-\\\\uDFFF])'\nhighSurrogates.toString({ 'bmpOnly': true });\n// → '[\\\\uD800-\\\\uDBFF]'\n\nvar lowSurrogates = regenerate().addRange(0xDC00, 0xDFFF);\nlowSurrogates.toString();\n// → '(?:[^\\\\uD800-\\\\uDBFF]|^)[\\\\uDC00-\\\\uDFFF]'\nlowSurrogates.toString({ 'bmpOnly': true });\n// → '[\\\\uDC00-\\\\uDFFF]'\n```\n\nNote that lone low surrogates cannot be matched accurately using regular expressions in JavaScript without the use of [lookbehind assertions](https://mathiasbynens.be/notes/es-regexp-proposals#lookbehinds), which aren't yet widely supported. Regenerate’s output makes a best-effort approach but [there can be false negatives in this regard](https://github.com/mathiasbynens/regenerate/issues/28#issuecomment-72224808).\n\nIf the `hasUnicodeFlag` property of the optional `options` object is set to `true`, the output makes use of Unicode code point escapes (`\\u{…}`) where applicable. This simplifies the output at the cost of compatibility and portability, since it means the output can only be used as a pattern in a regular expression with [the ES6 `u` flag](https://mathiasbynens.be/notes/es6-unicode-regex) enabled.\n\n```js\nvar set = regenerate().addRange(0x0, 0x10FFFF);\n\nset.toString();\n// → '[\\\\0-\\\\uD7FF\\\\uE000-\\\\uFFFF]|[\\\\uD800-\\\\uDBFF][\\\\uDC00-\\\\uDFFF]|[\\\\uD800-\\\\uDBFF](?![\\\\uDC00-\\\\uDFFF])|(?:[^\\\\uD800-\\\\uDBFF]|^)[\\\\uDC00-\\\\uDFFF]'\n\nset.toString({ 'hasUnicodeFlag': true });\n// → '[\\\\0-\\\\u{10FFFF}]'\n```\n\n### `regenerate.prototype.toRegExp(flags = '')`\n\nReturns a regular expression that matches all the symbols mapped to the code points within the set. Optionally, you can pass [flags](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#Parameters) to be added to the regular expression.\n\n```js\nvar regex = regenerate(0x1D306, 0x1F4A9).toRegExp();\n// → /\\uD834\\uDF06|\\uD83D\\uDCA9/\nregex.test('𝌆');\n// → true\nregex.test('A');\n// → false\n\n// With flags:\nvar regex = regenerate(0x1D306, 0x1F4A9).toRegExp('g');\n// → /\\uD834\\uDF06|\\uD83D\\uDCA9/g\n```\n\n**Note:** This probably shouldn’t be used. Regenerate is intended as a tool that is used as part of a build process, not at runtime.\n\n### `regenerate.prototype.valueOf()` or `regenerate.prototype.toArray()`\n\nReturns a sorted array of unique code points in the set.\n\n```js\nregenerate(0x1D306)\n  .addRange(0x60, 0x65)\n  .add(0x59, 0x60) // note: 0x59 is added after 0x65, and 0x60 is a duplicate\n  .valueOf();\n// → [0x59, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x1D306]\n```\n\n### `regenerate.version`\n\nA string representing the semantic version number.\n\n## Combine Regenerate with other libraries\n\nRegenerate gets even better when combined with other libraries such as [Punycode.js](https://mths.be/punycode). Here’s an example where [Punycode.js](https://mths.be/punycode) is used to convert a string into an array of code points, that is then passed on to Regenerate:\n\n```js\nvar regenerate = require('regenerate');\nvar punycode = require('punycode');\n\nvar string = 'Lorem ipsum dolor sit amet.';\n// Get an array of all code points used in the string:\nvar codePoints = punycode.ucs2.decode(string);\n\n// Generate a regular expression that matches any of the symbols used in the string:\nregenerate(codePoints).toString();\n// → '[ \\\\.Ladeilmopr-u]'\n```\n\nIn ES6 you can do something similar with [`Array.from`](https://mths.be/array-from) which uses [the string’s iterator](https://mathiasbynens.be/notes/javascript-unicode#iterating-over-symbols) to split the given string into an array of strings that each contain a single symbol. [`regenerate()`](#regenerateprototypeaddvalue1-value2-value3-) accepts both strings and code points, remember?\n\n```js\nvar regenerate = require('regenerate');\n\nvar string = 'Lorem ipsum dolor sit amet.';\n// Get an array of all symbols used in the string:\nvar symbols = Array.from(string);\n\n// Generate a regular expression that matches any of the symbols used in the string:\nregenerate(symbols).toString();\n// → '[ \\\\.Ladeilmopr-u]'\n```\n\n## Support\n\nRegenerate supports at least Chrome 27+, Firefox 3+, Safari 4+, Opera 10+, IE 6+, Node.js v0.10.0+, io.js v1.0.0+, Narwhal 0.3.2+, RingoJS 0.8+, PhantomJS 1.9.0+, and Rhino 1.7RC4+.\n\n## Unit tests & code coverage\n\nAfter cloning this repository, run `npm install` to install the dependencies needed for Regenerate development and testing.\n\nOnce that’s done, you can run the unit tests in Node using `npm test`. To run them in Node.js 6, install Mocha 6 using `npm install mocha@6` and use `npm run test-node6`.\n\nTo generate the code coverage report, use `npm run cover`.\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\nRegenerate is available under the [MIT](https://mths.be/mit) license.\n","publish_time":1791126126507,"_cnpm_publish_time":1791126126507,"dist-tags":{"latest":"1.5.0"}}