[Pkg-javascript-commits] [node-regenerate] 01/03: Imported Upstream version 1.2.1
Julien Puydt
julien.puydt at laposte.net
Fri Oct 16 17:26:34 UTC 2015
This is an automated email from the git hooks/post-receive script.
jpuydt-guest pushed a commit to branch master
in repository node-regenerate.
commit 74e8e2ab8cb57d4966247b8ce0e68d031a3d3699
Author: Julien Puydt <julien.puydt at laposte.net>
Date: Fri Oct 16 16:07:56 2015 +0200
Imported Upstream version 1.2.1
---
.gitattributes | 2 +
.gitignore | 17 +
.npmignore | 7 +
.travis.yml | 20 +
Gruntfile.js | 66 ++++
LICENSE-MIT.txt | 20 +
README.md | 332 ++++++++++++++++
bower.json | 14 +
component.json | 18 +
package.json | 37 ++
regenerate.js | 1158 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
tests/index.html | 35 ++
tests/tests.js | 806 +++++++++++++++++++++++++++++++++++++
13 files changed, 2532 insertions(+)
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..0a91f75
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+# Automatically normalize line endings for all text-based files
+* text=auto
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..444ec4d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,17 @@
+# Coverage report
+coverage
+
+# Installed npm modules
+node_modules
+
+# Folder view configuration files
+.DS_Store
+Desktop.ini
+
+# Thumbnail cache files
+._*
+Thumbs.db
+
+# Files that might appear on external disks
+.Spotlight-V100
+.Trashes
diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..44dac75
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1,7 @@
+.*
+*.md
+coverage
+tests
+bower.json
+component.json
+Gruntfile.js
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..74f02a3
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,20 @@
+language: node_js
+node_js:
+ - "0.10"
+before_script:
+ - "npm install -g grunt-cli"
+ # Narwhal uses a hardcoded path to openjdk v6, so use that version
+ - "sudo apt-get update -qq"
+ - "sudo apt-get install -qq openjdk-6-jre"
+ - "PACKAGE=rhino1_7R3; wget http://ftp.mozilla.org/pub/mozilla.org/js/$PACKAGE.zip && sudo unzip $PACKAGE -d /opt/ && rm $PACKAGE.zip"
+ - "PACKAGE=rhino1_7R3; echo -e '#!/bin/sh\\njava -jar /opt/'$PACKAGE'/js.jar $@' | sudo tee /usr/local/bin/rhino && sudo chmod +x /usr/local/bin/rhino"
+ - "PACKAGE=ringojs-0.11; wget https://github.com/ringo/ringojs/releases/download/v0.11.0/$PACKAGE.zip && sudo unzip $PACKAGE -d /opt/ && rm $PACKAGE.zip"
+ - "PACKAGE=ringojs-0.11; sudo ln -s /opt/$PACKAGE/bin/ringo /usr/local/bin/ringo && sudo chmod +x /usr/local/bin/ringo"
+ - "PACKAGE=v0.3.2; wget https://github.com/280north/narwhal/archive/$PACKAGE.zip && sudo unzip $PACKAGE -d /opt/ && rm $PACKAGE.zip"
+ - "PACKAGE=narwhal-0.3.2; sudo ln -s /opt/$PACKAGE/bin/narwhal /usr/local/bin/narwhal && sudo chmod +x /usr/local/bin/narwhal"
+ # If the enviroment stores rt.jar in a different directory, find it and symlink the directory
+ - "PREFIX=/usr/lib/jvm; if [ ! -d $PREFIX/java-6-openjdk ]; then for d in $PREFIX/java-6-openjdk-*; do if [ -e $d/jre/lib/rt.jar ]; then sudo ln -s $d $PREFIX/java-6-openjdk; break; fi; done; fi"
+script:
+ - "grunt ci"
+after_script:
+ - "grunt shell:cover-coveralls"
diff --git a/Gruntfile.js b/Gruntfile.js
new file mode 100644
index 0000000..9baae57
--- /dev/null
+++ b/Gruntfile.js
@@ -0,0 +1,66 @@
+module.exports = function(grunt) {
+
+ grunt.initConfig({
+ 'shell': {
+ 'options': {
+ 'stdout': true,
+ 'stderr': true,
+ 'failOnError': true
+ },
+ 'cover-html': {
+ 'command': 'istanbul cover --report "html" --verbose --dir "coverage" "tests/tests.js"'
+ },
+ 'cover-coveralls': {
+ 'command': 'istanbul cover --verbose --dir "coverage" "tests/tests.js" && cat coverage/lcov.info | coveralls; rm -rf coverage/lcov*'
+ },
+ 'test-narwhal': {
+ 'command': 'echo "Testing in Narwhal..."; export NARWHAL_OPTIMIZATION=-1; narwhal "tests/tests.js"'
+ },
+ 'test-phantomjs': {
+ 'command': 'echo "Testing in PhantomJS..."; phantomjs "tests/tests.js"'
+ },
+ // Rhino 1.7R4 has a bug that makes it impossible to test in.
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=775566
+ // To test, use Rhino 1.7R3, or wait (heh) for the 1.7R5 release.
+ 'test-rhino': {
+ 'command': 'echo "Testing in Rhino..."; rhino -opt -1 "tests.js"',
+ 'options': {
+ 'execOptions': {
+ 'cwd': 'tests'
+ }
+ }
+ },
+ 'test-ringo': {
+ 'command': 'echo "Testing in Ringo..."; ringo -o -1 "tests/tests.js"'
+ },
+ 'test-node': {
+ 'command': 'echo "Testing in Node..."; node "tests/tests.js"'
+ },
+ 'test-browser': {
+ 'command': 'echo "Testing in a browser..."; open "tests/index.html"'
+ }
+ }
+ });
+
+ grunt.loadNpmTasks('grunt-shell');
+
+ grunt.registerTask('cover', 'shell:cover-html');
+ grunt.registerTask('ci', [
+ 'shell:test-narwhal',
+ 'shell:test-phantomjs',
+ 'shell:test-rhino',
+ 'shell:test-ringo',
+ 'shell:test-node',
+ 'shell:cover-html'
+ ]);
+ grunt.registerTask('test', [
+ 'ci',
+ 'shell:test-browser'
+ ]);
+
+ grunt.registerTask('default', [
+ 'shell:test-node',
+ 'cover'
+ ]);
+
+};
diff --git a/LICENSE-MIT.txt b/LICENSE-MIT.txt
new file mode 100644
index 0000000..a41e0a7
--- /dev/null
+++ b/LICENSE-MIT.txt
@@ -0,0 +1,20 @@
+Copyright Mathias Bynens <https://mathiasbynens.be/>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..d4f3a3f
--- /dev/null
+++ b/README.md
@@ -0,0 +1,332 @@
+# Regenerate [![Build status](https://travis-ci.org/mathiasbynens/regenerate.svg?branch=master)](https://travis-ci.org/mathiasbynens/regenerate) [![Code coverage status](http://img.shields.io/coveralls/mathiasbynens/regenerate/master.svg)](https://coveralls.io/r/mathiasbynens/regenerate) [![Dependency status](https://gemnasium.com/mathiasbynens/regenerate.svg)](https://gemnasium.com/mathiasbynens/regenerate)
+
+_Regenerate_ is a Unicode-aware regex generator for JavaScript. It allows you to easily generate JavaScript-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).)
+
+Feel free to fork if you see possible improvements!
+
+## Installation
+
+Via [npm](https://npmjs.org/):
+
+```bash
+npm install regenerate
+```
+
+Via [Bower](http://bower.io/):
+
+```bash
+bower install regenerate
+```
+
+Via [Component](https://github.com/component/component):
+
+```bash
+component install mathiasbynens/regenerate
+```
+
+In a browser:
+
+```html
+<script src="regenerate.js"></script>
+```
+
+In [Node.js](https://nodejs.org/), [io.js](https://iojs.org/), and [RingoJS ≥ v0.8.0](http://ringojs.org/):
+
+```js
+var regenerate = require('regenerate');
+```
+
+In [Narwhal](http://narwhaljs.org/) and [RingoJS ≤ v0.7.0](http://ringojs.org/):
+
+```js
+var regenerate = require('regenerate').regenerate;
+```
+
+In [Rhino](http://www.mozilla.org/rhino/):
+
+```js
+load('regenerate.js');
+```
+
+Using an AMD loader like [RequireJS](http://requirejs.org/):
+
+```js
+require(
+ {
+ 'paths': {
+ 'regenerate': 'path/to/regenerate'
+ }
+ },
+ ['regenerate'],
+ function(regenerate) {
+ console.log(regenerate);
+ }
+);
+```
+
+## API
+
+### `regenerate(value1, value2, value3, ...)`
+
+The main Regenerate function. Calling this function creates a new set that gets a chainable API.
+
+```js
+var set = regenerate()
+ .addRange(0x60, 0x69) // add U+0060 to U+0069
+ .remove(0x62, 0x64) // remove U+0062 and U+0064
+ .add(0x1D306); // add U+1D306
+set.valueOf();
+// → [0x60, 0x61, 0x63, 0x65, 0x66, 0x67, 0x68, 0x69, 0x1D306]
+set.toString();
+// → '[`ace-i]|\\uD834\\uDF06'
+set.toRegExp();
+// → /[`ace-i]|\uD834\uDF06/
+```
+
+Any 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.
+
+```js
+regenerate(0x1D306, 'A', '©', 0x2603).toString();
+// → '[A\\xA9\\u2603]|\\uD834\\uDF06'
+
+var items = [0x1D306, 'A', '©', 0x2603];
+regenerate(items).toString();
+// → '[A\\xA9\\u2603]|\\uD834\\uDF06'
+```
+
+### `regenerate.prototype.add(value1, value2, value3, ...)`
+
+Any 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.
+
+```js
+regenerate().add(0x1D306, 'A', '©', 0x2603).toString();
+// → '[A\\xA9\\u2603]|\\uD834\\uDF06'
+
+var items = [0x1D306, 'A', '©', 0x2603];
+regenerate().add(items).toString();
+// → '[A\\xA9\\u2603]|\\uD834\\uDF06'
+```
+
+It’s also possible to pass in a Regenerate instance. Doing so adds all code points in that instance to the current set.
+
+```js
+var set = regenerate(0x1D306, 'A');
+regenerate().add('©', 0x2603).add(set).toString();
+// → '[A\\xA9\\u2603]|\\uD834\\uDF06'
+```
+
+Note 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:
+
+```js
+regenerate(0x1D306, 'A', '©', 0x2603).toString();
+// → '[A\\xA9\\u2603]|\\uD834\\uDF06'
+```
+
+### `regenerate.prototype.remove(value1, value2, value3, ...)`
+
+Any 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.
+
+```js
+regenerate(0x1D306, 'A', '©', 0x2603).remove('☃').toString();
+// → '[A\\xA9]|\\uD834\\uDF06'
+```
+
+It’s also possible to pass in a Regenerate instance. Doing so removes all code points in that instance from the current set.
+
+```js
+var set = regenerate('☃');
+regenerate(0x1D306, 'A', '©', 0x2603).remove(set).toString();
+// → '[A\\xA9]|\\uD834\\uDF06'
+```
+
+### `regenerate.prototype.addRange(start, end)`
+
+Adds 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.
+
+```js
+regenerate(0x1D306).addRange(0x00, 0xFF).toString(16);
+// → '[\\0-\\xFF]|\\uD834\\uDF06'
+
+regenerate().addRange('A', 'z').toString();
+// → '[A-z]'
+```
+
+### `regenerate.prototype.removeRange(start, end)`
+
+Removes 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.
+
+```js
+regenerate()
+ .addRange(0x000000, 0x10FFFF) // add all Unicode code points
+ .removeRange('A', 'z') // remove all symbols from `A` to `z`
+ .toString();
+// → '[\\0-@\\{-\\uD7FF\\uE000-\\uFFFF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF]'
+
+regenerate()
+ .addRange(0x000000, 0x10FFFF) // add all Unicode code points
+ .removeRange(0x0041, 0x007A) // remove all code points from U+0041 to U+007A
+ .toString();
+// → '[\\0-@\\{-\\uD7FF\\uE000-\\uFFFF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF]'
+```
+
+### `regenerate.prototype.intersection(codePoints)`
+
+Removes 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.
+
+```js
+regenerate()
+ .addRange(0x00, 0xFF) // add extended ASCII code points
+ .intersection([0x61, 0x69]) // remove all code points from the set except for these
+ .toString();
+// → '[ai]'
+```
+
+Instead of the `codePoints` array, it’s also possible to pass in a Regenerate instance.
+
+```js
+var whitelist = regenerate(0x61, 0x69);
+
+regenerate()
+ .addRange(0x00, 0xFF) // add extended ASCII code points
+ .intersection(whitelist) // remove all code points from the set except for those in the `whitelist` set
+ .toString();
+// → '[ai]'
+```
+
+### `regenerate.prototype.contains(value)`
+
+Returns `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.
+
+```js
+var set = regenerate().addRange(0x00, 0xFF);
+set.contains('A');
+// → true
+set.contains(0x1D306);
+// → false
+```
+
+### `regenerate.prototype.clone()`
+
+Returns a clone of the current code point set. Any actions performed on the clone won’t mutate the original set.
+
+```js
+var setA = regenerate(0x1D306);
+var setB = setA.clone().add(0x1F4A9);
+setA.toArray();
+// → [0x1D306]
+setB.toArray();
+// → [0x1D306, 0x1F4A9]
+```
+
+### `regenerate.prototype.toString(options)`
+
+Returns a string representing (part of) a regular expression that matches all the symbols mapped to the code points within the set.
+
+```js
+regenerate(0x1D306, 0x1F4A9).toString();
+// → '\\uD834\\uDF06|\\uD83D\\uDCA9'
+```
+
+If 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.
+
+```js
+var highSurrogates = regenerate().addRange(0xD800, 0xDBFF);
+highSurrogates.toString();
+// → '[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])'
+highSurrogates.toString({ 'bmpOnly': true });
+// → '[\\uD800-\\uDBFF]'
+
+var lowSurrogates = regenerate().addRange(0xDC00, 0xDFFF);
+lowSurrogates.toString();
+// → '(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF]'
+lowSurrogates.toString({ 'bmpOnly': true });
+// → '[\\uDC00-\\uDFFF]'
+```
+
+### `regenerate.prototype.toRegExp(flags = '')`
+
+Returns 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.
+
+```js
+var regex = regenerate(0x1D306, 0x1F4A9).toRegExp();
+// → /\uD834\uDF06|\uD83D\uDCA9/
+regex.test('𝌆');
+// → true
+regex.test('A');
+// → false
+
+// With flags:
+var regex = regenerate(0x1D306, 0x1F4A9).toRegExp('g');
+// → /\uD834\uDF06|\uD83D\uDCA9/g
+```
+
+**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.
+
+### `regenerate.prototype.valueOf()` or `regenerate.prototype.toArray()`
+
+Returns a sorted array of unique code points in the set.
+
+```js
+regenerate(0x1D306)
+ .addRange(0x60, 0x65)
+ .add(0x59, 0x60) // note: 0x59 is added after 0x65, and 0x60 is a duplicate
+ .valueOf();
+// → [0x59, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x1D306]
+```
+
+### `regenerate.version`
+
+A string representing the semantic version number.
+
+## Combine Regenerate with other libraries
+
+Regenerate 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:
+
+```js
+var regenerate = require('regenerate');
+var punycode = require('punycode');
+
+var string = 'Lorem ipsum dolor sit amet.';
+// Get an array of all code points used in the string:
+var codePoints = punycode.ucs2.decode(string);
+
+// Generate a regular expression that matches any of the symbols used in the string:
+regenerate(codePoints).toString();
+// → '[ \\.Ladeilmopr-u]'
+```
+
+In 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?
+
+```js
+var regenerate = require('regenerate');
+
+var string = 'Lorem ipsum dolor sit amet.';
+// Get an array of all symbols used in the string:
+var codePoints = Array.from(string);
+
+// Generate a regular expression that matches any of the symbols used in the string:
+regenerate(codePoints).toString();
+// → '[ \\.Ladeilmopr-u]'
+```
+
+## Support
+
+Regenerate 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+.
+
+## Unit tests & code coverage
+
+After 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`.
+
+Once 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`.
+
+To generate the code coverage report, use `grunt cover`.
+
+## Author
+
+| [![twitter/mathias](https://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") |
+|---|
+| [Mathias Bynens](https://mathiasbynens.be/) |
+
+## License
+
+Regenerate is available under the [MIT](https://mths.be/mit) license.
diff --git a/bower.json b/bower.json
new file mode 100644
index 0000000..9ce033e
--- /dev/null
+++ b/bower.json
@@ -0,0 +1,14 @@
+{
+ "name": "regenerate",
+ "version": "1.2.1",
+ "main": "regenerate.js",
+ "ignore": [
+ "coverage",
+ "tests",
+ ".*",
+ "component.json",
+ "Gruntfile.js",
+ "node_modules",
+ "package.json"
+ ]
+}
diff --git a/component.json b/component.json
new file mode 100644
index 0000000..ca116ed
--- /dev/null
+++ b/component.json
@@ -0,0 +1,18 @@
+{
+ "name": "regenerate",
+ "version": "1.2.1",
+ "description": "Generate JavaScript-compatible regular expressions based on a given set of Unicode symbols or code points.",
+ "repo": "mathiasbynens/regenerate",
+ "license": "MIT",
+ "scripts": [
+ "regenerate.js"
+ ],
+ "keywords": [
+ "regex",
+ "regexp",
+ "javascript",
+ "unicode",
+ "generator",
+ "tool"
+ ]
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..0ad623c
--- /dev/null
+++ b/package.json
@@ -0,0 +1,37 @@
+{
+ "name": "regenerate",
+ "version": "1.2.1",
+ "description": "Generate JavaScript-compatible regular expressions based on a given set of Unicode symbols or code points.",
+ "homepage": "https://mths.be/regenerate",
+ "main": "regenerate.js",
+ "keywords": [
+ "regex",
+ "regexp",
+ "javascript",
+ "unicode",
+ "generator",
+ "tool"
+ ],
+ "license": "MIT",
+ "author": {
+ "name": "Mathias Bynens",
+ "url": "https://mathiasbynens.be/"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/mathiasbynens/regenerate.git"
+ },
+ "bugs": "https://github.com/mathiasbynens/regenerate/issues",
+ "scripts": {
+ "test": "node tests/tests.js"
+ },
+ "devDependencies": {
+ "coveralls": "^2.11.2",
+ "grunt": "^0.4.5",
+ "grunt-shell": "^1.1.1",
+ "istanbul": "^0.3.2",
+ "qunit-extras": "^1.1.0",
+ "qunitjs": "~1.11.0",
+ "requirejs": "^2.1.15"
+ }
+}
diff --git a/regenerate.js b/regenerate.js
new file mode 100644
index 0000000..06de02c
--- /dev/null
+++ b/regenerate.js
@@ -0,0 +1,1158 @@
+/*! https://mths.be/regenerate v1.2.1 by @mathias | MIT license */
+;(function(root) {
+
+ // Detect free variables `exports`.
+ var freeExports = typeof exports == 'object' && exports;
+
+ // Detect free variable `module`.
+ var freeModule = typeof module == 'object' && module &&
+ module.exports == freeExports && module;
+
+ // Detect free variable `global`, from Node.js or Browserified code,
+ // and use it as `root`.
+ var freeGlobal = typeof global == 'object' && global;
+ if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
+ root = freeGlobal;
+ }
+
+ /*--------------------------------------------------------------------------*/
+
+ var ERRORS = {
+ 'rangeOrder': 'A range\u2019s `stop` value must be greater than or equal ' +
+ 'to the `start` value.',
+ 'codePointRange': 'Invalid code point value. Code points range from ' +
+ 'U+000000 to U+10FFFF.'
+ };
+
+ // https://mathiasbynens.be/notes/javascript-encoding#surrogate-pairs
+ var HIGH_SURROGATE_MIN = 0xD800;
+ var HIGH_SURROGATE_MAX = 0xDBFF;
+ var LOW_SURROGATE_MIN = 0xDC00;
+ var LOW_SURROGATE_MAX = 0xDFFF;
+
+ // In Regenerate output, `\0` will never be preceded by `\` because we sort
+ // by code point value, so let’s keep this regular expression simple.
+ var regexNull = /\\x00([^0123456789]|$)/g;
+
+ var object = {};
+ var hasOwnProperty = object.hasOwnProperty;
+ var extend = function(destination, source) {
+ var key;
+ for (key in source) {
+ if (hasOwnProperty.call(source, key)) {
+ destination[key] = source[key];
+ }
+ }
+ return destination;
+ };
+
+ var forEach = function(array, callback) {
+ var index = -1;
+ var length = array.length;
+ while (++index < length) {
+ callback(array[index], index);
+ }
+ };
+
+ var toString = object.toString;
+ var isArray = function(value) {
+ return toString.call(value) == '[object Array]';
+ };
+ var isNumber = function(value) {
+ return typeof value == 'number' ||
+ toString.call(value) == '[object Number]';
+ };
+
+ // This assumes that `number` is a positive integer that `toString()`s nicely
+ // (which is the case for all code point values).
+ var zeroes = '0000';
+ var pad = function(number, totalCharacters) {
+ var string = String(number);
+ return string.length < totalCharacters
+ ? (zeroes + string).slice(-totalCharacters)
+ : string;
+ };
+
+ var hex = function(number) {
+ return Number(number).toString(16).toUpperCase();
+ };
+
+ var slice = [].slice;
+
+ /*--------------------------------------------------------------------------*/
+
+ var dataFromCodePoints = function(codePoints) {
+ var index = -1;
+ var length = codePoints.length;
+ var max = length - 1;
+ var result = [];
+ var isStart = true;
+ var tmp;
+ var previous = 0;
+ while (++index < length) {
+ tmp = codePoints[index];
+ if (isStart) {
+ result.push(tmp);
+ previous = tmp;
+ isStart = false;
+ } else {
+ if (tmp == previous + 1) {
+ if (index != max) {
+ previous = tmp;
+ continue;
+ } else {
+ isStart = true;
+ result.push(tmp + 1);
+ }
+ } else {
+ // End the previous range and start a new one.
+ result.push(previous + 1, tmp);
+ previous = tmp;
+ }
+ }
+ }
+ if (!isStart) {
+ result.push(tmp + 1);
+ }
+ return result;
+ };
+
+ var dataRemove = function(data, codePoint) {
+ // Iterate over the data per `(start, end)` pair.
+ var index = 0;
+ var start;
+ var end;
+ var length = data.length;
+ while (index < length) {
+ start = data[index];
+ end = data[index + 1];
+ if (codePoint >= start && codePoint < end) {
+ // Modify this pair.
+ if (codePoint == start) {
+ if (end == start + 1) {
+ // Just remove `start` and `end`.
+ data.splice(index, 2);
+ return data;
+ } else {
+ // Just replace `start` with a new value.
+ data[index] = codePoint + 1;
+ return data;
+ }
+ } else if (codePoint == end - 1) {
+ // Just replace `end` with a new value.
+ data[index + 1] = codePoint;
+ return data;
+ } else {
+ // Replace `[start, end]` with `[startA, endA, startB, endB]`.
+ data.splice(index, 2, start, codePoint, codePoint + 1, end);
+ return data;
+ }
+ }
+ index += 2;
+ }
+ return data;
+ };
+
+ var dataRemoveRange = function(data, rangeStart, rangeEnd) {
+ if (rangeEnd < rangeStart) {
+ throw Error(ERRORS.rangeOrder);
+ }
+ // Iterate over the data per `(start, end)` pair.
+ var index = 0;
+ var start;
+ var end;
+ while (index < data.length) {
+ start = data[index];
+ end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
+
+ // Exit as soon as no more matching pairs can be found.
+ if (start > rangeEnd) {
+ return data;
+ }
+
+ // Check if this range pair is equal to, or forms a subset of, the range
+ // to be removed.
+ // E.g. we have `[0, 11, 40, 51]` and want to remove 0-10 → `[40, 51]`.
+ // E.g. we have `[40, 51]` and want to remove 0-100 → `[]`.
+ if (rangeStart <= start && rangeEnd >= end) {
+ // Remove this pair.
+ data.splice(index, 2);
+ continue;
+ }
+
+ // Check if both `rangeStart` and `rangeEnd` are within the bounds of
+ // this pair.
+ // E.g. we have `[0, 11]` and want to remove 4-6 → `[0, 4, 7, 11]`.
+ if (rangeStart >= start && rangeEnd < end) {
+ if (rangeStart == start) {
+ // Replace `[start, end]` with `[startB, endB]`.
+ data[index] = rangeEnd + 1;
+ data[index + 1] = end + 1;
+ return data;
+ }
+ // Replace `[start, end]` with `[startA, endA, startB, endB]`.
+ data.splice(index, 2, start, rangeStart, rangeEnd + 1, end + 1);
+ return data;
+ }
+
+ // Check if only `rangeStart` is within the bounds of this pair.
+ // E.g. we have `[0, 11]` and want to remove 4-20 → `[0, 4]`.
+ if (rangeStart >= start && rangeStart <= end) {
+ // Replace `end` with `rangeStart`.
+ data[index + 1] = rangeStart;
+ // Note: we cannot `return` just yet, in case any following pairs still
+ // contain matching code points.
+ // E.g. we have `[0, 11, 14, 31]` and want to remove 4-20
+ // → `[0, 4, 21, 31]`.
+ }
+
+ // Check if only `rangeEnd` is within the bounds of this pair.
+ // E.g. we have `[14, 31]` and want to remove 4-20 → `[21, 31]`.
+ else if (rangeEnd >= start && rangeEnd <= end) {
+ // Just replace `start`.
+ data[index] = rangeEnd + 1;
+ return data;
+ }
+
+ index += 2;
+ }
+ return data;
+ };
+
+ var dataAdd = function(data, codePoint) {
+ // Iterate over the data per `(start, end)` pair.
+ var index = 0;
+ var start;
+ var end;
+ var lastIndex = null;
+ var length = data.length;
+ if (codePoint < 0x0 || codePoint > 0x10FFFF) {
+ throw RangeError(ERRORS.codePointRange);
+ }
+ while (index < length) {
+ start = data[index];
+ end = data[index + 1];
+
+ // Check if the code point is already in the set.
+ if (codePoint >= start && codePoint < end) {
+ return data;
+ }
+
+ if (codePoint == start - 1) {
+ // Just replace `start` with a new value.
+ data[index] = codePoint;
+ return data;
+ }
+
+ // At this point, if `start` is `greater` than `codePoint`, insert a new
+ // `[start, end]` pair before the current pair, or after the current pair
+ // if there is a known `lastIndex`.
+ if (start > codePoint) {
+ data.splice(
+ lastIndex != null ? lastIndex + 2 : 0,
+ 0,
+ codePoint,
+ codePoint + 1
+ );
+ return data;
+ }
+
+ if (codePoint == end) {
+ // Check if adding this code point causes two separate ranges to become
+ // a single range, e.g. `dataAdd([0, 4, 5, 10], 4)` → `[0, 10]`.
+ if (codePoint + 1 == data[index + 2]) {
+ data.splice(index, 4, start, data[index + 3]);
+ return data;
+ }
+ // Else, just replace `end` with a new value.
+ data[index + 1] = codePoint + 1;
+ return data;
+ }
+ lastIndex = index;
+ index += 2;
+ }
+ // The loop has finished; add the new pair to the end of the data set.
+ data.push(codePoint, codePoint + 1);
+ return data;
+ };
+
+ var dataAddData = function(dataA, dataB) {
+ // Iterate over the data per `(start, end)` pair.
+ var index = 0;
+ var start;
+ var end;
+ var data = dataA.slice();
+ var length = dataB.length;
+ while (index < length) {
+ start = dataB[index];
+ end = dataB[index + 1] - 1;
+ if (start == end) {
+ data = dataAdd(data, start);
+ } else {
+ data = dataAddRange(data, start, end);
+ }
+ index += 2;
+ }
+ return data;
+ };
+
+ var dataRemoveData = function(dataA, dataB) {
+ // Iterate over the data per `(start, end)` pair.
+ var index = 0;
+ var start;
+ var end;
+ var data = dataA.slice();
+ var length = dataB.length;
+ while (index < length) {
+ start = dataB[index];
+ end = dataB[index + 1] - 1;
+ if (start == end) {
+ data = dataRemove(data, start);
+ } else {
+ data = dataRemoveRange(data, start, end);
+ }
+ index += 2;
+ }
+ return data;
+ };
+
+ var dataAddRange = function(data, rangeStart, rangeEnd) {
+ if (rangeEnd < rangeStart) {
+ throw Error(ERRORS.rangeOrder);
+ }
+ if (
+ rangeStart < 0x0 || rangeStart > 0x10FFFF ||
+ rangeEnd < 0x0 || rangeEnd > 0x10FFFF
+ ) {
+ throw RangeError(ERRORS.codePointRange);
+ }
+ // Iterate over the data per `(start, end)` pair.
+ var index = 0;
+ var start;
+ var end;
+ var added = false;
+ var length = data.length;
+ while (index < length) {
+ start = data[index];
+ end = data[index + 1];
+
+ if (added) {
+ // The range has already been added to the set; at this point, we just
+ // need to get rid of the following ranges in case they overlap.
+
+ // Check if this range can be combined with the previous range.
+ if (start == rangeEnd + 1) {
+ data.splice(index - 1, 2);
+ return data;
+ }
+
+ // Exit as soon as no more possibly overlapping pairs can be found.
+ if (start > rangeEnd) {
+ return data;
+ }
+
+ // E.g. `[0, 11, 12, 16]` and we’ve added 5-15, so we now have
+ // `[0, 16, 12, 16]`. Remove the `12,16` part, as it lies within the
+ // `0,16` range that was previously added.
+ if (start >= rangeStart && start <= rangeEnd) {
+ // `start` lies within the range that was previously added.
+
+ if (end > rangeStart && end - 1 <= rangeEnd) {
+ // `end` lies within the range that was previously added as well,
+ // so remove this pair.
+ data.splice(index, 2);
+ index -= 2;
+ // Note: we cannot `return` just yet, as there may still be other
+ // overlapping pairs.
+ } else {
+ // `start` lies within the range that was previously added, but
+ // `end` doesn’t. E.g. `[0, 11, 12, 31]` and we’ve added 5-15, so
+ // now we have `[0, 16, 12, 31]`. This must be written as `[0, 31]`.
+ // Remove the previously added `end` and the current `start`.
+ data.splice(index - 1, 2);
+ index -= 2;
+ }
+
+ // Note: we cannot return yet.
+ }
+
+ }
+
+ else if (start == rangeEnd + 1) {
+ data[index] = rangeStart;
+ return data;
+ }
+
+ // Check if a new pair must be inserted *before* the current one.
+ else if (start > rangeEnd) {
+ data.splice(index, 0, rangeStart, rangeEnd + 1);
+ return data;
+ }
+
+ else if (rangeStart >= start && rangeStart < end && rangeEnd + 1 <= end) {
+ // The new range lies entirely within an existing range pair. No action
+ // needed.
+ return data;
+ }
+
+ else if (
+ // E.g. `[0, 11]` and you add 5-15 → `[0, 16]`.
+ (rangeStart >= start && rangeStart < end) ||
+ // E.g. `[0, 3]` and you add 3-6 → `[0, 7]`.
+ end == rangeStart
+ ) {
+ // Replace `end` with the new value.
+ data[index + 1] = rangeEnd + 1;
+ // Make sure the next range pair doesn’t overlap, e.g. `[0, 11, 12, 14]`
+ // and you add 5-15 → `[0, 16]`, i.e. remove the `12,14` part.
+ added = true;
+ // Note: we cannot `return` just yet.
+ }
+
+ else if (rangeStart <= start && rangeEnd + 1 >= end) {
+ // The new range is a superset of the old range.
+ data[index] = rangeStart;
+ data[index + 1] = rangeEnd + 1;
+ added = true;
+ }
+
+ index += 2;
+ }
+ // The loop has finished without doing anything; add the new pair to the end
+ // of the data set.
+ if (!added) {
+ data.push(rangeStart, rangeEnd + 1);
+ }
+ return data;
+ };
+
+ var dataContains = function(data, codePoint) {
+ var index = 0;
+ var length = data.length;
+ // Exit early if `codePoint` is not within `data`’s overall range.
+ var start = data[index];
+ var end = data[length - 1];
+ if (length >= 2) {
+ if (codePoint < start || codePoint > end) {
+ return false;
+ }
+ }
+ // Iterate over the data per `(start, end)` pair.
+ while (index < length) {
+ start = data[index];
+ end = data[index + 1];
+ if (codePoint >= start && codePoint < end) {
+ return true;
+ }
+ index += 2;
+ }
+ return false;
+ };
+
+ var dataIntersection = function(data, codePoints) {
+ var index = 0;
+ var length = codePoints.length;
+ var codePoint;
+ var result = [];
+ while (index < length) {
+ codePoint = codePoints[index];
+ if (dataContains(data, codePoint)) {
+ result.push(codePoint);
+ }
+ ++index;
+ }
+ return dataFromCodePoints(result);
+ };
+
+ var dataIsEmpty = function(data) {
+ return !data.length;
+ };
+
+ var dataIsSingleton = function(data) {
+ // Check if the set only represents a single code point.
+ return data.length == 2 && data[0] + 1 == data[1];
+ };
+
+ var dataToArray = function(data) {
+ // Iterate over the data per `(start, end)` pair.
+ var index = 0;
+ var start;
+ var end;
+ var result = [];
+ var length = data.length;
+ while (index < length) {
+ start = data[index];
+ end = data[index + 1];
+ while (start < end) {
+ result.push(start);
+ ++start;
+ }
+ index += 2;
+ }
+ return result;
+ };
+
+ /*--------------------------------------------------------------------------*/
+
+ // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
+ var floor = Math.floor;
+ var highSurrogate = function(codePoint) {
+ return parseInt(
+ floor((codePoint - 0x10000) / 0x400) + HIGH_SURROGATE_MIN,
+ 10
+ );
+ };
+
+ var lowSurrogate = function(codePoint) {
+ return parseInt(
+ (codePoint - 0x10000) % 0x400 + LOW_SURROGATE_MIN,
+ 10
+ );
+ };
+
+ var stringFromCharCode = String.fromCharCode;
+ var codePointToString = function(codePoint) {
+ var string;
+ // https://mathiasbynens.be/notes/javascript-escapes#single
+ // Note: the `\b` escape sequence for U+0008 BACKSPACE in strings has a
+ // different meaning in regular expressions (word boundary), so it cannot
+ // be used here.
+ if (codePoint == 0x09) {
+ string = '\\t';
+ }
+ // Note: IE < 9 treats `'\v'` as `'v'`, so avoid using it.
+ // else if (codePoint == 0x0B) {
+ // string = '\\v';
+ // }
+ else if (codePoint == 0x0A) {
+ string = '\\n';
+ }
+ else if (codePoint == 0x0C) {
+ string = '\\f';
+ }
+ else if (codePoint == 0x0D) {
+ string = '\\r';
+ }
+ else if (codePoint == 0x5C) {
+ string = '\\\\';
+ }
+ else if (
+ codePoint == 0x24 ||
+ (codePoint >= 0x28 && codePoint <= 0x2B) ||
+ codePoint == 0x2D || codePoint == 0x2E || codePoint == 0x3F ||
+ (codePoint >= 0x5B && codePoint <= 0x5E) ||
+ (codePoint >= 0x7B && codePoint <= 0x7D)
+ ) {
+ // The code point maps to an unsafe printable ASCII character;
+ // backslash-escape it. Here’s the list of those symbols:
+ //
+ // $()*+-.?[\]^{|}
+ //
+ // See #7 for more info.
+ string = '\\' + stringFromCharCode(codePoint);
+ }
+ else if (codePoint >= 0x20 && codePoint <= 0x7E) {
+ // The code point maps to one of these printable ASCII symbols
+ // (including the space character):
+ //
+ // !"#%&',/0123456789:;<=>@ABCDEFGHIJKLMNO
+ // PQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~
+ //
+ // These can safely be used directly.
+ string = stringFromCharCode(codePoint);
+ }
+ else if (codePoint <= 0xFF) {
+ // https://mathiasbynens.be/notes/javascript-escapes#hexadecimal
+ string = '\\x' + pad(hex(codePoint), 2);
+ }
+ else { // `codePoint <= 0xFFFF` holds true.
+ // https://mathiasbynens.be/notes/javascript-escapes#unicode
+ string = '\\u' + pad(hex(codePoint), 4);
+ }
+
+ // There’s no need to account for astral symbols / surrogate pairs here,
+ // since `codePointToString` is private and only used for BMP code points.
+ // But if that’s what you need, just add an `else` block with this code:
+ //
+ // string = '\\u' + pad(hex(highSurrogate(codePoint)), 4)
+ // + '\\u' + pad(hex(lowSurrogate(codePoint)), 4);
+
+ return string;
+ };
+
+ var symbolToCodePoint = function(symbol) {
+ var length = symbol.length;
+ var first = symbol.charCodeAt(0);
+ var second;
+ if (
+ first >= HIGH_SURROGATE_MIN && first <= HIGH_SURROGATE_MAX &&
+ length > 1 // There is a next code unit.
+ ) {
+ // `first` is a high surrogate, and there is a next character. Assume
+ // it’s a low surrogate (else it’s invalid usage of Regenerate anyway).
+ second = symbol.charCodeAt(1);
+ // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
+ return (first - HIGH_SURROGATE_MIN) * 0x400 +
+ second - LOW_SURROGATE_MIN + 0x10000;
+ }
+ return first;
+ };
+
+ var createBMPCharacterClasses = function(data) {
+ // Iterate over the data per `(start, end)` pair.
+ var result = '';
+ var index = 0;
+ var start;
+ var end;
+ var length = data.length;
+ if (dataIsSingleton(data)) {
+ return codePointToString(data[0]);
+ }
+ while (index < length) {
+ start = data[index];
+ end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
+ if (start == end) {
+ result += codePointToString(start);
+ } else if (start + 1 == end) {
+ result += codePointToString(start) + codePointToString(end);
+ } else {
+ result += codePointToString(start) + '-' + codePointToString(end);
+ }
+ index += 2;
+ }
+ return '[' + result + ']';
+ };
+
+ var splitAtBMP = function(data) {
+ // Iterate over the data per `(start, end)` pair.
+ var loneHighSurrogates = [];
+ var loneLowSurrogates = [];
+ var bmp = [];
+ var astral = [];
+ var index = 0;
+ var start;
+ var end;
+ var length = data.length;
+ while (index < length) {
+ start = data[index];
+ end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
+
+ if (start < HIGH_SURROGATE_MIN) {
+
+ // The range starts and ends before the high surrogate range.
+ // E.g. (0, 0x10).
+ if (end < HIGH_SURROGATE_MIN) {
+ bmp.push(start, end + 1);
+ }
+
+ // The range starts before the high surrogate range and ends within it.
+ // E.g. (0, 0xD855).
+ if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
+ bmp.push(start, HIGH_SURROGATE_MIN);
+ loneHighSurrogates.push(HIGH_SURROGATE_MIN, end + 1);
+ }
+
+ // The range starts before the high surrogate range and ends in the low
+ // surrogate range. E.g. (0, 0xDCFF).
+ if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
+ bmp.push(start, HIGH_SURROGATE_MIN);
+ loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
+ loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
+ }
+
+ // The range starts before the high surrogate range and ends after the
+ // low surrogate range. E.g. (0, 0x10FFFF).
+ if (end > LOW_SURROGATE_MAX) {
+ bmp.push(start, HIGH_SURROGATE_MIN);
+ loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
+ loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
+ if (end <= 0xFFFF) {
+ bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
+ } else {
+ bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
+ astral.push(0xFFFF + 1, end + 1);
+ }
+ }
+
+ } else if (start >= HIGH_SURROGATE_MIN && start <= HIGH_SURROGATE_MAX) {
+
+ // The range starts and ends in the high surrogate range.
+ // E.g. (0xD855, 0xD866).
+ if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
+ loneHighSurrogates.push(start, end + 1);
+ }
+
+ // The range starts in the high surrogate range and ends in the low
+ // surrogate range. E.g. (0xD855, 0xDCFF).
+ if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
+ loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
+ loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
+ }
+
+ // The range starts in the high surrogate range and ends after the low
+ // surrogate range. E.g. (0xD855, 0x10FFFF).
+ if (end > LOW_SURROGATE_MAX) {
+ loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
+ loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
+ if (end <= 0xFFFF) {
+ bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
+ } else {
+ bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
+ astral.push(0xFFFF + 1, end + 1);
+ }
+ }
+
+ } else if (start >= LOW_SURROGATE_MIN && start <= LOW_SURROGATE_MAX) {
+
+ // The range starts and ends in the low surrogate range.
+ // E.g. (0xDCFF, 0xDDFF).
+ if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
+ loneLowSurrogates.push(start, end + 1);
+ }
+
+ // The range starts in the low surrogate range and ends after the low
+ // surrogate range. E.g. (0xDCFF, 0x10FFFF).
+ if (end > LOW_SURROGATE_MAX) {
+ loneLowSurrogates.push(start, LOW_SURROGATE_MAX + 1);
+ if (end <= 0xFFFF) {
+ bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
+ } else {
+ bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
+ astral.push(0xFFFF + 1, end + 1);
+ }
+ }
+
+ } else if (start > LOW_SURROGATE_MAX && start <= 0xFFFF) {
+
+ // The range starts and ends after the low surrogate range.
+ // E.g. (0xFFAA, 0x10FFFF).
+ if (end <= 0xFFFF) {
+ bmp.push(start, end + 1);
+ } else {
+ bmp.push(start, 0xFFFF + 1);
+ astral.push(0xFFFF + 1, end + 1);
+ }
+
+ } else {
+
+ // The range starts and ends in the astral range.
+ astral.push(start, end + 1);
+
+ }
+
+ index += 2;
+ }
+ return {
+ 'loneHighSurrogates': loneHighSurrogates,
+ 'loneLowSurrogates': loneLowSurrogates,
+ 'bmp': bmp,
+ 'astral': astral
+ };
+ };
+
+ var optimizeSurrogateMappings = function(surrogateMappings) {
+ var result = [];
+ var tmpLow = [];
+ var addLow = false;
+ var mapping;
+ var nextMapping;
+ var highSurrogates;
+ var lowSurrogates;
+ var nextHighSurrogates;
+ var nextLowSurrogates;
+ var index = -1;
+ var length = surrogateMappings.length;
+ while (++index < length) {
+ mapping = surrogateMappings[index];
+ nextMapping = surrogateMappings[index + 1];
+ if (!nextMapping) {
+ result.push(mapping);
+ continue;
+ }
+ highSurrogates = mapping[0];
+ lowSurrogates = mapping[1];
+ nextHighSurrogates = nextMapping[0];
+ nextLowSurrogates = nextMapping[1];
+
+ // Check for identical high surrogate ranges.
+ tmpLow = lowSurrogates;
+ while (
+ nextHighSurrogates &&
+ highSurrogates[0] == nextHighSurrogates[0] &&
+ highSurrogates[1] == nextHighSurrogates[1]
+ ) {
+ // Merge with the next item.
+ if (dataIsSingleton(nextLowSurrogates)) {
+ tmpLow = dataAdd(tmpLow, nextLowSurrogates[0]);
+ } else {
+ tmpLow = dataAddRange(
+ tmpLow,
+ nextLowSurrogates[0],
+ nextLowSurrogates[1] - 1
+ );
+ }
+ ++index;
+ mapping = surrogateMappings[index];
+ highSurrogates = mapping[0];
+ lowSurrogates = mapping[1];
+ nextMapping = surrogateMappings[index + 1];
+ nextHighSurrogates = nextMapping && nextMapping[0];
+ nextLowSurrogates = nextMapping && nextMapping[1];
+ addLow = true;
+ }
+ result.push([
+ highSurrogates,
+ addLow ? tmpLow : lowSurrogates
+ ]);
+ addLow = false;
+ }
+ return optimizeByLowSurrogates(result);
+ };
+
+ var optimizeByLowSurrogates = function(surrogateMappings) {
+ if (surrogateMappings.length == 1) {
+ return surrogateMappings;
+ }
+ var index = -1;
+ var innerIndex = -1;
+ while (++index < surrogateMappings.length) {
+ var mapping = surrogateMappings[index];
+ var lowSurrogates = mapping[1];
+ var lowSurrogateStart = lowSurrogates[0];
+ var lowSurrogateEnd = lowSurrogates[1];
+ innerIndex = index; // Note: the loop starts at the next index.
+ while (++innerIndex < surrogateMappings.length) {
+ var otherMapping = surrogateMappings[innerIndex];
+ var otherLowSurrogates = otherMapping[1];
+ var otherLowSurrogateStart = otherLowSurrogates[0];
+ var otherLowSurrogateEnd = otherLowSurrogates[1];
+ if (
+ lowSurrogateStart == otherLowSurrogateStart &&
+ lowSurrogateEnd == otherLowSurrogateEnd
+ ) {
+ // Add the code points in the other item to this one.
+ if (dataIsSingleton(otherMapping[0])) {
+ mapping[0] = dataAdd(mapping[0], otherMapping[0][0]);
+ } else {
+ mapping[0] = dataAddRange(
+ mapping[0],
+ otherMapping[0][0],
+ otherMapping[0][1] - 1
+ );
+ }
+ // Remove the other, now redundant, item.
+ surrogateMappings.splice(innerIndex, 1);
+ --innerIndex;
+ }
+ }
+ }
+ return surrogateMappings;
+ };
+
+ var surrogateSet = function(data) {
+ // Exit early if `data` is an empty set.
+ if (!data.length) {
+ return [];
+ }
+
+ // Iterate over the data per `(start, end)` pair.
+ var index = 0;
+ var start;
+ var end;
+ var startHigh;
+ var startLow;
+ var prevStartHigh = 0;
+ var prevEndHigh = 0;
+ var tmpLow = [];
+ var endHigh;
+ var endLow;
+ var surrogateMappings = [];
+ var length = data.length;
+ var dataHigh = [];
+ while (index < length) {
+ start = data[index];
+ end = data[index + 1] - 1;
+
+ startHigh = highSurrogate(start);
+ startLow = lowSurrogate(start);
+ endHigh = highSurrogate(end);
+ endLow = lowSurrogate(end);
+
+ var startsWithLowestLowSurrogate = startLow == LOW_SURROGATE_MIN;
+ var endsWithHighestLowSurrogate = endLow == LOW_SURROGATE_MAX;
+ var complete = false;
+
+ // Append the previous high-surrogate-to-low-surrogate mappings.
+ // Step 1: `(startHigh, startLow)` to `(startHigh, LOW_SURROGATE_MAX)`.
+ if (
+ startHigh == endHigh ||
+ startsWithLowestLowSurrogate && endsWithHighestLowSurrogate
+ ) {
+ surrogateMappings.push([
+ [startHigh, endHigh + 1],
+ [startLow, endLow + 1]
+ ]);
+ complete = true;
+ } else {
+ surrogateMappings.push([
+ [startHigh, startHigh + 1],
+ [startLow, LOW_SURROGATE_MAX + 1]
+ ]);
+ }
+
+ // Step 2: `(startHigh + 1, LOW_SURROGATE_MIN)` to
+ // `(endHigh - 1, LOW_SURROGATE_MAX)`.
+ if (!complete && startHigh + 1 < endHigh) {
+ if (endsWithHighestLowSurrogate) {
+ // Combine step 2 and step 3.
+ surrogateMappings.push([
+ [startHigh + 1, endHigh + 1],
+ [LOW_SURROGATE_MIN, endLow + 1]
+ ]);
+ complete = true;
+ } else {
+ surrogateMappings.push([
+ [startHigh + 1, endHigh],
+ [LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1]
+ ]);
+ }
+ }
+
+ // Step 3. `(endHigh, LOW_SURROGATE_MIN)` to `(endHigh, endLow)`.
+ if (!complete) {
+ surrogateMappings.push([
+ [endHigh, endHigh + 1],
+ [LOW_SURROGATE_MIN, endLow + 1]
+ ]);
+ }
+
+ prevStartHigh = startHigh;
+ prevEndHigh = endHigh;
+
+ index += 2;
+ }
+
+ // The format of `surrogateMappings` is as follows:
+ //
+ // [ surrogateMapping1, surrogateMapping2 ]
+ //
+ // i.e.:
+ //
+ // [
+ // [ highSurrogates1, lowSurrogates1 ],
+ // [ highSurrogates2, lowSurrogates2 ]
+ // ]
+ return optimizeSurrogateMappings(surrogateMappings);
+ };
+
+ var createSurrogateCharacterClasses = function(surrogateMappings) {
+ var result = [];
+ forEach(surrogateMappings, function(surrogateMapping) {
+ var highSurrogates = surrogateMapping[0];
+ var lowSurrogates = surrogateMapping[1];
+ result.push(
+ createBMPCharacterClasses(highSurrogates) +
+ createBMPCharacterClasses(lowSurrogates)
+ );
+ });
+ return result.join('|');
+ };
+
+ var createCharacterClassesFromData = function(data, bmpOnly) {
+ var result = [];
+
+ var parts = splitAtBMP(data);
+ var loneHighSurrogates = parts.loneHighSurrogates;
+ var loneLowSurrogates = parts.loneLowSurrogates;
+ var bmp = parts.bmp;
+ var astral = parts.astral;
+ var hasAstral = !dataIsEmpty(parts.astral);
+ var hasLoneHighSurrogates = !dataIsEmpty(loneHighSurrogates);
+ var hasLoneLowSurrogates = !dataIsEmpty(loneLowSurrogates);
+
+ var surrogateMappings = surrogateSet(astral);
+
+ if (bmpOnly) {
+ bmp = dataAddData(bmp, loneHighSurrogates);
+ hasLoneHighSurrogates = false;
+ bmp = dataAddData(bmp, loneLowSurrogates);
+ hasLoneLowSurrogates = false;
+ }
+
+ if (!dataIsEmpty(bmp)) {
+ // The data set contains BMP code points that are not high surrogates
+ // needed for astral code points in the set.
+ result.push(createBMPCharacterClasses(bmp));
+ }
+ if (surrogateMappings.length) {
+ // The data set contains astral code points; append character classes
+ // based on their surrogate pairs.
+ result.push(createSurrogateCharacterClasses(surrogateMappings));
+ }
+ // https://gist.github.com/mathiasbynens/bbe7f870208abcfec860
+ if (hasLoneHighSurrogates) {
+ result.push(
+ createBMPCharacterClasses(loneHighSurrogates) +
+ // Make sure the high surrogates aren’t part of a surrogate pair.
+ '(?![\\uDC00-\\uDFFF])'
+ );
+ }
+ if (hasLoneLowSurrogates) {
+ result.push(
+ // Make sure the low surrogates aren’t part of a surrogate pair.
+ '(?:[^\\uD800-\\uDBFF]|^)' +
+ createBMPCharacterClasses(loneLowSurrogates)
+ );
+ }
+ return result.join('|');
+ };
+
+ /*--------------------------------------------------------------------------*/
+
+ // `regenerate` can be used as a constructor (and new methods can be added to
+ // its prototype) but also as a regular function, the latter of which is the
+ // documented and most common usage. For that reason, it’s not capitalized.
+ var regenerate = function(value) {
+ if (arguments.length > 1) {
+ value = slice.call(arguments);
+ }
+ if (this instanceof regenerate) {
+ this.data = [];
+ return value ? this.add(value) : this;
+ }
+ return (new regenerate).add(value);
+ };
+
+ regenerate.version = '1.2.1';
+
+ var proto = regenerate.prototype;
+ extend(proto, {
+ 'add': function(value) {
+ var $this = this;
+ if (value == null) {
+ return $this;
+ }
+ if (value instanceof regenerate) {
+ // Allow passing other Regenerate instances.
+ $this.data = dataAddData($this.data, value.data);
+ return $this;
+ }
+ if (arguments.length > 1) {
+ value = slice.call(arguments);
+ }
+ if (isArray(value)) {
+ forEach(value, function(item) {
+ $this.add(item);
+ });
+ return $this;
+ }
+ $this.data = dataAdd(
+ $this.data,
+ isNumber(value) ? value : symbolToCodePoint(value)
+ );
+ return $this;
+ },
+ 'remove': function(value) {
+ var $this = this;
+ if (value == null) {
+ return $this;
+ }
+ if (value instanceof regenerate) {
+ // Allow passing other Regenerate instances.
+ $this.data = dataRemoveData($this.data, value.data);
+ return $this;
+ }
+ if (arguments.length > 1) {
+ value = slice.call(arguments);
+ }
+ if (isArray(value)) {
+ forEach(value, function(item) {
+ $this.remove(item);
+ });
+ return $this;
+ }
+ $this.data = dataRemove(
+ $this.data,
+ isNumber(value) ? value : symbolToCodePoint(value)
+ );
+ return $this;
+ },
+ 'addRange': function(start, end) {
+ var $this = this;
+ $this.data = dataAddRange($this.data,
+ isNumber(start) ? start : symbolToCodePoint(start),
+ isNumber(end) ? end : symbolToCodePoint(end)
+ );
+ return $this;
+ },
+ 'removeRange': function(start, end) {
+ var $this = this;
+ var startCodePoint = isNumber(start) ? start : symbolToCodePoint(start);
+ var endCodePoint = isNumber(end) ? end : symbolToCodePoint(end);
+ $this.data = dataRemoveRange(
+ $this.data,
+ startCodePoint,
+ endCodePoint
+ );
+ return $this;
+ },
+ 'intersection': function(argument) {
+ var $this = this;
+ // Allow passing other Regenerate instances.
+ // TODO: Optimize this by writing and using `dataIntersectionData()`.
+ var array = argument instanceof regenerate ?
+ dataToArray(argument.data) :
+ argument;
+ $this.data = dataIntersection($this.data, array);
+ return $this;
+ },
+ 'contains': function(codePoint) {
+ return dataContains(
+ this.data,
+ isNumber(codePoint) ? codePoint : symbolToCodePoint(codePoint)
+ );
+ },
+ 'clone': function() {
+ var set = new regenerate;
+ set.data = this.data.slice(0);
+ return set;
+ },
+ 'toString': function(options) {
+ var result = createCharacterClassesFromData(
+ this.data,
+ options ? options.bmpOnly : false
+ );
+ // Use `\0` instead of `\x00` where possible.
+ return result.replace(regexNull, '\\0$1');
+ },
+ 'toRegExp': function(flags) {
+ return RegExp(this.toString(), flags || '');
+ },
+ 'valueOf': function() { // Note: `valueOf` is aliased as `toArray`.
+ return dataToArray(this.data);
+ }
+ });
+
+ proto.toArray = proto.valueOf;
+
+ // Some AMD build optimizers, like r.js, check for specific condition patterns
+ // like the following:
+ if (
+ typeof define == 'function' &&
+ typeof define.amd == 'object' &&
+ define.amd
+ ) {
+ define(function() {
+ return regenerate;
+ });
+ } else if (freeExports && !freeExports.nodeType) {
+ if (freeModule) { // in Node.js, io.js, or RingoJS v0.8.0+
+ freeModule.exports = regenerate;
+ } else { // in Narwhal or RingoJS v0.7.0-
+ freeExports.regenerate = regenerate;
+ }
+ } else { // in Rhino or a web browser
+ root.regenerate = regenerate;
+ }
+
+}(this));
diff --git a/tests/index.html b/tests/index.html
new file mode 100644
index 0000000..897c695
--- /dev/null
+++ b/tests/index.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Regenerate test suite</title>
+ <link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css">
+ </head>
+ <body>
+ <div id="qunit"></div>
+ <script src="../node_modules/qunitjs/qunit/qunit.js"></script>
+ <script src="../regenerate.js"></script>
+ <script>
+ // populate `QUnit.urlParams`
+ QUnit.urlParams.norequire = /[?&]norequire=true(?:&|$)/.test(location.search);
+
+ // load tests.js if not using require.js
+ document.write(QUnit.urlParams.norequire
+ ? '<script src="tests.js"><\/script>'
+ : '<script src="../node_modules/requirejs/require.js"><\/script>'
+ );
+ </script>
+ <script>
+ window.require && require({
+ 'baseUrl': '../node_modules/requirejs/',
+ 'urlArgs': 't=' + (+new Date),
+ 'paths': {
+ 'regenerate': '../../regenerate'
+ }
+ },
+ ['regenerate'], function(regenerate) {
+ require(['tests.js']);
+ });
+ </script>
+ </body>
+</html>
diff --git a/tests/tests.js b/tests/tests.js
new file mode 100644
index 0000000..1b27d8c
--- /dev/null
+++ b/tests/tests.js
@@ -0,0 +1,806 @@
+(function(root) {
+ 'use strict';
+
+ var noop = Function.prototype;
+
+ var load = (typeof require == 'function' && !(root.define && define.amd)) ?
+ require :
+ (!root.document && root.java && root.load) || noop;
+
+ var QUnit = (function() {
+ return root.QUnit || (
+ root.addEventListener || (root.addEventListener = noop),
+ root.setTimeout || (root.setTimeout = noop),
+ root.QUnit = load('../node_modules/qunitjs/qunit/qunit.js') || root.QUnit,
+ addEventListener === noop && delete root.addEventListener,
+ root.QUnit
+ );
+ }());
+
+ var qe = load('../node_modules/qunit-extras/qunit-extras.js');
+ if (qe) {
+ qe.runInContext(root);
+ }
+
+ // Extend `Object.prototype` to see if Regenerate can handle it.
+ // 0xD834 is the high surrogate code point for U+1D306 (among others).
+ Object.prototype[0xD834] = true;
+
+ /** The `regenerate` object to test */
+ var regenerate = root.regenerate || (root.regenerate = (
+ regenerate = load('../regenerate.js') || root.regenerate,
+ regenerate = regenerate.regenerate || regenerate
+ ));
+
+ /*--------------------------------------------------------------------------*/
+
+ // Inclusive `range`, e.g. `range(1, 3)` → `[1, 2, 3]`.
+ var range = function(start, stop) {
+ for (var result = []; start <= stop; result.push(start++));
+ return result;
+ };
+
+ // `throws` is a reserved word in ES3; alias it to avoid errors
+ var raises = QUnit.assert['throws'];
+
+ // explicitly call `QUnit.module()` instead of `module()`
+ // in case we are in a CLI environment
+ QUnit.module('regenerate');
+
+ test('general functionality', function() {
+ var set = regenerate(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
+ .add(0x1D306)
+ .add([15, 16, 20])
+ .remove(20)
+ .remove([9, 15])
+ .intersection([3, 7, 10, 16, 0x1D306, 9001])
+ .remove(7, 16);
+ var setB = regenerate(0x1337, 0x1338, 0x31337);
+ var setC = regenerate(0x42);
+ deepEqual(
+ set.clone().add(setB).add(setC).toArray(),
+ [3, 10, 0x42, 0x1337, 0x1338, 0x1D306, 0x31337],
+ 'add(set) + clone'
+ );
+ deepEqual(
+ regenerate(3, 10, 0x42, 0x1337, 0x1338, 0x1D306, 0x31337).remove(setB).remove(setC).toArray(),
+ [3, 10, 0x1D306],
+ 'remove(set)'
+ );
+ deepEqual(
+ regenerate(3, 10, 0x42, 0x1337, 0x1D306, 0x31337).remove(setB).toArray(),
+ [3, 10, 0x42, 0x1D306],
+ 'remove(set)'
+ );
+ deepEqual(
+ regenerate(3, 10, 0x42, 0x1337, 0x1D306, 0x31337).intersection(setB).toArray(),
+ [0x1337, 0x31337],
+ 'intersection(set)'
+ );
+ deepEqual(
+ regenerate(0, 1, 2, 3, 4, 5).intersection([3, 4, 5]).toArray(),
+ [3, 4, 5],
+ 'intersection with consecutive code points'
+ );
+ deepEqual(
+ regenerate(0, 1, 2, 3, 4, 5).remove(5).toArray(),
+ [0, 1, 2, 3, 4],
+ 'remove that triggers an upper limit change in the data structure'
+ );
+ deepEqual(
+ regenerate(0, 1, 2, 3, 4, 5).remove().toArray(),
+ [0, 1, 2, 3, 4, 5],
+ 'remove with no arguments'
+ );
+ deepEqual(
+ set.toArray(),
+ [3, 10, 0x1D306],
+ 'Set: add, remove, remove, intersection'
+ );
+ equal(
+ set.toString(),
+ '[\\x03\\n]|\\uD834\\uDF06',
+ 'toString'
+ );
+ equal(
+ set.contains(0x1D306),
+ true,
+ 'contains: true'
+ );
+ equal(
+ set.contains(0x1D307),
+ false,
+ 'contains: false'
+ );
+ equal(
+ set.contains('\uD834\uDF07'),
+ false,
+ 'contains: false'
+ );
+ equal(
+ regenerate(0x62).add(0x1D307).contains('\uD834\uDF06'),
+ false,
+ 'contains: false'
+ );
+ equal(
+ regenerate().add([0x1D307, 0x1D3A0, 0x1D3FF]).remove([0x1D3A0, 0x1D3FF]).contains(0x1D3A0),
+ false,
+ 'contains: false'
+ );
+ deepEqual(
+ regenerate().addRange(0x0, 0x10FFFF).removeRange(0xA, 0x10FFFF).toArray(),
+ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
+ 'Set: start with a huge set, then remove a huge subset of code points'
+ );
+ deepEqual(
+ regenerate(0x1D3A0, 0x1D307).add(0x1D3FF, 'A').remove(0x1D3A0, 0x1D3FF).toArray(),
+ [0x41, 0x1D307],
+ 'set(a, b, ...)'
+ );
+ deepEqual(
+ regenerate(0x1D3A0, 0x1D307, 'A').add(0x1D3FF).remove(0x1D3A0, 0x1D3FF).toArray(),
+ [0x41, 0x1D307],
+ 'set(a, b, ...)'
+ );
+ deepEqual(
+ regenerate(0x0).addRange(0x5, 0x8).toArray(),
+ [0x0, 0x5, 0x6, 0x7, 0x8],
+ 'addRange with numbers'
+ );
+ deepEqual(
+ regenerate(0x0).addRange('a', 'c').toArray(),
+ [0x0, 0x61, 0x62, 0x63],
+ 'addRange with strings'
+ );
+ deepEqual(
+ regenerate(0x0).addRange(0x61, 'c').toArray(),
+ [0x0, 0x61, 0x62, 0x63],
+ 'addRange with a number and a string'
+ );
+ deepEqual(
+ regenerate(new Number(0x0)).addRange(new String('a'), new Number(0x63)).toArray(),
+ [0x0, 0x61, 0x62, 0x63],
+ 'addRange with a Number object and a String object'
+ );
+ equal(
+ regenerate('b').addRange('a', 'c').toString(),
+ '[a-c]',
+ 'addRange where the new range wraps an old range in the set'
+ );
+ equal(
+ regenerate('b', 'x').addRange('a', 'c').toString(),
+ '[a-cx]',
+ 'addRange where the new range wraps an old range in the set'
+ );
+ deepEqual(
+ regenerate(0x1D306).addRange(0x0, 0xFF).removeRange('\0', '\xFE').toArray(),
+ [0xFF, 0x1D306],
+ 'removeRange'
+ );
+ deepEqual(
+ regenerate(0x1D306).addRange(0x0, 0xFF).removeRange(0x0, 0x10FFFF).toArray(),
+ [],
+ 'removeRange removing all code points'
+ );
+ deepEqual(
+ regenerate().addRange(0x300, 0x374).removeRange(0x370, 0x374).toString(),
+ '[\\u0300-\\u036F]',
+ 'removeRange'
+ );
+ deepEqual(
+ regenerate().addRange(0x300, 0x374).removeRange(0x300, 0x304).toString(),
+ '[\\u0305-\\u0374]',
+ 'removeRange'
+ );
+ deepEqual(
+ regenerate().addRange(0x0000, 0x0300).removeRange(0x0100, 0x0200).toRegExp(),
+ /[\0-\xFF\u0201-\u0300]/,
+ 'toRegExp'
+ );
+ deepEqual(
+ regenerate().addRange(0x0000, 0x0300).removeRange(0x0100, 0x0200).toRegExp('g'),
+ /[\0-\xFF\u0201-\u0300]/g,
+ 'toRegExp with flags'
+ );
+ raises(
+ function() {
+ regenerate(0x10, 0x1F).removeRange(0x1F, 0x1A).toArray();
+ },
+ Error,
+ 'removeRange: incorrect usage'
+ );
+ raises(
+ function() {
+ regenerate(0x10, 0x1F).addRange(0x1F, 0x1A).toArray();
+ },
+ Error,
+ 'addRange: incorrect usage'
+ );
+ deepEqual(
+ regenerate(0).removeRange(0x1000, 0x2000).toArray(),
+ [0],
+ 'removeRange with no effect'
+ );
+ deepEqual(
+ regenerate(0x1000).removeRange(0, 1).toArray(),
+ [0x1000],
+ 'removeRange with no effect'
+ );
+ deepEqual(
+ regenerate(42).addRange(0, 10).removeRange(0, 10).toArray(),
+ [42],
+ 'removeRange removing an exact range'
+ );
+ deepEqual(
+ regenerate(42).addRange(0, 10).removeRange(4, 20).toArray(),
+ [0, 1, 2, 3, 42],
+ 'removeRange removing a partial range'
+ );
+ deepEqual(
+ regenerate(42).addRange(14, 23).removeRange(4, 20).toArray(),
+ [21, 22, 23, 42],
+ 'removeRange removing a partial range'
+ );
+ deepEqual(
+ regenerate().add(42, 50, 51, 53, 57, 59, 60).removeRange(50, 60).toArray(),
+ [42],
+ 'removeRange removing several ranges from the data'
+ );
+ deepEqual(
+ regenerate().addRange(0, 5).addRange(3, 7).toArray(),
+ [0, 1, 2, 3, 4, 5, 6, 7],
+ 'addRange with overlapping ranges'
+ );
+ deepEqual(
+ regenerate().addRange(0, 5).addRange(6, 7).toArray(),
+ [0, 1, 2, 3, 4, 5, 6, 7],
+ 'addRange extending the end of a range'
+ );
+ deepEqual(
+ regenerate().addRange(0, 2).addRange(4, 6).addRange(3, 4).toArray(),
+ [0, 1, 2, 3, 4, 5, 6],
+ 'addRange gluing two ranges together'
+ );
+ deepEqual(
+ regenerate().addRange(0, 2).addRange(5, 7).addRange(3, 4).toArray(),
+ [0, 1, 2, 3, 4, 5, 6, 7],
+ 'addRange gluing two ranges together'
+ );
+ deepEqual(
+ regenerate().addRange(0, 2).addRange(4, 6).addRange(1, 5).toArray(),
+ [0, 1, 2, 3, 4, 5, 6],
+ 'addRange with overlapping ranges'
+ );
+ deepEqual(
+ regenerate().addRange(0, 5).addRange(10, 12).addRange(1, 3).toArray(),
+ [0, 1, 2, 3, 4, 5, 10, 11, 12],
+ 'addRange with a sub-range'
+ );
+ deepEqual(
+ regenerate().addRange(0, 2).addRange(7, 9).addRange(3, 4).toArray(),
+ [0, 1, 2, 3, 4, 7, 8, 9],
+ 'addRange extending the end of a range'
+ );
+ deepEqual(
+ regenerate().addRange(0, 3).addRange(5, 10).add(4).toArray(),
+ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
+ 'addRange gluing two ranges together'
+ );
+ deepEqual(
+ regenerate().addRange(0, 5).addRange(10, 15).addRange(3, 17).toArray(),
+ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17],
+ 'addRange causing several sub-ranges to be deleted'
+ );
+ equal(
+ regenerate(0x08, 0x0A, 0x0C, 0x0D, 0x22, 0x27, 0x5C).toString(),
+ '[\\x08\\n\\f\\r"\'\\\\]',
+ 'toString escapes special characters using single escapes'
+ );
+ equal(
+ regenerate(0x09, 'a').toString(),
+ '[\\ta]',
+ 'toString escapes special characters using single escapes'
+ );
+ equal(
+ set.clone().add('a', '.', '-', ']').toString(),
+ '[\\x03\\n\\-\\.\\]a]|\\uD834\\uDF06',
+ 'toString uses hexadecimal and Unicode escapes when appropriate'
+ );
+ deepEqual(
+ regenerate().addRange(3, 6).add(2).toArray(),
+ [2, 3, 4, 5, 6],
+ 'add extending the start of a range'
+ );
+ deepEqual(
+ regenerate(set),
+ set,
+ 'Don’t wrap existing sets'
+ );
+ deepEqual(
+ regenerate(0x61).add(0x61, 0x61, 0x62).add(0x61).toArray(),
+ [0x61, 0x62],
+ 'Remove duplicates'
+ );
+ deepEqual(
+ regenerate().toArray(),
+ [],
+ 'Empty set returns empty array'
+ );
+ deepEqual(
+ regenerate().remove(0x1D306).toArray(),
+ [],
+ 'Empty set returns empty array'
+ );
+ deepEqual(
+ regenerate([]).toArray(),
+ [],
+ 'Empty array as input returns empty array'
+ );
+ equal(
+ regenerate(0x10, 0x11, 0x12, 0x13, 0x40, 0x41, 0x42, 0x43, 0x44, 0x2603, 0xFD3F, 0xFFFF).toString(),
+ '[\\x10-\\x13 at -D\\u2603\\uFD3F\\uFFFF]',
+ 'Random BMP code points'
+ );
+ equal(
+ regenerate(0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x5A, 0x61).toString(),
+ '[A-HZa]',
+ 'BMP code points within the a-zA-Z range'
+ );
+ equal(
+ regenerate(0x61, 0x5A, 0x48, 0x47, 0x46, 0x45, 0x44, 0x43, 0x42, 0x41).toString(),
+ '[A-HZa]',
+ 'BMP code points within the a-zA-Z range, unordered'
+ );
+ equal(
+ regenerate(0x20, 0x21, 0x23).toString(),
+ '[ !#]',
+ 'Random BMP code points'
+ );
+ equal(
+ regenerate(0xD800, 0xD801, 0xD802, 0xD803, 0xDBFF).toString(),
+ '[\\uD800-\\uD803\\uDBFF](?![\\uDC00-\\uDFFF])',
+ 'Unmatched high surrogates'
+ );
+ equal(
+ regenerate(0xD800, 0xD801, 0xD802, 0xD803, 0xDBFF).toString({ 'bmpOnly': false }),
+ '[\\uD800-\\uD803\\uDBFF](?![\\uDC00-\\uDFFF])',
+ 'Unmatched high surrogates with `bmpOnly: false`'
+ );
+ equal(
+ regenerate(0xD800, 0xD801, 0xD802, 0xD803, 0xDBFF).toString({ 'bmpOnly': true }),
+ '[\\uD800-\\uD803\\uDBFF]',
+ 'Unmatched high surrogates with `bmpOnly: true`'
+ );
+ equal(
+ regenerate(0xDC00, 0xDC01, 0xDC02, 0xDC03, 0xDC04, 0xDC05, 0xDFFB, 0xDFFD, 0xDFFE, 0xDFFF).toString(),
+ '(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDC05\\uDFFB\\uDFFD-\\uDFFF]',
+ 'Unmatched low surrogates'
+ );
+ equal(
+ regenerate(0xDC00, 0xDC01, 0xDC02, 0xDC03, 0xDC04, 0xDC05, 0xDFFB, 0xDFFD, 0xDFFE, 0xDFFF).toString({ 'bmpOnly': false }),
+ '(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDC05\\uDFFB\\uDFFD-\\uDFFF]',
+ 'Unmatched low surrogates with `bmpOnly: false`'
+ );
+ equal(
+ regenerate(0xDC00, 0xDC01, 0xDC02, 0xDC03, 0xDC04, 0xDC05, 0xDFFB, 0xDFFD, 0xDFFE, 0xDFFF).toString({ 'bmpOnly': true }),
+ '[\\uDC00-\\uDC05\\uDFFB\\uDFFD-\\uDFFF]',
+ 'Unmatched low surrogates with `bmpOnly: true`'
+ );
+ equal(
+ regenerate(0x0, 0x1, 0x2, 0x3, 0x1D306, 0x1D307, 0x1D308, 0x1D30A).toString(),
+ '[\\0-\\x03]|\\uD834[\\uDF06-\\uDF08\\uDF0A]',
+ 'Mixed BMP and astral code points'
+ );
+ equal(
+ regenerate(0).toString(),
+ '\\0',
+ '\\0'
+ );
+ equal(
+ regenerate(0, 0x31, 0x32).toString(),
+ '[\\x0012]',
+ '\\0 may not be followed by a digit'
+ );
+ equal(
+ regenerate(0, 0x38, 0x39).toString(),
+ '[\\x0089]',
+ '\\0 may not be followed by a digit, even if it’s not an octal digit'
+ );
+ equal(
+ regenerate().addRange(0x0, 0xFFFF).toString(),
+ '[\\0-\\uD7FF\\uE000-\\uFFFF]|[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF]',
+ 'All BMP code points'
+ );
+ equal(
+ regenerate().addRange(0x010000, 0x10FFFF).toString(),
+ '[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]',
+ 'All astral code points'
+ );
+ equal(
+ regenerate().addRange(0x0, 0x10FFFF).toString(),
+ '[\\0-\\uD7FF\\uE000-\\uFFFF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF]',
+ 'All Unicode code points'
+ );
+ raises(
+ function() {
+ regenerate(0x110000).toString();
+ },
+ RangeError,
+ 'Invalid code point > 0x10FFFF'
+ );
+ raises(
+ function() {
+ regenerate(-1).toString();
+ },
+ RangeError,
+ 'Invalid code point < 0x0000'
+ );
+ equal(
+ regenerate().addRange(0x10, 0x13).toString(),
+ '[\\x10-\\x13]',
+ 'BMP code points'
+ );
+ equal(
+ regenerate().addRange(0x41, 0x61).toString(),
+ '[A-a]',
+ 'BMP code points within the a-zA-Z range'
+ );
+ raises(
+ function() {
+ regenerate().addRange(0xFFFF, 0x0).toString();
+ },
+ Error,
+ 'addRange: start value greater than end value'
+ );
+ raises(
+ function() {
+ regenerate().removeRange(0xFFFF, 0x0).toString();
+ },
+ Error,
+ 'removeRange: start value greater than end value'
+ );
+ raises(
+ function() {
+ regenerate().addRange(0x110000, 0x110005).toString();
+ },
+ RangeError,
+ 'addRange: invalid code point > 0x10FFFF'
+ );
+ raises(
+ function() {
+ regenerate().addRange(-10, -5).toString();
+ },
+ RangeError,
+ 'addRange: Invalid code point < 0x0000'
+ );
+ equal(
+ regenerate().addRange(0, 0xDCFF).toString(),
+ '[\\0-\\uD7FF]|[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDCFF]',
+ 'Range starts before the high surrogate range and ends in the low surrogate range'
+ );
+ equal(
+ regenerate(0xD800 - 1).addRange(0xD800, 0xDBFF).toString(),
+ '\\uD7FF|[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])',
+ 'Range starts right before high surrogate range'
+ );
+ equal(
+ regenerate(0xD800 - 1).addRange(0xD800, 0xDBFF).toString({ 'bmpOnly': true }),
+ '[\\uD7FF-\\uDBFF]',
+ 'Range starts right before high surrogate range with `bmpOnly: true`'
+ );
+ equal(
+ regenerate().addRange(0xD855, 0xFFFF).toString(),
+ '[\\uE000-\\uFFFF]|[\\uD855-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF]',
+ 'Range starts in the high surrogate range and ends after the low surrogate range'
+ );
+ equal(
+ regenerate().addRange(0xDCFF, 0xDDFF).toString(),
+ '(?:[^\\uD800-\\uDBFF]|^)[\\uDCFF-\\uDDFF]',
+ 'Range starts and ends in the low surrogate range'
+ );
+ equal(
+ regenerate().addRange(0xDCFF, 0xFFFF).toString(),
+ '[\\uE000-\\uFFFF]|(?:[^\\uD800-\\uDBFF]|^)[\\uDCFF-\\uDFFF]',
+ 'Range starts in the low surrogate range and ends after the low surrogate range'
+ );
+ equal(
+ regenerate().addRange(0xDCFF, 0x10FFFF).toString(),
+ '[\\uE000-\\uFFFF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|(?:[^\\uD800-\\uDBFF]|^)[\\uDCFF-\\uDFFF]',
+ 'Range starts in the low surrogate range and ends after the low surrogate range'
+ );
+ equal(
+ regenerate(0xDC00 - 1).addRange(0xDC00, 0xDFFF).toString(),
+ '\\uDBFF(?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF]',
+ 'Range starts right before low surrogate range'
+ );
+ equal(
+ regenerate(0xDC00 - 1).addRange(0xDC00, 0xDFFF).toString({ 'bmpOnly': true }),
+ '[\\uDBFF-\\uDFFF]',
+ 'Range starts right before low surrogate range with `bmpOnly: true`'
+ );
+ equal(
+ regenerate(0x200C).addRange(0xF900, 0xFDCF).addRange(0xFDF0, 0xFFFD).addRange(0x010000, 0x0EFFFF).toString(),
+ '[\\u200C\\uF900-\\uFDCF\\uFDF0-\\uFFFD]|[\\uD800-\\uDB7F][\\uDC00-\\uDFFF]',
+ 'Various code points'
+ );
+ equal(
+ regenerate('\u200C').addRange('\uF900', '\uFDCF').addRange('\uFDF0', '\uFFFD').addRange('\uD800\uDC00', '\uDB7F\uDFFF').toString(),
+ '[\\u200C\\uF900-\\uFDCF\\uFDF0-\\uFFFD]|[\\uD800-\\uDB7F][\\uDC00-\\uDFFF]',
+ 'Various code points, using symbols as input'
+ );
+ raises(
+ function() {
+ regenerate({ 'lol': 'wat' }).toString();
+ },
+ TypeError,
+ 'Argument is not a symbol, code point, or array consisting of those'
+ );
+ raises(
+ function() {
+ regenerate().add({ 'lol': 'wat' }).toString();
+ },
+ TypeError,
+ 'Argument is not a symbol, code point, or array consisting of those'
+ );
+ raises(
+ function() {
+ regenerate().remove({ 'lol': 'wat' }).toString();
+ },
+ TypeError,
+ 'Argument is not a symbol, code point, or array consisting of those'
+ );
+ equal(
+ regenerate('\x10', '\x11', '\x12', '\x13', '@', 'A', 'B', 'C', 'D', '\u2603', '\uFD3F', '\uFFFF').toString(),
+ '[\\x10-\\x13 at -D\\u2603\\uFD3F\\uFFFF]',
+ 'BMP code points, using symbols as input'
+ );
+ equal(
+ regenerate('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'Z', 'a').toString(),
+ '[A-HZa]',
+ 'BMP code points within the a-zA-Z range, using symbols as input'
+ );
+ equal(
+ regenerate('a', 'Z', 'H', 'G', 'F', 'E', 'D', 'C', 'B', 'A').toString(),
+ '[A-HZa]',
+ 'BMP code points within the a-zA-Z range, unordered, using symbols as input'
+ );
+ equal(
+ regenerate('\uD800', '\uD801', '\uD802', '\uD803', '\uDBFF').toString(),
+ '[\\uD800-\\uD803\\uDBFF](?![\\uDC00-\\uDFFF])',
+ 'Unmatched high surrogates, using symbols as input'
+ );
+ equal(
+ regenerate('\uDC00', '\uDC01', '\uDC02', '\uDC03', '\uDC04', '\uDC05', '\uDFFB', '\uDFFD', '\uDFFE', '\uDFFF').toString(),
+ '(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDC05\\uDFFB\\uDFFD-\\uDFFF]',
+ 'Unmatched low surrogates, using symbols as input'
+ );
+ equal(
+ regenerate('\0', '\x01', '\x02', '\x03', '\uD834\uDF06', '\uD834\uDF07', '\uD834\uDF08', '\uD834\uDF0A').toString(),
+ '[\\0-\\x03]|\\uD834[\\uDF06-\\uDF08\\uDF0A]',
+ 'Mixed BMP and astral code points'
+ );
+ deepEqual(
+ regenerate().addRange(0xF9FF, 0xFA07).toArray(),
+ [0xF9FF, 0xFA00, 0xFA01, 0xFA02, 0xFA03, 0xFA04, 0xFA05, 0xFA06, 0xFA07],
+ 'Simple range'
+ );
+ deepEqual(
+ regenerate().addRange(0, 3).add(0x200C).addRange(0xF900, 0xF902).valueOf(),
+ [0, 1, 2, 3, 0x200C, 0xF900, 0xF901, 0xF902],
+ 'Some code point ranges'
+ );
+ raises(
+ function() {
+ regenerate(5).addRange(5).toString();
+ },
+ Error,
+ 'addRange with a single argument'
+ );
+ raises(
+ function() {
+ regenerate(5).removeRange(5).toString();
+ },
+ Error,
+ 'removeRange with a single argument'
+ );
+ equal(
+ regenerate().addRange('a', 'f').contains('a'),
+ true,
+ 'contains'
+ );
+ equal(
+ regenerate().addRange('a', 'f').contains('b'),
+ true,
+ 'contains'
+ );
+ equal(
+ regenerate().addRange('a', 'f').contains('f'),
+ true,
+ 'contains'
+ );
+ equal(
+ regenerate().addRange('a', 'f').contains('g'),
+ false,
+ 'contains'
+ );
+ equal(
+ regenerate().addRange('a', 'f').contains('A'),
+ false,
+ 'contains'
+ );
+ equal(
+ regenerate().addRange('a', 'f').contains('B'),
+ false,
+ 'contains'
+ );
+ equal(
+ regenerate().addRange('a', 'f').contains('F'),
+ false,
+ 'contains'
+ );
+ equal(
+ regenerate().addRange('a', 'f').contains('G'),
+ false,
+ 'contains'
+ );
+ deepEqual(
+ regenerate(1, 2, 3, 4, 5, 6, 7).remove([1, 3, 7]).toArray(),
+ [2, 4, 5, 6],
+ 'remove'
+ );
+ deepEqual(
+ regenerate(1, 2, 3, 4).remove([0]).toArray(),
+ [1, 2, 3, 4],
+ 'remove'
+ );
+ deepEqual(
+ regenerate(0x1D306, 0x41, 0x1D307, 0x42, 0x44, 0x1F4A9).remove('A', 0x1D307, ['B', 'D', '\uD83D\uDCA9']).toArray(),
+ [0x1D306],
+ 'remove with various value types'
+ );
+ deepEqual(
+ regenerate().add('A', 0x1D307, 119559, ['B', 0x1D306, 'D', '\uD83D\uDCA9']).toArray(),
+ [0x41, 0x42, 0x44, 0x1D306, 0x1D307, 0x1F4A9],
+ 'add with various value types'
+ );
+ equal(
+ regenerate().addRange(0x103FE, 0x10401).toString(),
+ '\\uD800[\\uDFFE\\uDFFF]|\\uD801[\\uDC00\\uDC01]',
+ 'surrogate bounds (from \\uD800\\uDFFE to \\uD801\\uDC01)'
+ );
+ equal(
+ regenerate().addRange(0x10001, 0x10401).toString(),
+ '\\uD800[\\uDC01-\\uDFFF]|\\uD801[\\uDC00\\uDC01]',
+ 'common low surrogates (from \\uD800\\uDC01 to \\uD801\\uDC01)'
+ );
+ equal(
+ regenerate().add(0x10001, 0x10401).toString(),
+ '[\\uD800\\uD801]\\uDC01',
+ 'common low surrogates (\\uD800\\uDC01 and \\uD801\\uDC01)'
+ );
+ equal(
+ regenerate().add(0x10001, 0x10401, 0x10801).toString(),
+ '[\\uD800-\\uD802]\\uDC01',
+ 'common low surrogates (\\uD800\\uDC01 and \\uD801\\uDC01 and \\uD802\\uDC01)'
+ );
+ equal(
+ regenerate().addRange(0xD800, 0xDBFF).addRange(0xDC00, 0xDFFF).add(0xFFFF).toString(),
+ '\\uFFFF|[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF]',
+ 'BMP-only symbols incl. lone surrogates but with higher code points too'
+ );
+ equal(
+ regenerate().addRange(0xD800, 0xDBFF).addRange(0xDC00, 0xDFFF).add(0xFFFF, 0x1D306).toString(),
+ '\\uFFFF|\\uD834\\uDF06|[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF]',
+ 'BMP-only symbols incl. lone surrogates but with higher code points and an astral code point too'
+ );
+ equal(
+ regenerate().addRange(0xD0300, 0xFABFF).toString(),
+ '\\uDB00[\\uDF00-\\uDFFF]|[\\uDB01-\\uDBAA][\\uDC00-\\uDFFF]',
+ 'two distinct sets of common low surrogates (from \\uDB00\\uDF00 to \\uDBAA\\uDFFF)'
+ );
+ equal(
+ regenerate().addRange(0xD0000, 0xD03FF).toString(),
+ '\\uDB00[\\uDC00-\\uDFFF]',
+ 'common high surrogates (from \\uDB00\\uDC00 to \\uDB00\\uDFFF)'
+ );
+ equal(
+ regenerate().add(0xD0000, 0xD03FF).toString(),
+ '\\uDB00[\\uDC00\\uDFFF]',
+ 'common high surrogates (\\uDB00\\uDC00 and \\uDB00\\uDFFF)'
+ );
+ equal(
+ regenerate().add(0xD0200, 0xFA9DD).toString(),
+ '\\uDB00\\uDE00|\\uDBAA\\uDDDD',
+ 'two distinct sets of common low surrogates (\\uDB00\\uDE00 and \\uDBAA\\uDDDD)'
+ );
+ equal(
+ regenerate().addRange(0xD0200, 0xFA9DD).toString(),
+ '\\uDB00[\\uDE00-\\uDFFF]|[\\uDB01-\\uDBA9][\\uDC00-\\uDFFF]|\\uDBAA[\\uDC00-\\uDDDD]',
+ 'two distinct sets of common low surrogates (from \\uDB00\\uDE00 to \\uDBAA\\uDDDD)'
+ );
+ equal(
+ regenerate().addRange(0x20, 0xD900).toString(),
+ '[ -\\uD7FF]|[\\uD800-\\uD900](?![\\uDC00-\\uDFFF])',
+ 'adding a range that starts in ASCII and ends in the high surrogate range'
+ );
+ equal(
+ regenerate().addRange(0x20, 0x1D306).toString(),
+ '[ -\\uD7FF\\uE000-\\uFFFF]|[\\uD800-\\uD833][\\uDC00-\\uDFFF]|\\uD834[\\uDC00-\\uDF06]|[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF]',
+ 'adding a range that starts in ASCII and ends in the astral range'
+ );
+ equal(
+ regenerate().addRange(0xD900, 0x1D306).toString(),
+ '[\\uE000-\\uFFFF]|[\\uD800-\\uD833][\\uDC00-\\uDFFF]|\\uD834[\\uDC00-\\uDF06]|[\\uD900-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF]',
+ 'adding a range that starts in the high surrogate range and ends in the astral range'
+ );
+ equal(
+ regenerate().addRange(0xF0000, 0xFFFFD).addRange(0x100000, 0x10FFFD).toString(),
+ '[\\uDB80-\\uDBBE\\uDBC0-\\uDBFE][\\uDC00-\\uDFFF]|[\\uDBBF\\uDBFF][\\uDC00-\\uDFFD]',
+ 'all astral code points except the last one'
+ );
+ equal(
+ regenerate().addRange(0xFFEF, 0xFFF8).addRange(0xFFFE, 0x102FF).toString(),
+ '[\\uFFEF-\\uFFF8\\uFFFE\\uFFFF]|\\uD800[\\uDC00-\\uDEFF]',
+ 'mixed BMP + astral code points'
+ );
+ equal(
+ '\uD834\uDF06'.match(
+ RegExp('(' + regenerate().addRange(0xD800, 0xDBFF).addRange(0xDC00, 0xDFFF).toString() + ')')
+ ),
+ null,
+ 'https://github.com/mathiasbynens/regenerate/issues/28'
+ );
+ equal(
+ regenerate.prototype.valueOf,
+ regenerate.prototype.toArray,
+ '`valueOf` and `toArray` should be the same'
+ );
+ equal(
+ new regenerate('a', 'b', 0x1D306).toString(),
+ regenerate('a', 'b', 0x1D306).toString(),
+ '`regenerate` can be called as a constructor'
+ );
+ deepEqual(
+ [regenerate.prototype.add.length, regenerate.prototype.remove.length, regenerate.prototype.addRange.length, regenerate.prototype.removeRange.length, regenerate.prototype.remove.length, regenerate.prototype.intersection.length, regenerate.prototype.contains.length, regenerate.prototype.clone.length, regenerate.prototype.toString.length, regenerate.prototype.toRegExp.length, regenerate.prototype.valueOf.length, regenerate.prototype.toArray.length],
+ [1, 1, 2, 2, 1, 1, 1, 0, 1, 1, 0, 0],
+ 'Regenerate methods are available on `regenerate.prototype`'
+ );
+ deepEqual(
+ regenerate(42).data,
+ [42, 43],
+ 'each Regenerate instance `set` stores its data in `set.data` for plugins to use'
+ );
+ });
+ test('acid tests', function() {
+ // Based on the output for https://gist.github.com/mathiasbynens/6334847
+ equal(
+ regenerate(0x24, 0x5F, 0xAA, 0xB5, 0xBA, 0x2EC, 0x2EE, 0x386, 0x38C, 0x559, 0x6D5, 0x6FF, 0x710, 0x7B1, 0x7FA, 0x81A, 0x824, 0x828, 0x8A0, 0x93D, 0x950, 0x9B2, 0x9BD, 0x9CE, 0xA5E, 0xABD, 0xAD0, 0xB3D, 0xB71, 0xB83, 0xB9C, 0xBD0, 0xC3D, 0xCBD, 0xCDE, 0xD3D, 0xD4E, 0xDBD, 0xE84, 0xE8A, 0xE8D, 0xEA5, 0xEA7, 0xEBD, 0xEC6, 0xF00, 0x103F, 0x1061, 0x108E, 0x10C7, 0x10CD, 0x1258, 0x12C0, 0x17D7, 0x17DC, 0x18AA, 0x1AA7, 0x1F59, 0x1F5B, 0x1F5D, 0x1FBE, 0x2071, 0x207F, 0x2102, 0x2107, 0x2115, 0 [...]
+ '[\\$A-Z_a-z\\xAA\\xB5\\xBA\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0370-\\u0374\\u0376\\u0377\\u037A-\\u037D\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u048A-\\u0527\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0620-\\u064A\\u066E\\u066F\\u0671-\\u06D3\\u06D5\\u06E5\\u06E6\\u06EE\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4\\u07F5\\u07FA\\ [...]
+ 'ES 5.1 / Unicode 6.3.0 `IdentifierStart`'
+ );
+ equal(
+ regenerate(0x24, 0x5F, 0xAA, 0xB5, 0xBA, 0x2EC, 0x2EE, 0x386, 0x38C, 0x559, 0x5BF, 0x5C7, 0x6FF, 0x7FA, 0x8A0, 0x9B2, 0x9D7, 0xA3C, 0xA51, 0xA5E, 0xAD0, 0xB71, 0xB9C, 0xBD0, 0xBD7, 0xCDE, 0xD57, 0xDBD, 0xDCA, 0xDD6, 0xE84, 0xE8A, 0xE8D, 0xEA5, 0xEA7, 0xEC6, 0xF00, 0xF35, 0xF37, 0xF39, 0xFC6, 0x10C7, 0x10CD, 0x1258, 0x12C0, 0x17D7, 0x1AA7, 0x1F59, 0x1F5B, 0x1F5D, 0x1FBE, 0x2054, 0x2071, 0x207F, 0x20E1, 0x2102, 0x2107, 0x2115, 0x2124, 0x2126, 0x2128, 0x214E, 0x2D27, 0x2D2D, 0x2D6F, 0x2E [...]
+ '[\\$0-9A-Z_a-z\\xAA\\xB5\\xBA\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0300-\\u0374\\u0376\\u0377\\u037A-\\u037D\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u0483-\\u0487\\u048A-\\u0527\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u0591-\\u05BD\\u05BF\\u05C1\\u05C2\\u05C4\\u05C5\\u05C7\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0610-\\u061A\\u0620-\\u0669\\u066E-\\u06D3\\u06D5-\\u06DC\\u06DF-\\u06E8\\u06EA-\\u06FC\\u06FF\\u0710-\\u [...]
+ 'ES 5.1 / Unicode 6.3.0 `IdentifierPart`'
+ );
+ equal(
+ regenerate(0x24, 0x5F, 0xAA, 0xB5, 0xBA, 0x2EC, 0x2EE, 0x386, 0x38C, 0x559, 0x6D5, 0x6FF, 0x710, 0x7B1, 0x7FA, 0x81A, 0x824, 0x828, 0x8A0, 0x93D, 0x950, 0x9B2, 0x9BD, 0x9CE, 0xA5E, 0xABD, 0xAD0, 0xB3D, 0xB71, 0xB83, 0xB9C, 0xBD0, 0xC3D, 0xCBD, 0xCDE, 0xD3D, 0xD4E, 0xDBD, 0xE84, 0xE8A, 0xE8D, 0xEA5, 0xEA7, 0xEBD, 0xEC6, 0xF00, 0x103F, 0x1061, 0x108E, 0x10C7, 0x10CD, 0x1258, 0x12C0, 0x17D7, 0x17DC, 0x18AA, 0x1AA7, 0x1F59, 0x1F5B, 0x1F5D, 0x1FBE, 0x2071, 0x207F, 0x2102, 0x2107, 0x2115, 0 [...]
+ '[\\$A-Z_a-z\\xAA\\xB5\\xBA\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0370-\\u0374\\u0376\\u0377\\u037A-\\u037D\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u048A-\\u0527\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0620-\\u064A\\u066E\\u066F\\u0671-\\u06D3\\u06D5\\u06E5\\u06E6\\u06EE\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4\\u07F5\\u07FA\\ [...]
+ 'ES 6 / Unicode 6.3.0 `IdentifierStart`'
+ );
+ equal(
+ regenerate(0x24, 0x5F, 0xAA, 0xB5, 0xBA, 0x2EC, 0x2EE, 0x386, 0x38C, 0x559, 0x5BF, 0x5C7, 0x6FF, 0x7FA, 0x8A0, 0x9B2, 0x9D7, 0xA3C, 0xA51, 0xA5E, 0xAD0, 0xB71, 0xB9C, 0xBD0, 0xBD7, 0xCDE, 0xD57, 0xDBD, 0xDCA, 0xDD6, 0xE84, 0xE8A, 0xE8D, 0xEA5, 0xEA7, 0xEC6, 0xF00, 0xF35, 0xF37, 0xF39, 0xFC6, 0x10C7, 0x10CD, 0x1258, 0x12C0, 0x17D7, 0x1AA7, 0x1F59, 0x1F5B, 0x1F5D, 0x1FBE, 0x2054, 0x2071, 0x207F, 0x20E1, 0x2102, 0x2107, 0x2115, 0x2124, 0x2126, 0x2128, 0x214E, 0x2D27, 0x2D2D, 0x2D6F, 0xA8 [...]
+ '[\\$0-9A-Z_a-z\\xAA\\xB5\\xBA\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0300-\\u0374\\u0376\\u0377\\u037A-\\u037D\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u0483-\\u0487\\u048A-\\u0527\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u0591-\\u05BD\\u05BF\\u05C1\\u05C2\\u05C4\\u05C5\\u05C7\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0610-\\u061A\\u0620-\\u0669\\u066E-\\u06D3\\u06D5-\\u06DC\\u06DF-\\u06E8\\u06EA-\\u06FC\\u06FF\\u0710-\\u [...]
+ 'ES 6 / Unicode 6.3.0 `IdentifierPart`'
+ );
+ });
+
+ /*--------------------------------------------------------------------------*/
+
+ // configure QUnit and call `QUnit.start()` for
+ // Narwhal, Node.js, PhantomJS, Rhino, and RingoJS
+ if (!root.document || root.phantom) {
+ QUnit.config.noglobals = true;
+ QUnit.start();
+ }
+}(typeof global == 'object' && global || this));
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-regenerate.git
More information about the Pkg-javascript-commits
mailing list