regenerate
Advanced tools
Comparing version 1.1.0 to 1.2.0
{ | ||
"name": "regenerate", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Generate JavaScript-compatible regular expressions based on a given set of Unicode symbols or code points.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://mths.be/regenerate", |
@@ -221,3 +221,3 @@ # 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.prototype.toString()` | ||
### `regenerate.prototype.toString(options)` | ||
@@ -231,2 +231,18 @@ Returns a string representing (part of) a regular expression that matches all the symbols mapped to the code points within the set. | ||
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 = '')` | ||
@@ -233,0 +249,0 @@ |
@@ -1,2 +0,2 @@ | ||
/*! https://mths.be/regenerate v1.1.0 by @mathias | MIT license */ | ||
/*! https://mths.be/regenerate v1.2.0 by @mathias | MIT license */ | ||
;(function(root) { | ||
@@ -961,3 +961,3 @@ | ||
var createCharacterClassesFromData = function(data) { | ||
var createCharacterClassesFromData = function(data, bmpOnly) { | ||
var result = []; | ||
@@ -991,3 +991,3 @@ | ||
// Make sure the high surrogates aren’t part of a surrogate pair. | ||
'(?![\\uDC00-\\uDFFF])' | ||
(bmpOnly ? '' : '(?![\\uDC00-\\uDFFF])') | ||
); | ||
@@ -998,3 +998,3 @@ } | ||
// Make sure the low surrogates aren’t part of a surrogate pair. | ||
'(?:[^\\uD800-\\uDBFF]|^)' + | ||
(bmpOnly ? '' : '(?:[^\\uD800-\\uDBFF]|^)') + | ||
createBMPCharacterClasses(loneLowSurrogates) | ||
@@ -1022,3 +1022,3 @@ ); | ||
regenerate.version = '1.1.0'; | ||
regenerate.version = '1.2.0'; | ||
@@ -1117,4 +1117,7 @@ var proto = regenerate.prototype; | ||
}, | ||
'toString': function() { | ||
var result = createCharacterClassesFromData(this.data); | ||
'toString': function(options) { | ||
var result = createCharacterClassesFromData( | ||
this.data, | ||
options ? options.bmpOnly : false | ||
); | ||
// Use `\0` instead of `\x00` where possible. | ||
@@ -1121,0 +1124,0 @@ return result.replace(regexNull, '\\0$1'); |
46649
1060
333