Package Exports
- regenerate
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (regenerate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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.
Feel free to fork if you see possible improvements!
Installation and usage
In a browser:
<script src="regenerate.js"></script>
Via npm:
npm install regenerate
In Narwhal, Node.js, and RingoJS:
var regenerate = require('regenerate');
In Rhino:
load('regenerate.js');
Using an AMD loader like RequireJS:
require(
{
'paths': {
'regenerate': 'path/to/regenerate'
}
},
['regenerate'],
function(regenerate) {
console.log(regenerate);
}
);
Usage example:
// Code points used in this example:
// U+1F604 SMILING FACE WITH OPEN MOUTH AND SMILING EYES
// U+1F605 SMILING FACE WITH OPEN MOUTH AND COLD SWEAT
// U+1F606 SMILING FACE WITH OPEN MOUTH AND TIGHTLY-CLOSED EYES
// U+1F607 SMILING FACE WITH HALO
// Create a regular expression that matches any of the given code points:
regenerate.fromCodePoints([0x1F604, 0x1F605, 0x1F606, 0x1F607]);
// β '\\uD83D[\\uDE04-\\uDE07]'
// Create a regular expression that matches any code point in the given range:
regenerate.fromCodePointRange(0x1F604, 0x1F607);
// β '\\uD83D[\\uDE04-\\uDE07]'
// Create a regular expression that matches any Unicode code point:
regenerate.fromCodePointRange(0x000000, 0x10FFFF);
// β '[\\0-\\uD7FF\\uDC00-\\uFFFF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|[\\uD800-\\uDBFF]'
regenerate.fromSymbols(['π', 'π', 'π', 'π', 'π']);
// β '\\uD835[\\uDC00-\\uDC04]'
regenerate.fromSymbolRange('π', 'π');
// β '\\uD835[\\uDC0F-\\uDC1F]'
Note that all of Regenerateβs methods return strings that can be used as (part of) a regular expression literal. To convert an output string into a regular expression dynamically, just wrap it in RegExp(β¦)
:
// Create a regular expression that matches any code point in the given range:
var result = regenerate.fromCodePointRange(0x1F604, 0x1F607);
// β '\\uD83D[\\uDE04-\\uDE07]'
var regex = RegExp(result);
regex.test('\uD83D\uDE03'); // 0x1F603
// β false
regex.test('\uD83D\uDE04'); // 0x1F604
// β true
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
Mathias Bynens |