Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

named-regexp-groups

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

named-regexp-groups - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

115

dist/index.es.js

@@ -0,1 +1,37 @@

function _typeof(obj) {
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function (obj) {
return typeof obj;
};
} else {
_typeof = function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
}
return _typeof(obj);
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
/*!

@@ -5,10 +41,8 @@ * @copyright 2017- Commenthol

*/
var R_NAME = /([a-zA-Z_$][a-zA-Z_$0-9]{0,50})/;
var R_NAME_REPLACE = new RegExp('\\$\\+{' + R_NAME.source + '}', 'g');
var R_NAMED_BACKREF = new RegExp('^[?:]&' + R_NAME.source);
var R_GROUP = new RegExp('^[?:]<' + R_NAME.source + '>([^]*)');
var R_NAME_REPLACE = new RegExp("\\$\\+{".concat(R_NAME.source, "}"), 'g');
var R_NAMED_BACKREF = new RegExp("^[?:]&".concat(R_NAME.source));
var R_GROUP = new RegExp("^[?:]<".concat(R_NAME.source, ">([^]*)"));
var R_GROUPS = /([\\]?[()])/g;
var R_EMPTY_GROUPS = /\(\)/g;
function generate(str, flags) {

@@ -20,5 +54,7 @@ str = str || '';

/* istanbul ignore else */
if (str instanceof RegExp) {
flags = flags || str.flags || '';
/* istanbul ignore if */
if (!flags) {

@@ -30,2 +66,3 @@ // No RegExp.flags for node < v6.

}
str = str.source;

@@ -35,7 +72,9 @@ }

var store = {
count: 0, // counter for unnamed matching group
groups: [''], // store for named pattern
count: 0,
// counter for unnamed matching group
groups: [''],
// store for named pattern
names: [] // store for names of capture groups
};
var index = 0;

@@ -53,2 +92,3 @@ var arr = str.split(R_GROUPS);

break;
case ')':

@@ -58,6 +98,9 @@ block = store.groups.pop();

/* istanbul ignore else */
if (name) {
named[name] = block.substr(1);
}
break;
default:

@@ -68,5 +111,6 @@ // is it a real group, not a cluster (?:...), or assertion (?=...), (?!...)

if (isGroup) {
index++;
// named capture group check
index++; // named capture group check
name = R_GROUP.exec(s);
if (name && name[1]) {

@@ -79,3 +123,5 @@ if (!groups[name[1]]) {

}
s = name[2] || '';
if (arr[i + 1] === ')' && !name[2]) {

@@ -87,5 +133,7 @@ s = '[^]+';

groups[store.count++] = index;
}
// named backreference check
} // named backreference check
name = R_NAMED_BACKREF.exec(s);
if (name && name[1]) {

@@ -95,20 +143,20 @@ s = named[name[1]] || '';

}
break;
}
store.groups = store.groups.map(function (group) {
return group + s;
});
return s;
}).join('').replace(R_EMPTY_GROUPS, ''); // remove any empty groups
return { source: source, flags: flags, groups: groups, named: named };
return {
source: source,
flags: flags,
groups: groups,
named: named
};
}
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**

@@ -120,3 +168,5 @@ * Creates a regular expression with named capture groups

var NamedRegExp = function () {
var NamedRegExp =
/*#__PURE__*/
function () {
/**

@@ -163,3 +213,2 @@ * Creates a regular expression with named capture groups

}
/**

@@ -179,3 +228,3 @@ * Execute a search with `str`

_createClass(NamedRegExp, [{
key: 'exec',
key: "exec",
value: function exec(str) {

@@ -185,2 +234,3 @@ var _this = this;

var res = this.regex.exec(str);
if (res) {

@@ -192,5 +242,5 @@ res.groups = {};

}
return res;
}
/**

@@ -207,7 +257,6 @@ * test for `str`

}, {
key: 'test',
key: "test",
value: function test(str) {
return this.regex.test(str);
}
/**

@@ -218,7 +267,6 @@ * outputs regex as String

}, {
key: 'toString',
key: "toString",
value: function toString() {
return this.regex.toString();
}
/**

@@ -257,21 +305,26 @@ * Replace `str` by `replacement` using named capture groups

/* istanbul ignore next */
switch (typeof repl === 'undefined' ? 'undefined' : _typeof(repl)) {
switch (_typeof(repl)) {
case 'string':
repl = repl.replace(R_NAME_REPLACE, function (m, name) {
var idx = _this2.groups[name];
if (idx === undefined || idx === null) {
return '';
}
return '$' + _this2.groups[name];
});
break;
case 'function':
repl = replacement.bind(this);
break;
default:
return String(repl);
}
return str.replace(this.regex, repl);
}
/**

@@ -295,3 +348,2 @@ * Search for a match in `str`

}
/**

@@ -313,3 +365,2 @@ * split `str`

}
/**

@@ -316,0 +367,0 @@ * search `str`

@@ -1,1 +0,1 @@

var R_NAME=/([a-zA-Z_$][a-zA-Z_$0-9]{0,50})/,R_NAME_REPLACE=new RegExp("\\$\\+{"+R_NAME.source+"}","g"),R_NAMED_BACKREF=new RegExp("^[?:]&"+R_NAME.source),R_GROUP=new RegExp("^[?:]<"+R_NAME.source+">([^]*)"),R_GROUPS=/([\\]?[()])/g,R_EMPTY_GROUPS=/\(\)/g;function generate(e,r){var t={},n={};(e=e||"")instanceof RegExp&&((r=r||e.flags||"")||(e.ignoreCase&&(r+="i"),e.multiline&&(r+="m"),e.global&&(r+="g")),e=e.source);var o={count:0,groups:[""],names:[]},u=0,s=e.split(R_GROUPS);return{source:s.map(function(e,r){var a,c;switch(e){case"(":o.groups.push(""),o.names.push("");break;case")":c=o.groups.pop(),(a=o.names.pop())&&(n[a]=c.substr(1));break;default:"("===s[r-1]&&!/^\?[:!=]/.test(e)&&(u++,(a=R_GROUP.exec(e))&&a[1]?(t[a[1]]?t[o.count++]=u:(o.names[o.names.length-1]=a[1],t[a[1]]=u),e=a[2]||"",")"!==s[r+1]||a[2]||(e="[^]+")):t[o.count++]=u,(a=R_NAMED_BACKREF.exec(e))&&a[1]&&(e=n[a[1]]||""))}return o.groups=o.groups.map(function(r){return r+e}),e}).join("").replace(R_EMPTY_GROUPS,""),flags:r,groups:t,named:n}}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_createClass=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}();function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}var NamedRegExp=function(){function e(r,t){_classCallCheck(this,e);var n=generate(r,t);this.regex=new RegExp(n.source,n.flags),this.source=this.regex.source,this.groups=n.groups}return _createClass(e,[{key:"exec",value:function(e){var r=this,t=this.regex.exec(e);return t&&(t.groups={},Object.keys(this.groups).forEach(function(e){t.groups[e]=t[r.groups[e]]})),t}},{key:"test",value:function(e){return this.regex.test(e)}},{key:"toString",value:function(){return this.regex.toString()}},{key:Symbol.replace,value:function(e,r){var t=this,n=r;switch(void 0===n?"undefined":_typeof(n)){case"string":n=n.replace(R_NAME_REPLACE,function(e,r){var n=t.groups[r];return void 0===n||null===n?"":"$"+t.groups[r]});break;case"function":n=r.bind(this);break;default:return String(n)}return e.replace(this.regex,n)}},{key:Symbol.match,value:function(e){return this.exec(e)}},{key:Symbol.split,value:function(e){return e.split(this.regex)}},{key:Symbol.search,value:function(e){return e.search(this.regex)}}]),e}();export default NamedRegExp;
function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),e}function generate(e,r){var t={},n={},o="";(e=e||"")instanceof RegExp&&((r=r||e.flags||"")||(e.ignoreCase&&(r+="i"),e.multiline&&(r+="m"),e.global&&(r+="g")),e=e.source);var s={count:0,groups:[""],names:[]},u=0,a=e.split(R_GROUPS);return o=a.map(function(e,r){var o,c;switch(e){case"(":s.groups.push(""),s.names.push("");break;case")":c=s.groups.pop(),(o=s.names.pop())&&(n[o]=c.substr(1));break;default:"("===a[r-1]&&!/^\?[:!=]/.test(e)&&(u++,(o=R_GROUP.exec(e))&&o[1]?(t[o[1]]?t[s.count++]=u:(s.names[s.names.length-1]=o[1],t[o[1]]=u),e=o[2]||"",")"!==a[r+1]||o[2]||(e="[^]+")):t[s.count++]=u,(o=R_NAMED_BACKREF.exec(e))&&o[1]&&(e=n[o[1]]||""))}return s.groups=s.groups.map(function(r){return r+e}),e}).join("").replace(R_EMPTY_GROUPS,""),{source:o,flags:r,groups:t,named:n}}var R_NAME=/([a-zA-Z_$][a-zA-Z_$0-9]{0,50})/,R_NAME_REPLACE=new RegExp("\\$\\+{".concat(R_NAME.source,"}"),"g"),R_NAMED_BACKREF=new RegExp("^[?:]&".concat(R_NAME.source)),R_GROUP=new RegExp("^[?:]<".concat(R_NAME.source,">([^]*)")),R_GROUPS=/([\\]?[()])/g,R_EMPTY_GROUPS=/\(\)/g,NamedRegExp=function(){function e(r,t){_classCallCheck(this,e);var n=generate(r,t);this.regex=new RegExp(n.source,n.flags),this.source=this.regex.source,this.groups=n.groups}return _createClass(e,[{key:"exec",value:function(e){var r=this,t=this.regex.exec(e);return t&&(t.groups={},Object.keys(this.groups).forEach(function(e){t.groups[e]=t[r.groups[e]]})),t}},{key:"test",value:function(e){return this.regex.test(e)}},{key:"toString",value:function(){return this.regex.toString()}},{key:Symbol.replace,value:function(e,r){var t=this,n=r;switch(_typeof(n)){case"string":n=n.replace(R_NAME_REPLACE,function(e,r){var n=t.groups[r];return void 0===n||null===n?"":"$"+t.groups[r]});break;case"function":n=r.bind(this);break;default:return String(n)}return e.replace(this.regex,n)}},{key:Symbol.match,value:function(e){return this.exec(e)}},{key:Symbol.split,value:function(e){return e.split(this.regex)}},{key:Symbol.search,value:function(e){return e.search(this.regex)}}]),e}();export default NamedRegExp;

@@ -5,2 +5,38 @@ 'use strict';

function _typeof(obj) {
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function (obj) {
return typeof obj;
};
} else {
_typeof = function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
}
return _typeof(obj);
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
/*!

@@ -10,10 +46,8 @@ * @copyright 2017- Commenthol

*/
var R_NAME = /([a-zA-Z_$][a-zA-Z_$0-9]{0,50})/;
var R_NAME_REPLACE = new RegExp('\\$\\+{' + R_NAME.source + '}', 'g');
var R_NAMED_BACKREF = new RegExp('^[?:]&' + R_NAME.source);
var R_GROUP = new RegExp('^[?:]<' + R_NAME.source + '>([^]*)');
var R_NAME_REPLACE = new RegExp("\\$\\+{".concat(R_NAME.source, "}"), 'g');
var R_NAMED_BACKREF = new RegExp("^[?:]&".concat(R_NAME.source));
var R_GROUP = new RegExp("^[?:]<".concat(R_NAME.source, ">([^]*)"));
var R_GROUPS = /([\\]?[()])/g;
var R_EMPTY_GROUPS = /\(\)/g;
function generate(str, flags) {

@@ -25,5 +59,7 @@ str = str || '';

/* istanbul ignore else */
if (str instanceof RegExp) {
flags = flags || str.flags || '';
/* istanbul ignore if */
if (!flags) {

@@ -35,2 +71,3 @@ // No RegExp.flags for node < v6.

}
str = str.source;

@@ -40,7 +77,9 @@ }

var store = {
count: 0, // counter for unnamed matching group
groups: [''], // store for named pattern
count: 0,
// counter for unnamed matching group
groups: [''],
// store for named pattern
names: [] // store for names of capture groups
};
var index = 0;

@@ -58,2 +97,3 @@ var arr = str.split(R_GROUPS);

break;
case ')':

@@ -63,6 +103,9 @@ block = store.groups.pop();

/* istanbul ignore else */
if (name) {
named[name] = block.substr(1);
}
break;
default:

@@ -73,5 +116,6 @@ // is it a real group, not a cluster (?:...), or assertion (?=...), (?!...)

if (isGroup) {
index++;
// named capture group check
index++; // named capture group check
name = R_GROUP.exec(s);
if (name && name[1]) {

@@ -84,3 +128,5 @@ if (!groups[name[1]]) {

}
s = name[2] || '';
if (arr[i + 1] === ')' && !name[2]) {

@@ -92,5 +138,7 @@ s = '[^]+';

groups[store.count++] = index;
}
// named backreference check
} // named backreference check
name = R_NAMED_BACKREF.exec(s);
if (name && name[1]) {

@@ -100,20 +148,20 @@ s = named[name[1]] || '';

}
break;
}
store.groups = store.groups.map(function (group) {
return group + s;
});
return s;
}).join('').replace(R_EMPTY_GROUPS, ''); // remove any empty groups
return { source: source, flags: flags, groups: groups, named: named };
return {
source: source,
flags: flags,
groups: groups,
named: named
};
}
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**

@@ -125,3 +173,5 @@ * Creates a regular expression with named capture groups

var NamedRegExp = function () {
var NamedRegExp =
/*#__PURE__*/
function () {
/**

@@ -168,3 +218,2 @@ * Creates a regular expression with named capture groups

}
/**

@@ -184,3 +233,3 @@ * Execute a search with `str`

_createClass(NamedRegExp, [{
key: 'exec',
key: "exec",
value: function exec(str) {

@@ -190,2 +239,3 @@ var _this = this;

var res = this.regex.exec(str);
if (res) {

@@ -197,5 +247,5 @@ res.groups = {};

}
return res;
}
/**

@@ -212,7 +262,6 @@ * test for `str`

}, {
key: 'test',
key: "test",
value: function test(str) {
return this.regex.test(str);
}
/**

@@ -223,7 +272,6 @@ * outputs regex as String

}, {
key: 'toString',
key: "toString",
value: function toString() {
return this.regex.toString();
}
/**

@@ -262,21 +310,26 @@ * Replace `str` by `replacement` using named capture groups

/* istanbul ignore next */
switch (typeof repl === 'undefined' ? 'undefined' : _typeof(repl)) {
switch (_typeof(repl)) {
case 'string':
repl = repl.replace(R_NAME_REPLACE, function (m, name) {
var idx = _this2.groups[name];
if (idx === undefined || idx === null) {
return '';
}
return '$' + _this2.groups[name];
});
break;
case 'function':
repl = replacement.bind(this);
break;
default:
return String(repl);
}
return str.replace(this.regex, repl);
}
/**

@@ -300,3 +353,2 @@ * Search for a match in `str`

}
/**

@@ -318,3 +370,2 @@ * split `str`

}
/**

@@ -321,0 +372,0 @@ * search `str`

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var R_NAME=/([a-zA-Z_$][a-zA-Z_$0-9]{0,50})/,R_NAME_REPLACE=new RegExp("\\$\\+{"+R_NAME.source+"}","g"),R_NAMED_BACKREF=new RegExp("^[?:]&"+R_NAME.source),R_GROUP=new RegExp("^[?:]<"+R_NAME.source+">([^]*)"),R_GROUPS=/([\\]?[()])/g,R_EMPTY_GROUPS=/\(\)/g;function generate(e,r){var t={},n={};(e=e||"")instanceof RegExp&&((r=r||e.flags||"")||(e.ignoreCase&&(r+="i"),e.multiline&&(r+="m"),e.global&&(r+="g")),e=e.source);var o={count:0,groups:[""],names:[]},u=0,s=e.split(R_GROUPS);return{source:s.map(function(e,r){var a,c;switch(e){case"(":o.groups.push(""),o.names.push("");break;case")":c=o.groups.pop(),(a=o.names.pop())&&(n[a]=c.substr(1));break;default:"("===s[r-1]&&!/^\?[:!=]/.test(e)&&(u++,(a=R_GROUP.exec(e))&&a[1]?(t[a[1]]?t[o.count++]=u:(o.names[o.names.length-1]=a[1],t[a[1]]=u),e=a[2]||"",")"!==s[r+1]||a[2]||(e="[^]+")):t[o.count++]=u,(a=R_NAMED_BACKREF.exec(e))&&a[1]&&(e=n[a[1]]||""))}return o.groups=o.groups.map(function(r){return r+e}),e}).join("").replace(R_EMPTY_GROUPS,""),flags:r,groups:t,named:n}}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_createClass=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}();function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}var NamedRegExp=function(){function e(r,t){_classCallCheck(this,e);var n=generate(r,t);this.regex=new RegExp(n.source,n.flags),this.source=this.regex.source,this.groups=n.groups}return _createClass(e,[{key:"exec",value:function(e){var r=this,t=this.regex.exec(e);return t&&(t.groups={},Object.keys(this.groups).forEach(function(e){t.groups[e]=t[r.groups[e]]})),t}},{key:"test",value:function(e){return this.regex.test(e)}},{key:"toString",value:function(){return this.regex.toString()}},{key:Symbol.replace,value:function(e,r){var t=this,n=r;switch(void 0===n?"undefined":_typeof(n)){case"string":n=n.replace(R_NAME_REPLACE,function(e,r){var n=t.groups[r];return void 0===n||null===n?"":"$"+t.groups[r]});break;case"function":n=r.bind(this);break;default:return String(n)}return e.replace(this.regex,n)}},{key:Symbol.match,value:function(e){return this.exec(e)}},{key:Symbol.split,value:function(e){return e.split(this.regex)}},{key:Symbol.search,value:function(e){return e.search(this.regex)}}]),e}();exports.default=NamedRegExp,module.exports=exports.default;
"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),e}function generate(e,t){var r={},n={},o="";(e=e||"")instanceof RegExp&&((t=t||e.flags||"")||(e.ignoreCase&&(t+="i"),e.multiline&&(t+="m"),e.global&&(t+="g")),e=e.source);var s={count:0,groups:[""],names:[]},u=0,a=e.split(R_GROUPS);return o=a.map(function(e,t){var o,c;switch(e){case"(":s.groups.push(""),s.names.push("");break;case")":c=s.groups.pop(),(o=s.names.pop())&&(n[o]=c.substr(1));break;default:"("===a[t-1]&&!/^\?[:!=]/.test(e)&&(u++,(o=R_GROUP.exec(e))&&o[1]?(r[o[1]]?r[s.count++]=u:(s.names[s.names.length-1]=o[1],r[o[1]]=u),e=o[2]||"",")"!==a[t+1]||o[2]||(e="[^]+")):r[s.count++]=u,(o=R_NAMED_BACKREF.exec(e))&&o[1]&&(e=n[o[1]]||""))}return s.groups=s.groups.map(function(t){return t+e}),e}).join("").replace(R_EMPTY_GROUPS,""),{source:o,flags:t,groups:r,named:n}}Object.defineProperty(exports,"__esModule",{value:!0});var R_NAME=/([a-zA-Z_$][a-zA-Z_$0-9]{0,50})/,R_NAME_REPLACE=new RegExp("\\$\\+{".concat(R_NAME.source,"}"),"g"),R_NAMED_BACKREF=new RegExp("^[?:]&".concat(R_NAME.source)),R_GROUP=new RegExp("^[?:]<".concat(R_NAME.source,">([^]*)")),R_GROUPS=/([\\]?[()])/g,R_EMPTY_GROUPS=/\(\)/g,NamedRegExp=function(){function e(t,r){_classCallCheck(this,e);var n=generate(t,r);this.regex=new RegExp(n.source,n.flags),this.source=this.regex.source,this.groups=n.groups}return _createClass(e,[{key:"exec",value:function(e){var t=this,r=this.regex.exec(e);return r&&(r.groups={},Object.keys(this.groups).forEach(function(e){r.groups[e]=r[t.groups[e]]})),r}},{key:"test",value:function(e){return this.regex.test(e)}},{key:"toString",value:function(){return this.regex.toString()}},{key:Symbol.replace,value:function(e,t){var r=this,n=t;switch(_typeof(n)){case"string":n=n.replace(R_NAME_REPLACE,function(e,t){var n=r.groups[t];return void 0===n||null===n?"":"$"+r.groups[t]});break;case"function":n=t.bind(this);break;default:return String(n)}return e.replace(this.regex,n)}},{key:Symbol.match,value:function(e){return this.exec(e)}},{key:Symbol.split,value:function(e){return e.split(this.regex)}},{key:Symbol.search,value:function(e){return e.search(this.regex)}}]),e}();exports.default=NamedRegExp,module.exports=exports.default;
{
"name": "named-regexp-groups",
"version": "1.0.3",
"version": "1.0.4",
"description": "Regular expressions with named capture groups and named back-references",

@@ -19,2 +19,6 @@ "keywords": [

},
"repository": {
"type": "git",
"url": "git://github.com/commenthol/named-regexp-groups.git"
},
"license": "MIT",

@@ -24,6 +28,2 @@ "author": "commenthol <commenthol@gmail.com>",

"module": "dist/index.es.js",
"repository": {
"type": "git",
"url": "git://github.com/commenthol/named-regexp-groups.git"
},
"scripts": {

@@ -41,22 +41,24 @@ "all": "npm run clean && npm run lint && npm run build && npm test",

"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-stage-2": "^6.24.1",
"babel-register": "^6.26.0",
"core-js": "^2.5.5",
"eslint": "^4.19.1",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.11.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.7.0",
"eslint-plugin-standard": "^3.0.1",
"mocha": "^5.1.1",
"nyc": "^11.7.1",
"rimraf": "^2.6.2",
"rollup": "^0.58.1",
"rollup-plugin-babel": "^3.0.3",
"rollup-plugin-uglify": "^3.0.0",
"safe-regex": "^1.1.0"
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.4",
"@babel/preset-env": "^7.6.3",
"@babel/register": "^7.6.2",
"core-js": "^3.3.4",
"eslint": "^6.5.1",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"mocha": "^6.2.2",
"nyc": "^14.1.1",
"rimraf": "^3.0.0",
"rollup": "^1.25.2",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-uglify-es": "^0.0.1",
"safe-regex": "^2.1.1"
},
"engines": {
"node": ">=6.0"
},
"maintainers": [

@@ -63,0 +65,0 @@ "commenthol <commenthol@gmail.com>"

@@ -96,3 +96,3 @@ /*!

return {source, flags, groups, named}
return { source, flags, groups, named }
}

@@ -9,3 +9,3 @@ /*!

import {generate, R_NAME_REPLACE} from './generate'
import { generate, R_NAME_REPLACE } from './generate'

@@ -12,0 +12,0 @@ /**

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc