Skip to content

Commit 381fa75

Browse files
committed
Formatting and comments
1 parent c1f4abf commit 381fa75

File tree

9 files changed

+2311
-2403
lines changed

9 files changed

+2311
-2403
lines changed

src/addons/build.js

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* XRegExp.build 3.1.0
2+
* XRegExp.build 3.1.1-dev
33
* <xregexp.com>
44
* Steven Levithan (c) 2012-2016 MIT License
55
* Inspired by Lea Verou's RegExp.create <lea.verou.me>
@@ -12,13 +12,12 @@ module.exports = function(XRegExp) {
1212
subParts = /(\()(?!\?)|\\([1-9]\d*)|\\[\s\S]|\[(?:[^\\\]]|\\[\s\S])*]/g,
1313
parts = XRegExp.union([/\({{([\w$]+)}}\)|{{([\w$]+)}}/, subParts], 'g');
1414

15-
/**
16-
* Strips a leading `^` and trailing unescaped `$`, if both are present.
17-
*
18-
* @private
19-
* @param {String} pattern Pattern to process.
20-
* @returns {String} Pattern with edge anchors removed.
21-
*/
15+
/**
16+
* Strips a leading `^` and trailing unescaped `$`, if both are present.
17+
*
18+
* @param {String} pattern Pattern to process.
19+
* @returns {String} Pattern with edge anchors removed.
20+
*/
2221
function deanchor(pattern) {
2322
// Allow any number of empty noncapturing groups before/after anchors, because regexes
2423
// built/generated by XRegExp sometimes include them
@@ -37,13 +36,12 @@ module.exports = function(XRegExp) {
3736
return pattern;
3837
}
3938

40-
/**
41-
* Converts the provided value to an XRegExp. Native RegExp flags are not preserved.
42-
*
43-
* @private
44-
* @param {String|RegExp} value Value to convert.
45-
* @returns {RegExp} XRegExp object with XRegExp syntax applied.
46-
*/
39+
/**
40+
* Converts the provided value to an XRegExp. Native RegExp flags are not preserved.
41+
*
42+
* @param {String|RegExp} value Value to convert.
43+
* @returns {RegExp} XRegExp object with XRegExp syntax applied.
44+
*/
4745
function asXRegExp(value) {
4846
return XRegExp.isRegExp(value) ?
4947
(value[REGEX_DATA] && value[REGEX_DATA].captureNames ?
@@ -56,31 +54,30 @@ module.exports = function(XRegExp) {
5654
XRegExp(value);
5755
}
5856

59-
/**
60-
* Builds regexes using named subpatterns, for readability and pattern reuse. Backreferences in the
61-
* outer pattern and provided subpatterns are automatically renumbered to work correctly. Native
62-
* flags used by provided subpatterns are ignored in favor of the `flags` argument.
63-
*
64-
* @memberOf XRegExp
65-
* @param {String} pattern XRegExp pattern using `{{name}}` for embedded subpatterns. Allows
66-
* `({{name}})` as shorthand for `(?<name>{{name}})`. Patterns cannot be embedded within
67-
* character classes.
68-
* @param {Object} subs Lookup object for named subpatterns. Values can be strings or regexes. A
69-
* leading `^` and trailing unescaped `$` are stripped from subpatterns, if both are present.
70-
* @param {String} [flags] Any combination of XRegExp flags.
71-
* @returns {RegExp} Regex with interpolated subpatterns.
72-
* @example
73-
*
74-
* var time = XRegExp.build('(?x)^ {{hours}} ({{minutes}}) $', {
75-
* hours: XRegExp.build('{{h12}} : | {{h24}}', {
76-
* h12: /1[0-2]|0?[1-9]/,
77-
* h24: /2[0-3]|[01][0-9]/
78-
* }, 'x'),
79-
* minutes: /^[0-5][0-9]$/
80-
* });
81-
* time.test('10:59'); // -> true
82-
* XRegExp.exec('10:59', time).minutes; // -> '59'
83-
*/
57+
/**
58+
* Builds regexes using named subpatterns, for readability and pattern reuse. Backreferences in
59+
* the outer pattern and provided subpatterns are automatically renumbered to work correctly.
60+
* Native flags used by provided subpatterns are ignored in favor of the `flags` argument.
61+
*
62+
* @param {String} pattern XRegExp pattern using `{{name}}` for embedded subpatterns. Allows
63+
* `({{name}})` as shorthand for `(?<name>{{name}})`. Patterns cannot be embedded within
64+
* character classes.
65+
* @param {Object} subs Lookup object for named subpatterns. Values can be strings or regexes. A
66+
* leading `^` and trailing unescaped `$` are stripped from subpatterns, if both are present.
67+
* @param {String} [flags] Any combination of XRegExp flags.
68+
* @returns {RegExp} Regex with interpolated subpatterns.
69+
* @example
70+
*
71+
* var time = XRegExp.build('(?x)^ {{hours}} ({{minutes}}) $', {
72+
* hours: XRegExp.build('{{h12}} : | {{h24}}', {
73+
* h12: /1[0-2]|0?[1-9]/,
74+
* h24: /2[0-3]|[01][0-9]/
75+
* }, 'x'),
76+
* minutes: /^[0-5][0-9]$/
77+
* });
78+
* time.test('10:59'); // -> true
79+
* XRegExp.exec('10:59', time).minutes; // -> '59'
80+
*/
8481
XRegExp.build = function(pattern, subs, flags) {
8582
var inlineFlags = /^\(\?([\w$]+)\)/.exec(pattern),
8683
data = {},

src/addons/matchrecursive.js

Lines changed: 53 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
/*!
2-
* XRegExp.matchRecursive 3.1.0
2+
* XRegExp.matchRecursive 3.1.1-dev
33
* <xregexp.com>
44
* Steven Levithan (c) 2009-2016 MIT License
55
*/
66

77
module.exports = function(XRegExp) {
88
'use strict';
99

10-
/**
11-
* Returns a match detail object composed of the provided values.
12-
*
13-
* @private
14-
*/
10+
/**
11+
* Returns a match detail object composed of the provided values.
12+
*/
1513
function row(name, value, start, end) {
1614
return {
1715
name: name,
@@ -21,56 +19,55 @@ module.exports = function(XRegExp) {
2119
};
2220
}
2321

24-
/**
25-
* Returns an array of match strings between outermost left and right delimiters, or an array of
26-
* objects with detailed match parts and position data. An error is thrown if delimiters are
27-
* unbalanced within the data.
28-
*
29-
* @memberOf XRegExp
30-
* @param {String} str String to search.
31-
* @param {String} left Left delimiter as an XRegExp pattern.
32-
* @param {String} right Right delimiter as an XRegExp pattern.
33-
* @param {String} [flags] Any native or XRegExp flags, used for the left and right delimiters.
34-
* @param {Object} [options] Lets you specify `valueNames` and `escapeChar` options.
35-
* @returns {Array} Array of matches, or an empty array.
36-
* @example
37-
*
38-
* // Basic usage
39-
* var str = '(t((e))s)t()(ing)';
40-
* XRegExp.matchRecursive(str, '\\(', '\\)', 'g');
41-
* // -> ['t((e))s', '', 'ing']
42-
*
43-
* // Extended information mode with valueNames
44-
* str = 'Here is <div> <div>an</div></div> example';
45-
* XRegExp.matchRecursive(str, '<div\\s*>', '</div>', 'gi', {
46-
* valueNames: ['between', 'left', 'match', 'right']
47-
* });
48-
* // -> [
49-
* // {name: 'between', value: 'Here is ', start: 0, end: 8},
50-
* // {name: 'left', value: '<div>', start: 8, end: 13},
51-
* // {name: 'match', value: ' <div>an</div>', start: 13, end: 27},
52-
* // {name: 'right', value: '</div>', start: 27, end: 33},
53-
* // {name: 'between', value: ' example', start: 33, end: 41}
54-
* // ]
55-
*
56-
* // Omitting unneeded parts with null valueNames, and using escapeChar
57-
* str = '...{1}.\\{{function(x,y){return {y:x}}}';
58-
* XRegExp.matchRecursive(str, '{', '}', 'g', {
59-
* valueNames: ['literal', null, 'value', null],
60-
* escapeChar: '\\'
61-
* });
62-
* // -> [
63-
* // {name: 'literal', value: '...', start: 0, end: 3},
64-
* // {name: 'value', value: '1', start: 4, end: 5},
65-
* // {name: 'literal', value: '.\\{', start: 6, end: 9},
66-
* // {name: 'value', value: 'function(x,y){return {y:x}}', start: 10, end: 37}
67-
* // ]
68-
*
69-
* // Sticky mode via flag y
70-
* str = '<1><<<2>>><3>4<5>';
71-
* XRegExp.matchRecursive(str, '<', '>', 'gy');
72-
* // -> ['1', '<<2>>', '3']
73-
*/
22+
/**
23+
* Returns an array of match strings between outermost left and right delimiters, or an array of
24+
* objects with detailed match parts and position data. An error is thrown if delimiters are
25+
* unbalanced within the data.
26+
*
27+
* @param {String} str String to search.
28+
* @param {String} left Left delimiter as an XRegExp pattern.
29+
* @param {String} right Right delimiter as an XRegExp pattern.
30+
* @param {String} [flags] Any native or XRegExp flags, used for the left and right delimiters.
31+
* @param {Object} [options] Lets you specify `valueNames` and `escapeChar` options.
32+
* @returns {Array} Array of matches, or an empty array.
33+
* @example
34+
*
35+
* // Basic usage
36+
* var str = '(t((e))s)t()(ing)';
37+
* XRegExp.matchRecursive(str, '\\(', '\\)', 'g');
38+
* // -> ['t((e))s', '', 'ing']
39+
*
40+
* // Extended information mode with valueNames
41+
* str = 'Here is <div> <div>an</div></div> example';
42+
* XRegExp.matchRecursive(str, '<div\\s*>', '</div>', 'gi', {
43+
* valueNames: ['between', 'left', 'match', 'right']
44+
* });
45+
* // -> [
46+
* // {name: 'between', value: 'Here is ', start: 0, end: 8},
47+
* // {name: 'left', value: '<div>', start: 8, end: 13},
48+
* // {name: 'match', value: ' <div>an</div>', start: 13, end: 27},
49+
* // {name: 'right', value: '</div>', start: 27, end: 33},
50+
* // {name: 'between', value: ' example', start: 33, end: 41}
51+
* // ]
52+
*
53+
* // Omitting unneeded parts with null valueNames, and using escapeChar
54+
* str = '...{1}.\\{{function(x,y){return {y:x}}}';
55+
* XRegExp.matchRecursive(str, '{', '}', 'g', {
56+
* valueNames: ['literal', null, 'value', null],
57+
* escapeChar: '\\'
58+
* });
59+
* // -> [
60+
* // {name: 'literal', value: '...', start: 0, end: 3},
61+
* // {name: 'value', value: '1', start: 4, end: 5},
62+
* // {name: 'literal', value: '.\\{', start: 6, end: 9},
63+
* // {name: 'value', value: 'function(x,y){return {y:x}}', start: 10, end: 37}
64+
* // ]
65+
*
66+
* // Sticky mode via flag y
67+
* str = '<1><<<2>>><3>4<5>';
68+
* XRegExp.matchRecursive(str, '<', '>', 'gy');
69+
* // -> ['1', '<<2>>', '3']
70+
*/
7471
XRegExp.matchRecursive = function(str, left, right, flags, options) {
7572
flags = flags || '';
7673
options = options || {};

0 commit comments

Comments
 (0)