Comparing version 3.1.0 to 3.1.1
{ | ||
"name": "xregexp", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "Extended regular expressions", | ||
@@ -14,3 +14,5 @@ "homepage": "http://xregexp.com/", | ||
"regex", | ||
"regexp" | ||
"regexp", | ||
"regular expression", | ||
"unicode" | ||
], | ||
@@ -17,0 +19,0 @@ "main": "./src/index.js", |
@@ -1,7 +0,7 @@ | ||
[XRegExp](http://xregexp.com/) 3.1.0 | ||
[XRegExp](http://xregexp.com/) 3.1.1 | ||
==================================== | ||
XRegExp provides augmented (and extensible) JavaScript regular expressions. You get new modern syntax and flags beyond what browsers support natively. XRegExp is also a regex utility belt with tools to make your client-side grepping and parsing easier, while freeing you from worrying about pesky aspects of JavaScript regexes like cross-browser inconsistencies and manually manipulating `lastIndex`. | ||
XRegExp provides augmented (and extensible) JavaScript regular expressions. You get new modern syntax and flags beyond what browsers support natively. XRegExp is also a regex utility belt with tools to make your client-side grepping and parsing easier, while freeing you from worrying about pesky aspects of JavaScript regexes like cross-browser inconsistencies or manually manipulating `lastIndex`. | ||
XRegExp supports all native ES6 regular expression syntax. It supports Internet Explorer 5.5+, Firefox 1.5+, Chrome, Safari 3+, and Opera 11+. You can also use it with Node.js, or as a RequireJS module. The base library is about 4.25 KB, minified and gzipped. | ||
XRegExp supports all native ES6 regular expression syntax. It supports Internet Explorer 5.5+, Firefox 1.5+, Chrome, Safari 3+, and Opera 11+. You can also use it with Node.js or as a RequireJS module. | ||
@@ -25,19 +25,26 @@ ## Performance | ||
// It also includes optional pos and sticky arguments | ||
var pos = 3, result = []; | ||
var pos = 3; | ||
var result = []; | ||
while (match = XRegExp.exec('<1><2><3><4>5<6>', /<(\d+)>/, pos, 'sticky')) { | ||
result.push(match[1]); | ||
pos = match.index + match[0].length; | ||
} // result -> ['2', '3', '4'] | ||
} | ||
// result -> ['2', '3', '4'] | ||
// XRegExp.replace allows named backreferences in replacements | ||
XRegExp.replace('2015-02-22', date, '${month}/${day}/${year}'); // -> '02/22/2015' | ||
XRegExp.replace('2015-02-22', date, '${month}/${day}/${year}'); | ||
// -> '02/22/2015' | ||
XRegExp.replace('2015-02-22', date, function(match) { | ||
return match.month + '/' + match.day + '/' + match.year; | ||
}); // -> '02/22/2015' | ||
}); | ||
// -> '02/22/2015' | ||
// In fact, XRegExps compile to RegExps and work perfectly with native methods | ||
date.test('2015-02-22'); // -> true | ||
date.test('2015-02-22'); | ||
// -> true | ||
// The *only* caveat is that named captures must be referenced using numbered backreferences | ||
'2015-02-22'.replace(date, '$2/$3/$1'); // -> '02/22/2015' | ||
// The only caveat is that named captures must be referenced using numbered | ||
// backreferences if used with native methods | ||
'2015-02-22'.replace(date, '$2/$3/$1'); | ||
// -> '02/22/2015' | ||
@@ -55,3 +62,4 @@ // Extract every other digit from a string using XRegExp.forEach | ||
/\d+/ | ||
]); // -> ['2', '4', '56'] | ||
]); | ||
// -> ['2', '4', '56'] | ||
@@ -64,5 +72,6 @@ // You can also pass forward and return specific backreferences | ||
{regex: XRegExp('(?i)^https?://(?<domain>[^/?#]+)'), backref: 'domain'} | ||
]); // -> ['xregexp.com', 'www.google.com'] | ||
]); | ||
// -> ['xregexp.com', 'www.google.com'] | ||
// Merge strings and regexes into a single pattern, safely rewriting backreferences | ||
// Merge strings and regexes into a single pattern with updated backreferences | ||
XRegExp.union(['a+b*c', /(dog)\1/, /(cat)\1/], 'i'); | ||
@@ -72,19 +81,12 @@ // -> /a\+b\*c|(dog)\1|(cat)\2/i | ||
These examples should give you the flavor of what's possible, but XRegExp has more syntax, flags, methods, options, and browser fixes that aren't shown here. You can even augment XRegExp's regular expression syntax with addons (see below) or write your own. See [xregexp.com](http://xregexp.com/) for more details. | ||
These examples give the flavor of what's possible, but XRegExp has more syntax, flags, methods, options, and browser fixes that aren't shown here. You can even augment XRegExp's regular expression syntax with addons (see below) or write your own. See [xregexp.com](http://xregexp.com/) for details. | ||
## Addons | ||
You can either load addons individually, or bundle all addons together with XRegExp by loading `xregexp-all.js`. XRegExp's [npm package](https://www.npmjs.com/package/xregexp) uses `xregexp-all.js`, so addons are always available when XRegExp is installed using npm. | ||
You can either load addons individually, or bundle all addons with XRegExp by loading `xregexp-all.js`. | ||
### Unicode | ||
In browsers, first include the Unicode Base script and then one or more of the addons for Unicode blocks, categories, properties, or scripts. | ||
If not using `xregexp-all.js`, first include the Unicode Base script and then one or more of the addons for Unicode blocks, categories, properties, or scripts. | ||
```html | ||
<script src="src/xregexp.js"></script> | ||
<script src="src/addons/unicode-base.js"></script> | ||
<script src="src/addons/unicode-categories.js"></script> | ||
<script src="src/addons/unicode-scripts.js"></script> | ||
``` | ||
Then you can do this: | ||
@@ -125,11 +127,4 @@ | ||
In browsers, first include the script: | ||
Build regular expressions using named subpatterns, for readability and pattern reuse: | ||
```html | ||
<script src="src/xregexp.js"></script> | ||
<script src="src/addons/build.js"></script> | ||
``` | ||
You can then build regular expressions using named subpatterns, for readability and pattern reuse: | ||
```js | ||
@@ -154,11 +149,4 @@ var time = XRegExp.build('(?x)^ {{hours}} ({{minutes}}) $', { | ||
In browsers, first include the script: | ||
Match recursive constructs using XRegExp pattern strings as left and right delimiters: | ||
```html | ||
<script src="src/xregexp.js"></script> | ||
<script src="src/addons/matchrecursive.js"></script> | ||
``` | ||
You can then match recursive constructs using XRegExp pattern strings as left and right delimiters: | ||
```js | ||
@@ -205,11 +193,5 @@ var str = '(t((e))s)t()(ing)'; | ||
In browsers: | ||
In browsers (bundle XRegExp with all of its addons): | ||
```html | ||
<script src="src/xregexp.js"></script> | ||
``` | ||
Or, to bundle XRegExp with all of its addons: | ||
```html | ||
<script src="xregexp-all.js"></script> | ||
@@ -242,10 +224,6 @@ ``` | ||
Tools: Unicode range generators by [Mathias Bynens](http://mathiasbynens.be/), and adapted from his [unicode-data](https://github.com/mathiasbynens/unicode-data) project. | ||
Unicode range generators by [Mathias Bynens](http://mathiasbynens.be/), and adapted from his [unicode-data](https://github.com/mathiasbynens/unicode-data) project. Uses [Jasmine](http://jasmine.github.io/) for unit tests, and [Benchmark.js](http://benchmarkjs.com) for performance tests. `XRegExp.build` inspired by [RegExp.create](http://lea.verou.me/2011/03/create-complex-regexps-more-easily/) by [Lea Verou](http://lea.verou.me/). `XRegExp.union` inspired by [Ruby](http://www.ruby-lang.org/). XRegExp's syntax extensions and flags come from [Perl](http://www.perl.org/), [.NET](http://www.microsoft.com/net), etc. | ||
Tests: Uses [Jasmine](http://jasmine.github.io/) for unit tests, and [Benchmark.js](http://benchmarkjs.com) for performance tests. | ||
All code, including addons, tools, and tests, is released under the terms of the [MIT License](http://mit-license.org/). | ||
Prior art: `XRegExp.build` inspired by [Lea Verou](http://lea.verou.me/)'s [RegExp.create](http://lea.verou.me/2011/03/create-complex-regexps-more-easily/). `XRegExp.union` inspired by [Ruby](http://www.ruby-lang.org/). XRegExp's syntax extensions and flags come from [Perl](http://www.perl.org/), [.NET](http://www.microsoft.com/net), etc. | ||
All code, including addons, tools, and tests, is released under the terms of the [MIT](http://mit-license.org/) license. | ||
Fork me to show support, fix, and extend. |
/*! | ||
* XRegExp.build 3.1.0 | ||
* XRegExp.build 3.1.1 | ||
* <xregexp.com> | ||
@@ -11,13 +11,12 @@ * Steven Levithan (c) 2012-2016 MIT License | ||
var REGEX_DATA = 'xregexp', | ||
subParts = /(\()(?!\?)|\\([1-9]\d*)|\\[\s\S]|\[(?:[^\\\]]|\\[\s\S])*]/g, | ||
parts = XRegExp.union([/\({{([\w$]+)}}\)|{{([\w$]+)}}/, subParts], 'g'); | ||
var REGEX_DATA = 'xregexp'; | ||
var subParts = /(\()(?!\?)|\\([1-9]\d*)|\\[\s\S]|\[(?:[^\\\]]|\\[\s\S])*]/g; | ||
var parts = XRegExp.union([/\({{([\w$]+)}}\)|{{([\w$]+)}}/, subParts], 'g'); | ||
/** | ||
* Strips a leading `^` and trailing unescaped `$`, if both are present. | ||
* | ||
* @private | ||
* @param {String} pattern Pattern to process. | ||
* @returns {String} Pattern with edge anchors removed. | ||
*/ | ||
/** | ||
* Strips a leading `^` and trailing unescaped `$`, if both are present. | ||
* | ||
* @param {String} pattern Pattern to process. | ||
* @returns {String} Pattern with edge anchors removed. | ||
*/ | ||
function deanchor(pattern) { | ||
@@ -41,9 +40,8 @@ // Allow any number of empty noncapturing groups before/after anchors, because regexes | ||
/** | ||
* Converts the provided value to an XRegExp. Native RegExp flags are not preserved. | ||
* | ||
* @private | ||
* @param {String|RegExp} value Value to convert. | ||
* @returns {RegExp} XRegExp object with XRegExp syntax applied. | ||
*/ | ||
/** | ||
* Converts the provided value to an XRegExp. Native RegExp flags are not preserved. | ||
* | ||
* @param {String|RegExp} value Value to convert. | ||
* @returns {RegExp} XRegExp object with XRegExp syntax applied. | ||
*/ | ||
function asXRegExp(value) { | ||
@@ -61,27 +59,26 @@ return XRegExp.isRegExp(value) ? | ||
/** | ||
* Builds regexes using named subpatterns, for readability and pattern reuse. Backreferences in the | ||
* outer pattern and provided subpatterns are automatically renumbered to work correctly. Native | ||
* flags used by provided subpatterns are ignored in favor of the `flags` argument. | ||
* | ||
* @memberOf XRegExp | ||
* @param {String} pattern XRegExp pattern using `{{name}}` for embedded subpatterns. Allows | ||
* `({{name}})` as shorthand for `(?<name>{{name}})`. Patterns cannot be embedded within | ||
* character classes. | ||
* @param {Object} subs Lookup object for named subpatterns. Values can be strings or regexes. A | ||
* leading `^` and trailing unescaped `$` are stripped from subpatterns, if both are present. | ||
* @param {String} [flags] Any combination of XRegExp flags. | ||
* @returns {RegExp} Regex with interpolated subpatterns. | ||
* @example | ||
* | ||
* var time = XRegExp.build('(?x)^ {{hours}} ({{minutes}}) $', { | ||
* hours: XRegExp.build('{{h12}} : | {{h24}}', { | ||
* h12: /1[0-2]|0?[1-9]/, | ||
* h24: /2[0-3]|[01][0-9]/ | ||
* }, 'x'), | ||
* minutes: /^[0-5][0-9]$/ | ||
* }); | ||
* time.test('10:59'); // -> true | ||
* XRegExp.exec('10:59', time).minutes; // -> '59' | ||
*/ | ||
/** | ||
* Builds regexes using named subpatterns, for readability and pattern reuse. Backreferences in | ||
* the outer pattern and provided subpatterns are automatically renumbered to work correctly. | ||
* Native flags used by provided subpatterns are ignored in favor of the `flags` argument. | ||
* | ||
* @param {String} pattern XRegExp pattern using `{{name}}` for embedded subpatterns. Allows | ||
* `({{name}})` as shorthand for `(?<name>{{name}})`. Patterns cannot be embedded within | ||
* character classes. | ||
* @param {Object} subs Lookup object for named subpatterns. Values can be strings or regexes. A | ||
* leading `^` and trailing unescaped `$` are stripped from subpatterns, if both are present. | ||
* @param {String} [flags] Any combination of XRegExp flags. | ||
* @returns {RegExp} Regex with interpolated subpatterns. | ||
* @example | ||
* | ||
* var time = XRegExp.build('(?x)^ {{hours}} ({{minutes}}) $', { | ||
* hours: XRegExp.build('{{h12}} : | {{h24}}', { | ||
* h12: /1[0-2]|0?[1-9]/, | ||
* h24: /2[0-3]|[01][0-9]/ | ||
* }, 'x'), | ||
* minutes: /^[0-5][0-9]$/ | ||
* }); | ||
* time.test('10:59'); // -> true | ||
* XRegExp.exec('10:59', time).minutes; // -> '59' | ||
*/ | ||
XRegExp.build = function(pattern, subs, flags) { | ||
@@ -88,0 +85,0 @@ var inlineFlags = /^\(\?([\w$]+)\)/.exec(pattern), |
/*! | ||
* XRegExp.matchRecursive 3.1.0 | ||
* XRegExp.matchRecursive 3.1.1 | ||
* <xregexp.com> | ||
@@ -10,7 +10,5 @@ * Steven Levithan (c) 2009-2016 MIT License | ||
/** | ||
* Returns a match detail object composed of the provided values. | ||
* | ||
* @private | ||
*/ | ||
/** | ||
* Returns a match detail object composed of the provided values. | ||
*/ | ||
function row(name, value, start, end) { | ||
@@ -25,52 +23,51 @@ return { | ||
/** | ||
* Returns an array of match strings between outermost left and right delimiters, or an array of | ||
* objects with detailed match parts and position data. An error is thrown if delimiters are | ||
* unbalanced within the data. | ||
* | ||
* @memberOf XRegExp | ||
* @param {String} str String to search. | ||
* @param {String} left Left delimiter as an XRegExp pattern. | ||
* @param {String} right Right delimiter as an XRegExp pattern. | ||
* @param {String} [flags] Any native or XRegExp flags, used for the left and right delimiters. | ||
* @param {Object} [options] Lets you specify `valueNames` and `escapeChar` options. | ||
* @returns {Array} Array of matches, or an empty array. | ||
* @example | ||
* | ||
* // Basic usage | ||
* var str = '(t((e))s)t()(ing)'; | ||
* XRegExp.matchRecursive(str, '\\(', '\\)', 'g'); | ||
* // -> ['t((e))s', '', 'ing'] | ||
* | ||
* // Extended information mode with valueNames | ||
* str = 'Here is <div> <div>an</div></div> example'; | ||
* XRegExp.matchRecursive(str, '<div\\s*>', '</div>', 'gi', { | ||
* valueNames: ['between', 'left', 'match', 'right'] | ||
* }); | ||
* // -> [ | ||
* // {name: 'between', value: 'Here is ', start: 0, end: 8}, | ||
* // {name: 'left', value: '<div>', start: 8, end: 13}, | ||
* // {name: 'match', value: ' <div>an</div>', start: 13, end: 27}, | ||
* // {name: 'right', value: '</div>', start: 27, end: 33}, | ||
* // {name: 'between', value: ' example', start: 33, end: 41} | ||
* // ] | ||
* | ||
* // Omitting unneeded parts with null valueNames, and using escapeChar | ||
* str = '...{1}.\\{{function(x,y){return {y:x}}}'; | ||
* XRegExp.matchRecursive(str, '{', '}', 'g', { | ||
* valueNames: ['literal', null, 'value', null], | ||
* escapeChar: '\\' | ||
* }); | ||
* // -> [ | ||
* // {name: 'literal', value: '...', start: 0, end: 3}, | ||
* // {name: 'value', value: '1', start: 4, end: 5}, | ||
* // {name: 'literal', value: '.\\{', start: 6, end: 9}, | ||
* // {name: 'value', value: 'function(x,y){return {y:x}}', start: 10, end: 37} | ||
* // ] | ||
* | ||
* // Sticky mode via flag y | ||
* str = '<1><<<2>>><3>4<5>'; | ||
* XRegExp.matchRecursive(str, '<', '>', 'gy'); | ||
* // -> ['1', '<<2>>', '3'] | ||
*/ | ||
/** | ||
* Returns an array of match strings between outermost left and right delimiters, or an array of | ||
* objects with detailed match parts and position data. An error is thrown if delimiters are | ||
* unbalanced within the data. | ||
* | ||
* @param {String} str String to search. | ||
* @param {String} left Left delimiter as an XRegExp pattern. | ||
* @param {String} right Right delimiter as an XRegExp pattern. | ||
* @param {String} [flags] Any native or XRegExp flags, used for the left and right delimiters. | ||
* @param {Object} [options] Lets you specify `valueNames` and `escapeChar` options. | ||
* @returns {Array} Array of matches, or an empty array. | ||
* @example | ||
* | ||
* // Basic usage | ||
* var str = '(t((e))s)t()(ing)'; | ||
* XRegExp.matchRecursive(str, '\\(', '\\)', 'g'); | ||
* // -> ['t((e))s', '', 'ing'] | ||
* | ||
* // Extended information mode with valueNames | ||
* str = 'Here is <div> <div>an</div></div> example'; | ||
* XRegExp.matchRecursive(str, '<div\\s*>', '</div>', 'gi', { | ||
* valueNames: ['between', 'left', 'match', 'right'] | ||
* }); | ||
* // -> [ | ||
* // {name: 'between', value: 'Here is ', start: 0, end: 8}, | ||
* // {name: 'left', value: '<div>', start: 8, end: 13}, | ||
* // {name: 'match', value: ' <div>an</div>', start: 13, end: 27}, | ||
* // {name: 'right', value: '</div>', start: 27, end: 33}, | ||
* // {name: 'between', value: ' example', start: 33, end: 41} | ||
* // ] | ||
* | ||
* // Omitting unneeded parts with null valueNames, and using escapeChar | ||
* str = '...{1}.\\{{function(x,y){return {y:x}}}'; | ||
* XRegExp.matchRecursive(str, '{', '}', 'g', { | ||
* valueNames: ['literal', null, 'value', null], | ||
* escapeChar: '\\' | ||
* }); | ||
* // -> [ | ||
* // {name: 'literal', value: '...', start: 0, end: 3}, | ||
* // {name: 'value', value: '1', start: 4, end: 5}, | ||
* // {name: 'literal', value: '.\\{', start: 6, end: 9}, | ||
* // {name: 'value', value: 'function(x,y){return {y:x}}', start: 10, end: 37} | ||
* // ] | ||
* | ||
* // Sticky mode via flag y | ||
* str = '<1><<<2>>><3>4<5>'; | ||
* XRegExp.matchRecursive(str, '<', '>', 'gy'); | ||
* // -> ['1', '<<2>>', '3'] | ||
*/ | ||
XRegExp.matchRecursive = function(str, left, right, flags, options) { | ||
@@ -77,0 +74,0 @@ flags = flags || ''; |
/*! | ||
* XRegExp Unicode Base 3.1.0 | ||
* XRegExp Unicode Base 3.1.1 | ||
* <xregexp.com> | ||
@@ -7,26 +7,32 @@ * Steven Levithan (c) 2008-2016 MIT License | ||
/** | ||
* Adds base support for Unicode matching: | ||
* - Adds syntax `\p{..}` for matching Unicode tokens. Tokens can be inverted using `\P{..}` or | ||
* `\p{^..}`. Token names ignore case, spaces, hyphens, and underscores. You can omit the braces | ||
* for token names that are a single letter (e.g. `\pL` or `PL`). | ||
* - Adds flag A (astral), which enables 21-bit Unicode support. | ||
* - Adds the `XRegExp.addUnicodeData` method used by other addons to provide character data. | ||
* | ||
* Unicode Base relies on externally provided Unicode character data. Official addons are available | ||
* to provide data for Unicode categories, scripts, blocks, and properties. | ||
* | ||
* @requires XRegExp | ||
*/ | ||
module.exports = function(XRegExp) { | ||
'use strict'; | ||
// Storage for Unicode data | ||
/** | ||
* Adds base support for Unicode matching: | ||
* - Adds syntax `\p{..}` for matching Unicode tokens. Tokens can be inverted using `\P{..}` or | ||
* `\p{^..}`. Token names ignore case, spaces, hyphens, and underscores. You can omit the | ||
* braces for token names that are a single letter (e.g. `\pL` or `PL`). | ||
* - Adds flag A (astral), which enables 21-bit Unicode support. | ||
* - Adds the `XRegExp.addUnicodeData` method used by other addons to provide character data. | ||
* | ||
* Unicode Base relies on externally provided Unicode character data. Official addons are | ||
* available to provide data for Unicode categories, scripts, blocks, and properties. | ||
* | ||
* @requires XRegExp | ||
*/ | ||
// ==--------------------------== | ||
// Private stuff | ||
// ==--------------------------== | ||
// Storage for Unicode data | ||
var unicode = {}; | ||
/* ============================== | ||
* Private functions | ||
* ============================== */ | ||
// Reuse utils | ||
var dec = XRegExp._dec; | ||
var hex = XRegExp._hex; | ||
var pad4 = XRegExp._pad4; | ||
// Generates a token lookup name: lowercase, with hyphens, spaces, and underscores removed | ||
// Generates a token lookup name: lowercase, with hyphens, spaces, and underscores removed | ||
function normalize(name) { | ||
@@ -36,21 +42,3 @@ return name.replace(/[- _]+/g, '').toLowerCase(); | ||
// Adds leading zeros if shorter than four characters | ||
function pad4(str) { | ||
while (str.length < 4) { | ||
str = '0' + str; | ||
} | ||
return str; | ||
} | ||
// Converts a hexadecimal number to decimal | ||
function dec(hex) { | ||
return parseInt(hex, 16); | ||
} | ||
// Converts a decimal number to hexadecimal | ||
function hex(dec) { | ||
return parseInt(dec, 10).toString(16); | ||
} | ||
// Gets the decimal code of a literal code unit, \xHH, \uHHHH, or a backslash-escaped literal | ||
// Gets the decimal code of a literal code unit, \xHH, \uHHHH, or a backslash-escaped literal | ||
function charCode(chr) { | ||
@@ -63,17 +51,20 @@ var esc = /^\\[xu](.+)/.exec(chr); | ||
// Inverts a list of ordered BMP characters and ranges | ||
// Inverts a list of ordered BMP characters and ranges | ||
function invertBmp(range) { | ||
var output = '', | ||
lastEnd = -1, | ||
start; | ||
XRegExp.forEach(range, /(\\x..|\\u....|\\?[\s\S])(?:-(\\x..|\\u....|\\?[\s\S]))?/, function(m) { | ||
start = charCode(m[1]); | ||
if (start > (lastEnd + 1)) { | ||
output += '\\u' + pad4(hex(lastEnd + 1)); | ||
if (start > (lastEnd + 2)) { | ||
output += '-\\u' + pad4(hex(start - 1)); | ||
var output = ''; | ||
var lastEnd = -1; | ||
XRegExp.forEach( | ||
range, | ||
/(\\x..|\\u....|\\?[\s\S])(?:-(\\x..|\\u....|\\?[\s\S]))?/, | ||
function(m) { | ||
var start = charCode(m[1]); | ||
if (start > (lastEnd + 1)) { | ||
output += '\\u' + pad4(hex(lastEnd + 1)); | ||
if (start > (lastEnd + 2)) { | ||
output += '-\\u' + pad4(hex(start - 1)); | ||
} | ||
} | ||
lastEnd = charCode(m[2] || m[1]); | ||
} | ||
lastEnd = charCode(m[2] || m[1]); | ||
}); | ||
); | ||
if (lastEnd < 0xFFFF) { | ||
@@ -88,3 +79,3 @@ output += '\\u' + pad4(hex(lastEnd + 1)); | ||
// Generates an inverted BMP range on first use | ||
// Generates an inverted BMP range on first use | ||
function cacheInvertedBmp(slug) { | ||
@@ -97,3 +88,3 @@ var prop = 'b!'; | ||
// Combines and optionally negates BMP and astral data | ||
// Combines and optionally negates BMP and astral data | ||
function buildAstral(slug, isNegated) { | ||
@@ -117,3 +108,3 @@ var item = unicode[slug], | ||
// Builds a complete astral pattern on first use | ||
// Builds a complete astral pattern on first use | ||
function cacheAstral(slug, isNegated) { | ||
@@ -126,9 +117,9 @@ var prop = isNegated ? 'a!' : 'a='; | ||
/* ============================== | ||
* Core functionality | ||
* ============================== */ | ||
// ==--------------------------== | ||
// Core functionality | ||
// ==--------------------------== | ||
/* | ||
* Add Unicode token syntax: \p{..}, \P{..}, \p{^..}. Also add astral mode (flag A). | ||
*/ | ||
/* | ||
* Add Unicode token syntax: \p{..}, \P{..}, \p{^..}. Also add astral mode (flag A). | ||
*/ | ||
XRegExp.addToken( | ||
@@ -191,29 +182,29 @@ // Use `*` instead of `+` to avoid capturing `^` as the token name in `\p{^}` | ||
/** | ||
* Adds to the list of Unicode tokens that XRegExp regexes can match via `\p` or `\P`. | ||
* | ||
* @memberOf XRegExp | ||
* @param {Array} data Objects with named character ranges. Each object may have properties `name`, | ||
* `alias`, `isBmpLast`, `inverseOf`, `bmp`, and `astral`. All but `name` are optional, although | ||
* one of `bmp` or `astral` is required (unless `inverseOf` is set). If `astral` is absent, the | ||
* `bmp` data is used for BMP and astral modes. If `bmp` is absent, the name errors in BMP mode | ||
* but works in astral mode. If both `bmp` and `astral` are provided, the `bmp` data only is used | ||
* in BMP mode, and the combination of `bmp` and `astral` data is used in astral mode. | ||
* `isBmpLast` is needed when a token matches orphan high surrogates *and* uses surrogate pairs | ||
* to match astral code points. The `bmp` and `astral` data should be a combination of literal | ||
* characters and `\xHH` or `\uHHHH` escape sequences, with hyphens to create ranges. Any regex | ||
* metacharacters in the data should be escaped, apart from range-creating hyphens. The `astral` | ||
* data can additionally use character classes and alternation, and should use surrogate pairs to | ||
* represent astral code points. `inverseOf` can be used to avoid duplicating character data if a | ||
* Unicode token is defined as the exact inverse of another token. | ||
* @example | ||
* | ||
* // Basic use | ||
* XRegExp.addUnicodeData([{ | ||
* name: 'XDigit', | ||
* alias: 'Hexadecimal', | ||
* bmp: '0-9A-Fa-f' | ||
* }]); | ||
* XRegExp('\\p{XDigit}:\\p{Hexadecimal}+').test('0:3D'); // -> true | ||
*/ | ||
/** | ||
* Adds to the list of Unicode tokens that XRegExp regexes can match via `\p` or `\P`. | ||
* | ||
* @param {Array} data Objects with named character ranges. Each object may have properties | ||
* `name`, `alias`, `isBmpLast`, `inverseOf`, `bmp`, and `astral`. All but `name` are | ||
* optional, although one of `bmp` or `astral` is required (unless `inverseOf` is set). If | ||
* `astral` is absent, the `bmp` data is used for BMP and astral modes. If `bmp` is absent, | ||
* the name errors in BMP mode but works in astral mode. If both `bmp` and `astral` are | ||
* provided, the `bmp` data only is used in BMP mode, and the combination of `bmp` and | ||
* `astral` data is used in astral mode. `isBmpLast` is needed when a token matches orphan | ||
* high surrogates *and* uses surrogate pairs to match astral code points. The `bmp` and | ||
* `astral` data should be a combination of literal characters and `\xHH` or `\uHHHH` escape | ||
* sequences, with hyphens to create ranges. Any regex metacharacters in the data should be | ||
* escaped, apart from range-creating hyphens. The `astral` data can additionally use | ||
* character classes and alternation, and should use surrogate pairs to represent astral code | ||
* points. `inverseOf` can be used to avoid duplicating character data if a Unicode token is | ||
* defined as the exact inverse of another token. | ||
* @example | ||
* | ||
* // Basic use | ||
* XRegExp.addUnicodeData([{ | ||
* name: 'XDigit', | ||
* alias: 'Hexadecimal', | ||
* bmp: '0-9A-Fa-f' | ||
* }]); | ||
* XRegExp('\\p{XDigit}:\\p{Hexadecimal}+').test('0:3D'); // -> true | ||
*/ | ||
XRegExp.addUnicodeData = function(data) { | ||
@@ -220,0 +211,0 @@ var ERR_NO_NAME = 'Unicode token requires name', |
/*! | ||
* XRegExp Unicode Blocks 3.1.0 | ||
* XRegExp Unicode Blocks 3.1.1 | ||
* <xregexp.com> | ||
@@ -8,13 +8,15 @@ * Steven Levithan (c) 2010-2016 MIT License | ||
/** | ||
* Adds support for all Unicode blocks. Block names use the prefix 'In'. E.g., `\p{InBasicLatin}`. | ||
* Token names are case insensitive, and any spaces, hyphens, and underscores are ignored. | ||
* | ||
* Uses Unicode 8.0.0. | ||
* | ||
* @requires XRegExp, Unicode Base | ||
*/ | ||
module.exports = function(XRegExp) { | ||
'use strict'; | ||
/** | ||
* Adds support for all Unicode blocks. Block names use the prefix 'In'. E.g., | ||
* `\p{InBasicLatin}`. Token names are case insensitive, and any spaces, hyphens, and | ||
* underscores are ignored. | ||
* | ||
* Uses Unicode 8.0.0. | ||
* | ||
* @requires XRegExp, Unicode Base | ||
*/ | ||
if (!XRegExp.addUnicodeData) { | ||
@@ -21,0 +23,0 @@ throw new ReferenceError('Unicode Base must be loaded before Unicode Blocks'); |
/*! | ||
* XRegExp Unicode Categories 3.1.0 | ||
* XRegExp Unicode Categories 3.1.1 | ||
* <xregexp.com> | ||
@@ -8,14 +8,15 @@ * Steven Levithan (c) 2010-2016 MIT License | ||
/** | ||
* Adds support for Unicode's general categories. E.g., `\p{Lu}` or `\p{Uppercase Letter}`. See | ||
* category descriptions in UAX #44 <http://unicode.org/reports/tr44/#GC_Values_Table>. Token names | ||
* are case insensitive, and any spaces, hyphens, and underscores are ignored. | ||
* | ||
* Uses Unicode 8.0.0. | ||
* | ||
* @requires XRegExp, Unicode Base | ||
*/ | ||
module.exports = function(XRegExp) { | ||
'use strict'; | ||
/** | ||
* Adds support for Unicode's general categories. E.g., `\p{Lu}` or `\p{Uppercase Letter}`. See | ||
* category descriptions in UAX #44 <http://unicode.org/reports/tr44/#GC_Values_Table>. Token | ||
* names are case insensitive, and any spaces, hyphens, and underscores are ignored. | ||
* | ||
* Uses Unicode 8.0.0. | ||
* | ||
* @requires XRegExp, Unicode Base | ||
*/ | ||
if (!XRegExp.addUnicodeData) { | ||
@@ -22,0 +23,0 @@ throw new ReferenceError('Unicode Base must be loaded before Unicode Categories'); |
/*! | ||
* XRegExp Unicode Properties 3.1.0 | ||
* XRegExp Unicode Properties 3.1.1 | ||
* <xregexp.com> | ||
@@ -8,43 +8,44 @@ * Steven Levithan (c) 2012-2016 MIT License | ||
/** | ||
* Adds properties to meet the UTS #18 Level 1 RL1.2 requirements for Unicode regex support. See | ||
* <http://unicode.org/reports/tr18/#RL1.2>. Following are definitions of these properties from UAX | ||
* #44 <http://unicode.org/reports/tr44/>: | ||
* | ||
* - Alphabetic | ||
* Characters with the Alphabetic property. Generated from: Lowercase + Uppercase + Lt + Lm + Lo + | ||
* Nl + Other_Alphabetic. | ||
* | ||
* - Default_Ignorable_Code_Point | ||
* For programmatic determination of default ignorable code points. New characters that should be | ||
* ignored in rendering (unless explicitly supported) will be assigned in these ranges, permitting | ||
* programs to correctly handle the default rendering of such characters when not otherwise | ||
* supported. | ||
* | ||
* - Lowercase | ||
* Characters with the Lowercase property. Generated from: Ll + Other_Lowercase. | ||
* | ||
* - Noncharacter_Code_Point | ||
* Code points permanently reserved for internal use. | ||
* | ||
* - Uppercase | ||
* Characters with the Uppercase property. Generated from: Lu + Other_Uppercase. | ||
* | ||
* - White_Space | ||
* Spaces, separator characters and other control characters which should be treated by | ||
* programming languages as "white space" for the purpose of parsing elements. | ||
* | ||
* The properties ASCII, Any, and Assigned are also included but are not defined in UAX #44. UTS #18 | ||
* RL1.2 additionally requires support for Unicode scripts and general categories. These are | ||
* included in XRegExp's Unicode Categories and Unicode Scripts addons. | ||
* | ||
* Token names are case insensitive, and any spaces, hyphens, and underscores are ignored. | ||
* | ||
* Uses Unicode 8.0.0. | ||
* | ||
* @requires XRegExp, Unicode Base | ||
*/ | ||
module.exports = function(XRegExp) { | ||
'use strict'; | ||
/** | ||
* Adds properties to meet the UTS #18 Level 1 RL1.2 requirements for Unicode regex support. See | ||
* <http://unicode.org/reports/tr18/#RL1.2>. Following are definitions of these properties from | ||
* UAX #44 <http://unicode.org/reports/tr44/>: | ||
* | ||
* - Alphabetic | ||
* Characters with the Alphabetic property. Generated from: Lowercase + Uppercase + Lt + Lm + | ||
* Lo + Nl + Other_Alphabetic. | ||
* | ||
* - Default_Ignorable_Code_Point | ||
* For programmatic determination of default ignorable code points. New characters that should | ||
* be ignored in rendering (unless explicitly supported) will be assigned in these ranges, | ||
* permitting programs to correctly handle the default rendering of such characters when not | ||
* otherwise supported. | ||
* | ||
* - Lowercase | ||
* Characters with the Lowercase property. Generated from: Ll + Other_Lowercase. | ||
* | ||
* - Noncharacter_Code_Point | ||
* Code points permanently reserved for internal use. | ||
* | ||
* - Uppercase | ||
* Characters with the Uppercase property. Generated from: Lu + Other_Uppercase. | ||
* | ||
* - White_Space | ||
* Spaces, separator characters and other control characters which should be treated by | ||
* programming languages as "white space" for the purpose of parsing elements. | ||
* | ||
* The properties ASCII, Any, and Assigned are also included but are not defined in UAX #44. UTS | ||
* #18 RL1.2 additionally requires support for Unicode scripts and general categories. These are | ||
* included in XRegExp's Unicode Categories and Unicode Scripts addons. | ||
* | ||
* Token names are case insensitive, and any spaces, hyphens, and underscores are ignored. | ||
* | ||
* Uses Unicode 8.0.0. | ||
* | ||
* @requires XRegExp, Unicode Base | ||
*/ | ||
if (!XRegExp.addUnicodeData) { | ||
@@ -51,0 +52,0 @@ throw new ReferenceError('Unicode Base must be loaded before Unicode Properties'); |
/*! | ||
* XRegExp Unicode Scripts 3.1.0 | ||
* XRegExp Unicode Scripts 3.1.1 | ||
* <xregexp.com> | ||
@@ -8,13 +8,14 @@ * Steven Levithan (c) 2010-2016 MIT License | ||
/** | ||
* Adds support for all Unicode scripts. E.g., `\p{Latin}`. Token names are case insensitive, and | ||
* any spaces, hyphens, and underscores are ignored. | ||
* | ||
* Uses Unicode 8.0.0. | ||
* | ||
* @requires XRegExp, Unicode Base | ||
*/ | ||
module.exports = function(XRegExp) { | ||
'use strict'; | ||
/** | ||
* Adds support for all Unicode scripts. E.g., `\p{Latin}`. Token names are case insensitive, | ||
* and any spaces, hyphens, and underscores are ignored. | ||
* | ||
* Uses Unicode 8.0.0. | ||
* | ||
* @requires XRegExp, Unicode Base | ||
*/ | ||
if (!XRegExp.addUnicodeData) { | ||
@@ -21,0 +22,0 @@ throw new ReferenceError('Unicode Base must be loaded before Unicode Scripts'); |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
232190
4462
222