{ "_args": [ [ { "raw": "regenerate@^1.2.1", "scope": null, "escapedName": "regenerate", "name": "regenerate", "rawSpec": "^1.2.1", "spec": ">=1.2.1 <2.0.0", "type": "range" }, "/Volumes/2009-SSD/GT2/GT2-iOS/node_modules/regexpu-core" ] ], "_from": "regenerate@>=1.2.1 <2.0.0", "_id": "regenerate@1.3.3", "_inCache": true, "_location": "/regenerate", "_nodeVersion": "8.1.2", "_npmOperationalInternal": { "host": "s3://npm-registry-packages", "tmp": "tmp/regenerate-1.3.3.tgz_1505744276299_0.4259878061711788" }, "_npmUser": { "name": "mathias", "email": "mathias@qiwi.be" }, "_npmVersion": "5.4.1", "_phantomChildren": {}, "_requested": { "raw": "regenerate@^1.2.1", "scope": null, "escapedName": "regenerate", "name": "regenerate", "rawSpec": "^1.2.1", "spec": ">=1.2.1 <2.0.0", "type": "range" }, "_requiredBy": [ "/regexpu-core" ], "_resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.3.3.tgz", "_shasum": "0c336d3980553d755c39b586ae3b20aa49c82b7f", "_shrinkwrap": null, "_spec": "regenerate@^1.2.1", "_where": "/Volumes/2009-SSD/GT2/GT2-iOS/node_modules/regexpu-core", "author": { "name": "Mathias Bynens", "url": "https://mathiasbynens.be/" }, "bugs": { "url": "https://github.com/mathiasbynens/regenerate/issues" }, "dependencies": {}, "description": "Generate JavaScript-compatible regular expressions based on a given set of Unicode symbols or code points.", "devDependencies": { "codecov": "^1.0.1", "grunt": "^0.4.5", "grunt-shell": "^1.1.1", "istanbul": "^0.4.3", "qunit-extras": "^1.1.0", "qunitjs": "~1.11.0", "requirejs": "^2.1.15" }, "directories": {}, "dist": { "integrity": "sha512-jVpo1GadrDAK59t/0jRx5VxYWQEDkkEKi6+HjE3joFVLfDOh9Xrdh0dF1eSq+BI/SwvTQ44gSscJ8N5zYL61sg==", "shasum": "0c336d3980553d755c39b586ae3b20aa49c82b7f", "tarball": "https://registry.npmjs.org/regenerate/-/regenerate-1.3.3.tgz" }, "gitHead": "d34ae9be511306a872b742d8421ae18c4ffdc0bf", "homepage": "https://mths.be/regenerate", "keywords": [ "regex", "regexp", "javascript", "unicode", "generator", "tool" ], "license": "MIT", "main": "regenerate.js", "maintainers": [ { "name": "mathias", "email": "mathias@qiwi.be" } ], "name": "regenerate", "optionalDependencies": {}, "readme": "# Regenerate [![Build status](https://travis-ci.org/mathiasbynens/regenerate.svg?branch=master)](https://travis-ci.org/mathiasbynens/regenerate) [![Code coverage status](https://img.shields.io/codecov/c/github/mathiasbynens/regenerate.svg)](https://codecov.io/gh/mathiasbynens/regenerate) [![Dependency status](https://gemnasium.com/mathiasbynens/regenerate.svg)](https://gemnasium.com/mathiasbynens/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\nVia [Component](https://github.com/component/component):\n\n```bash\ncomponent install mathiasbynens/regenerate\n```\n\nIn a browser:\n\n```html\n\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 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(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. 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. You may want to install Istanbul _globally_ using `npm install istanbul -g`.\n\nOnce that’s done, you can run the unit tests in Node using `npm test` or `node tests/tests.js`. To run the tests in Rhino, Ringo, Narwhal, and web browsers as well, use `grunt test`.\n\nTo generate the code coverage report, use `grunt 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", "readmeFilename": "README.md", "repository": { "type": "git", "url": "git+https://github.com/mathiasbynens/regenerate.git" }, "scripts": { "cover": "istanbul cover --report html --verbose --dir coverage tests/tests.js", "test": "node tests/tests.js" }, "version": "1.3.3" }