JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 23273175
  • Score
    100M100P100Q211247F

Generate JavaScript-compatible regular expressions based on a given set of symbols or code points.

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

Dependency status

Regenerate is a regular expression generator for JavaScript. Easily generate JavaScript-compatible regular expressions based on a given set of 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 BMP code point:
regenerate.fromCodePointRange(0x0000, 0xFFFF);
// → '[\\0-\\uD7FF\\uDC00-\\uFFFF]|[\\uD800-\\uDBFF]'

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
Mathias Bynens

License

Regenerate is dual licensed under the MIT and GPL licenses.