added all files to project

This commit is contained in:
partoschph68073 committed 2022-03-10 10:36:59 +01:00
1 parent 09dd957b33
commit 46a936d7de
25351 files changed
+3883356

No files matched your search

+442
View File
@@ -0,0 +1,442 @@
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;
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _construct(Parent, args, Class) {
if (_isNativeReflectConstruct()) {
_construct = Reflect.construct;
} else {
_construct = function _construct(Parent, args, Class) {
var a = [null];
a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor();
if (Class) _setPrototypeOf(instance, Class.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
/* eslint-disable node/no-unsupported-features/es-syntax */
/**
* @param {RegExp} regex
* @param {string} newFlags
* @param {Integer} [newLastIndex=regex.lastIndex]
* @returns {RegExp}
*/
function mixinRegex(regex, newFlags) {
var newLastIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : regex.lastIndex;
newFlags = newFlags || '';
regex = new RegExp(regex.source, (newFlags.includes('g') ? 'g' : regex.global ? 'g' : '') + (newFlags.includes('i') ? 'i' : regex.ignoreCase ? 'i' : '') + (newFlags.includes('m') ? 'm' : regex.multiline ? 'm' : '') + (newFlags.includes('u') ? 'u' : regex.unicode ? 'u' : '') + (newFlags.includes('y') ? 'y' : regex.sticky ? 'y' : '') + (newFlags.includes('s') ? 's' : regex.dotAll ? 's' : ''));
regex.lastIndex = newLastIndex;
return regex;
}
var RegExtras = /*#__PURE__*/function () {
function RegExtras(regex, flags, newLastIndex) {
_classCallCheck(this, RegExtras);
this.regex = mixinRegex(typeof regex === 'string' ? new RegExp(regex) : mixinRegex(regex), flags || '', newLastIndex);
}
_createClass(RegExtras, [{
key: "forEach",
value: function forEach(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var regex = mixinRegex(this.regex, 'g');
var matches,
n0,
i = 0;
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
cb.apply(thisObj, matches.concat(i++, n0));
}
return this;
}
}, {
key: "some",
value: function some(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var regex = mixinRegex(this.regex, 'g');
var matches,
ret,
n0,
i = 0;
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return true;
}
}
return false;
}
}, {
key: "every",
value: function every(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var regex = mixinRegex(this.regex, 'g');
var matches,
ret,
n0,
i = 0;
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (!ret) {
return false;
}
}
return true;
}
}, {
key: "map",
value: function map(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var ret = [];
var regex = mixinRegex(this.regex, 'g');
var matches,
n0,
i = 0;
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret.push(cb.apply(thisObj, matches.concat(i++, n0)));
}
return ret;
}
}, {
key: "filter",
value: function filter(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [],
regex = mixinRegex(this.regex, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
matches = matches.concat(i++, n0);
if (cb.apply(thisObj, matches)) {
ret.push(n0[0]);
}
}
return ret;
}
}, {
key: "reduce",
value: function reduce(str, cb, prev) {
var thisObj = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
var matches,
n0,
i = 0;
var regex = mixinRegex(this.regex, 'g');
if (!prev) {
if ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [''].concat(matches.concat(i++, n0)));
}
}
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [prev].concat(matches.concat(i++, n0)));
}
return prev;
}
}, {
key: "reduceRight",
value: function reduceRight(str, cb, prevOrig, thisObjOrig) {
var matches,
n0,
i,
thisObj = thisObjOrig,
prev = prevOrig;
var matchesContainer = [],
regex = mixinRegex(this.regex, 'g');
thisObj = thisObj || null;
while ((matches = regex.exec(str)) !== null) {
matchesContainer.push(matches);
}
i = matchesContainer.length;
if (!i) {
if (arguments.length < 3) {
throw new TypeError('reduce of empty matches array with no initial value');
}
return prev;
}
if (!prev) {
matches = matchesContainer.splice(-1)[0];
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [''].concat(matches.concat(i--, n0)));
}
matchesContainer.reduceRight(function (container, mtches) {
n0 = mtches.splice(0, 1);
prev = cb.apply(thisObj, [prev].concat(mtches.concat(i--, n0)));
return container;
}, matchesContainer);
return prev;
}
}, {
key: "find",
value: function find(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
var regex = mixinRegex(this.regex, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return n0[0];
}
}
return false;
}
}, {
key: "findIndex",
value: function findIndex(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var regex = mixinRegex(this.regex, 'g');
var matches,
i = 0;
while ((matches = regex.exec(str)) !== null) {
var n0 = matches.splice(0, 1);
var ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return i - 1;
}
}
return -1;
}
}, {
key: "findExec",
value: function findExec(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var regex = mixinRegex(this.regex, 'g');
var matches,
i = 0;
while ((matches = regex.exec(str)) !== null) {
var n0 = matches.splice(0, 1);
var ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return matches;
}
}
return false;
}
}, {
key: "filterExec",
value: function filterExec(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [],
regex = mixinRegex(this.regex, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
matches.push(i++, n0[0]);
if (cb.apply(thisObj, matches)) {
ret.push(matches);
}
}
return ret;
}
}]);
return RegExtras;
}();
var _RegExtras = RegExtras;
RegExtras = function RegExtras() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
// eslint-disable-line no-class-assign
return _construct(_RegExtras, args);
};
RegExtras.prototype = _RegExtras.prototype;
RegExtras.mixinRegex = mixinRegex;
/* eslint-disable node/no-unsupported-features/es-syntax */
// We copy the regular expression so as to be able to always
// ensure the exec expression is a global one (and thereby prevent recursion)
/**
*
* @param {RegExtras} RegExtras
* @returns {void}
*/
function addPrototypeMethods(RegExtras) {
RegExtras.prototype.entries = /*#__PURE__*/regeneratorRuntime.mark(function _callee(str) {
var matches, i, regex;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
i = 0;
regex = RegExtras.mixinRegex(this.regex, 'g');
case 2:
if (!((matches = regex.exec(str)) !== null)) {
_context.next = 7;
break;
}
_context.next = 5;
return [i++, matches];
case 5:
_context.next = 2;
break;
case 7:
case "end":
return _context.stop();
}
}
}, _callee, this);
});
RegExtras.prototype.values = /*#__PURE__*/regeneratorRuntime.mark(function _callee2(str) {
var matches, regex;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
regex = RegExtras.mixinRegex(this.regex, 'g');
case 1:
if (!((matches = regex.exec(str)) !== null)) {
_context2.next = 6;
break;
}
_context2.next = 4;
return matches;
case 4:
_context2.next = 1;
break;
case 6:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
});
RegExtras.prototype.keys = /*#__PURE__*/regeneratorRuntime.mark(function _callee3(str) {
var i, regex;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
i = 0;
regex = RegExtras.mixinRegex(this.regex, 'g');
case 2:
if (!(regex.exec(str) !== null)) {
_context3.next = 7;
break;
}
_context3.next = 5;
return i++;
case 5:
_context3.next = 2;
break;
case 7:
case "end":
return _context3.stop();
}
}
}, _callee3, this);
});
}
addPrototypeMethods(RegExtras);
export { RegExtras, mixinRegex };
+1
View File
@@ -0,0 +1 @@
function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function n(e,t){return(n=Object.setPrototypeOf||function(e,n){return e.__proto__=n,e})(e,t)}function t(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function r(e,c,u){return(r=t()?Reflect.construct:function(e,t,r){var c=[null];c.push.apply(c,t);var u=new(Function.bind.apply(e,c));return r&&n(u,r.prototype),u}).apply(null,arguments)}function c(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.lastIndex;return n=n||"",(e=new RegExp(e.source,(n.includes("g")||e.global?"g":"")+(n.includes("i")||e.ignoreCase?"i":"")+(n.includes("m")||e.multiline?"m":"")+(n.includes("u")||e.unicode?"u":"")+(n.includes("y")||e.sticky?"y":"")+(n.includes("s")||e.dotAll?"s":""))).lastIndex=t,e}var u=function(){function n(e,t,r){!function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,n),this.regex=c("string"==typeof e?new RegExp(e):c(e),t||"",r)}var t,r,u;return t=n,(r=[{key:"forEach",value:function(e,n){for(var t,r,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,l=c(this.regex,"g"),i=0;null!==(t=l.exec(e));)r=t.splice(0,1),n.apply(u,t.concat(i++,r));return this}},{key:"some",value:function(e,n){for(var t,r,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,l=c(this.regex,"g"),i=0;null!==(t=l.exec(e));)if(r=t.splice(0,1),n.apply(u,t.concat(i++,r)))return!0;return!1}},{key:"every",value:function(e,n){for(var t,r,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,l=c(this.regex,"g"),i=0;null!==(t=l.exec(e));)if(r=t.splice(0,1),!n.apply(u,t.concat(i++,r)))return!1;return!0}},{key:"map",value:function(e,n){for(var t,r,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,l=[],i=c(this.regex,"g"),o=0;null!==(t=i.exec(e));)r=t.splice(0,1),l.push(n.apply(u,t.concat(o++,r)));return l}},{key:"filter",value:function(e,n){for(var t,r,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,l=0,i=[],o=c(this.regex,"g");null!==(t=o.exec(e));)r=t.splice(0,1),t=t.concat(l++,r),n.apply(u,t)&&i.push(r[0]);return i}},{key:"reduce",value:function(e,n,t){var r,u,l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=0,o=c(this.regex,"g");for(t||null!==(r=o.exec(e))&&(u=r.splice(0,1),t=n.apply(l,[""].concat(r.concat(i++,u))));null!==(r=o.exec(e));)u=r.splice(0,1),t=n.apply(l,[t].concat(r.concat(i++,u)));return t}},{key:"reduceRight",value:function(e,n,t,r){var u,l,i,o=r,a=t,p=[],s=c(this.regex,"g");for(o=o||null;null!==(u=s.exec(e));)p.push(u);if(!(i=p.length)){if(arguments.length<3)throw new TypeError("reduce of empty matches array with no initial value");return a}return a||(u=p.splice(-1)[0],l=u.splice(0,1),a=n.apply(o,[""].concat(u.concat(i--,l)))),p.reduceRight((function(e,t){return l=t.splice(0,1),a=n.apply(o,[a].concat(t.concat(i--,l))),e}),p),a}},{key:"find",value:function(e,n){for(var t,r,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,l=0,i=c(this.regex,"g");null!==(t=i.exec(e));)if(r=t.splice(0,1),n.apply(u,t.concat(l++,r)))return r[0];return!1}},{key:"findIndex",value:function(e,n){for(var t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,u=c(this.regex,"g"),l=0;null!==(t=u.exec(e));){var i=t.splice(0,1),o=n.apply(r,t.concat(l++,i));if(o)return l-1}return-1}},{key:"findExec",value:function(e,n){for(var t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,u=c(this.regex,"g"),l=0;null!==(t=u.exec(e));){var i=t.splice(0,1),o=n.apply(r,t.concat(l++,i));if(o)return t}return!1}},{key:"filterExec",value:function(e,n){for(var t,r,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,l=0,i=[],o=c(this.regex,"g");null!==(t=o.exec(e));)r=t.splice(0,1),t.push(l++,r[0]),n.apply(u,t)&&i.push(t);return i}}])&&e(t.prototype,r),u&&e(t,u),n}(),l=u;(u=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return r(l,n)}).prototype=l.prototype,u.mixinRegex=c,function(e){e.prototype.entries=regeneratorRuntime.mark((function n(t){var r,c,u;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:c=0,u=e.mixinRegex(this.regex,"g");case 2:if(null===(r=u.exec(t))){n.next=7;break}return n.next=5,[c++,r];case 5:n.next=2;break;case 7:case"end":return n.stop()}}),n,this)})),e.prototype.values=regeneratorRuntime.mark((function n(t){var r,c;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:c=e.mixinRegex(this.regex,"g");case 1:if(null===(r=c.exec(t))){n.next=6;break}return n.next=4,r;case 4:n.next=1;break;case 6:case"end":return n.stop()}}),n,this)})),e.prototype.keys=regeneratorRuntime.mark((function n(t){var r,c;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.Line truncated
+99
View File
@@ -0,0 +1,99 @@
/* eslint-disable node/no-unsupported-features/es-syntax */
// We copy the regular expression so as to be able to always
// ensure the exec expression is a global one (and thereby prevent recursion)
/**
*
* @param {RegExtras} RegExtras
* @returns {void}
*/
function addPrototypeMethods(RegExtras) {
RegExtras.prototype.entries = /*#__PURE__*/regeneratorRuntime.mark(function _callee(str) {
var matches, i, regex;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
i = 0;
regex = RegExtras.mixinRegex(this.regex, 'g');
case 2:
if (!((matches = regex.exec(str)) !== null)) {
_context.next = 7;
break;
}
_context.next = 5;
return [i++, matches];
case 5:
_context.next = 2;
break;
case 7:
case "end":
return _context.stop();
}
}
}, _callee, this);
});
RegExtras.prototype.values = /*#__PURE__*/regeneratorRuntime.mark(function _callee2(str) {
var matches, regex;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
regex = RegExtras.mixinRegex(this.regex, 'g');
case 1:
if (!((matches = regex.exec(str)) !== null)) {
_context2.next = 6;
break;
}
_context2.next = 4;
return matches;
case 4:
_context2.next = 1;
break;
case 6:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
});
RegExtras.prototype.keys = /*#__PURE__*/regeneratorRuntime.mark(function _callee3(str) {
var i, regex;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
i = 0;
regex = RegExtras.mixinRegex(this.regex, 'g');
case 2:
if (!(regex.exec(str) !== null)) {
_context3.next = 7;
break;
}
_context3.next = 5;
return i++;
case 5:
_context3.next = 2;
break;
case 7:
case "end":
return _context3.stop();
}
}
}, _callee3, this);
});
}
export default addPrototypeMethods;
+109
View File
@@ -0,0 +1,109 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.RegExtras = {}));
}(this, (function (exports) { 'use strict';
/* eslint-disable node/no-unsupported-features/es-syntax */
// We copy the regular expression so as to be able to always
// ensure the exec expression is a global one (and thereby prevent recursion)
/**
*
* @param {RegExtras} RegExtras
* @returns {void}
*/
function addPrototypeMethods(RegExtras) {
RegExtras.prototype.entries = /*#__PURE__*/regeneratorRuntime.mark(function _callee(str) {
var matches, i, regex;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
i = 0;
regex = RegExtras.mixinRegex(this.regex, 'g');
case 2:
if (!((matches = regex.exec(str)) !== null)) {
_context.next = 7;
break;
}
_context.next = 5;
return [i++, matches];
case 5:
_context.next = 2;
break;
case 7:
case "end":
return _context.stop();
}
}
}, _callee, this);
});
RegExtras.prototype.values = /*#__PURE__*/regeneratorRuntime.mark(function _callee2(str) {
var matches, regex;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
regex = RegExtras.mixinRegex(this.regex, 'g');
case 1:
if (!((matches = regex.exec(str)) !== null)) {
_context2.next = 6;
break;
}
_context2.next = 4;
return matches;
case 4:
_context2.next = 1;
break;
case 6:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
});
RegExtras.prototype.keys = /*#__PURE__*/regeneratorRuntime.mark(function _callee3(str) {
var i, regex;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
i = 0;
regex = RegExtras.mixinRegex(this.regex, 'g');
case 2:
if (!(regex.exec(str) !== null)) {
_context3.next = 7;
break;
}
_context3.next = 5;
return i++;
case 5:
_context3.next = 2;
break;
case 7:
case "end":
return _context3.stop();
}
}
}, _callee3, this);
});
}
exports.default = addPrototypeMethods;
Object.defineProperty(exports, '__esModule', { value: true });
})));
+452
View File
@@ -0,0 +1,452 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.RegExtras = {}));
}(this, (function (exports) { 'use strict';
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;
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _construct(Parent, args, Class) {
if (_isNativeReflectConstruct()) {
_construct = Reflect.construct;
} else {
_construct = function _construct(Parent, args, Class) {
var a = [null];
a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor();
if (Class) _setPrototypeOf(instance, Class.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
/* eslint-disable node/no-unsupported-features/es-syntax */
/**
* @param {RegExp} regex
* @param {string} newFlags
* @param {Integer} [newLastIndex=regex.lastIndex]
* @returns {RegExp}
*/
function mixinRegex(regex, newFlags) {
var newLastIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : regex.lastIndex;
newFlags = newFlags || '';
regex = new RegExp(regex.source, (newFlags.includes('g') ? 'g' : regex.global ? 'g' : '') + (newFlags.includes('i') ? 'i' : regex.ignoreCase ? 'i' : '') + (newFlags.includes('m') ? 'm' : regex.multiline ? 'm' : '') + (newFlags.includes('u') ? 'u' : regex.unicode ? 'u' : '') + (newFlags.includes('y') ? 'y' : regex.sticky ? 'y' : '') + (newFlags.includes('s') ? 's' : regex.dotAll ? 's' : ''));
regex.lastIndex = newLastIndex;
return regex;
}
exports.RegExtras = /*#__PURE__*/function () {
function RegExtras(regex, flags, newLastIndex) {
_classCallCheck(this, RegExtras);
this.regex = mixinRegex(typeof regex === 'string' ? new RegExp(regex) : mixinRegex(regex), flags || '', newLastIndex);
}
_createClass(RegExtras, [{
key: "forEach",
value: function forEach(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var regex = mixinRegex(this.regex, 'g');
var matches,
n0,
i = 0;
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
cb.apply(thisObj, matches.concat(i++, n0));
}
return this;
}
}, {
key: "some",
value: function some(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var regex = mixinRegex(this.regex, 'g');
var matches,
ret,
n0,
i = 0;
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return true;
}
}
return false;
}
}, {
key: "every",
value: function every(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var regex = mixinRegex(this.regex, 'g');
var matches,
ret,
n0,
i = 0;
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (!ret) {
return false;
}
}
return true;
}
}, {
key: "map",
value: function map(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var ret = [];
var regex = mixinRegex(this.regex, 'g');
var matches,
n0,
i = 0;
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret.push(cb.apply(thisObj, matches.concat(i++, n0)));
}
return ret;
}
}, {
key: "filter",
value: function filter(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [],
regex = mixinRegex(this.regex, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
matches = matches.concat(i++, n0);
if (cb.apply(thisObj, matches)) {
ret.push(n0[0]);
}
}
return ret;
}
}, {
key: "reduce",
value: function reduce(str, cb, prev) {
var thisObj = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
var matches,
n0,
i = 0;
var regex = mixinRegex(this.regex, 'g');
if (!prev) {
if ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [''].concat(matches.concat(i++, n0)));
}
}
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [prev].concat(matches.concat(i++, n0)));
}
return prev;
}
}, {
key: "reduceRight",
value: function reduceRight(str, cb, prevOrig, thisObjOrig) {
var matches,
n0,
i,
thisObj = thisObjOrig,
prev = prevOrig;
var matchesContainer = [],
regex = mixinRegex(this.regex, 'g');
thisObj = thisObj || null;
while ((matches = regex.exec(str)) !== null) {
matchesContainer.push(matches);
}
i = matchesContainer.length;
if (!i) {
if (arguments.length < 3) {
throw new TypeError('reduce of empty matches array with no initial value');
}
return prev;
}
if (!prev) {
matches = matchesContainer.splice(-1)[0];
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [''].concat(matches.concat(i--, n0)));
}
matchesContainer.reduceRight(function (container, mtches) {
n0 = mtches.splice(0, 1);
prev = cb.apply(thisObj, [prev].concat(mtches.concat(i--, n0)));
return container;
}, matchesContainer);
return prev;
}
}, {
key: "find",
value: function find(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
var regex = mixinRegex(this.regex, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return n0[0];
}
}
return false;
}
}, {
key: "findIndex",
value: function findIndex(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var regex = mixinRegex(this.regex, 'g');
var matches,
i = 0;
while ((matches = regex.exec(str)) !== null) {
var n0 = matches.splice(0, 1);
var ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return i - 1;
}
}
return -1;
}
}, {
key: "findExec",
value: function findExec(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var regex = mixinRegex(this.regex, 'g');
var matches,
i = 0;
while ((matches = regex.exec(str)) !== null) {
var n0 = matches.splice(0, 1);
var ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return matches;
}
}
return false;
}
}, {
key: "filterExec",
value: function filterExec(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [],
regex = mixinRegex(this.regex, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
matches.push(i++, n0[0]);
if (cb.apply(thisObj, matches)) {
ret.push(matches);
}
}
return ret;
}
}]);
return RegExtras;
}();
var _RegExtras = exports.RegExtras;
exports.RegExtras = function RegExtras() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
// eslint-disable-line no-class-assign
return _construct(_RegExtras, args);
};
exports.RegExtras.prototype = _RegExtras.prototype;
exports.RegExtras.mixinRegex = mixinRegex;
/* eslint-disable node/no-unsupported-features/es-syntax */
// We copy the regular expression so as to be able to always
// ensure the exec expression is a global one (and thereby prevent recursion)
/**
*
* @param {RegExtras} RegExtras
* @returns {void}
*/
function addPrototypeMethods(RegExtras) {
RegExtras.prototype.entries = /*#__PURE__*/regeneratorRuntime.mark(function _callee(str) {
var matches, i, regex;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
i = 0;
regex = RegExtras.mixinRegex(this.regex, 'g');
case 2:
if (!((matches = regex.exec(str)) !== null)) {
_context.next = 7;
break;
}
_context.next = 5;
return [i++, matches];
case 5:
_context.next = 2;
break;
case 7:
case "end":
return _context.stop();
}
}
}, _callee, this);
});
RegExtras.prototype.values = /*#__PURE__*/regeneratorRuntime.mark(function _callee2(str) {
var matches, regex;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
regex = RegExtras.mixinRegex(this.regex, 'g');
case 1:
if (!((matches = regex.exec(str)) !== null)) {
_context2.next = 6;
break;
}
_context2.next = 4;
return matches;
case 4:
_context2.next = 1;
break;
case 6:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
});
RegExtras.prototype.keys = /*#__PURE__*/regeneratorRuntime.mark(function _callee3(str) {
var i, regex;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
i = 0;
regex = RegExtras.mixinRegex(this.regex, 'g');
case 2:
if (!(regex.exec(str) !== null)) {
_context3.next = 7;
break;
}
_context3.next = 5;
return i++;
case 5:
_context3.next = 2;
break;
case 7:
case "end":
return _context3.stop();
}
}
}, _callee3, this);
});
}
addPrototypeMethods(exports.RegExtras);
exports.mixinRegex = mixinRegex;
Object.defineProperty(exports, '__esModule', { value: true });
})));
+1
View File
@@ -0,0 +1 @@
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).RegExtras={})}(this,(function(e){"use strict";function n(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function t(e,n){return(t=Object.setPrototypeOf||function(e,n){return e.__proto__=n,e})(e,n)}function r(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function u(e,n,c){return(u=r()?Reflect.construct:function(e,n,r){var u=[null];u.push.apply(u,n);var c=new(Function.bind.apply(e,u));return r&&t(c,r.prototype),c}).apply(null,arguments)}function c(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.lastIndex;return n=n||"",(e=new RegExp(e.source,(n.includes("g")||e.global?"g":"")+(n.includes("i")||e.ignoreCase?"i":"")+(n.includes("m")||e.multiline?"m":"")+(n.includes("u")||e.unicode?"u":"")+(n.includes("y")||e.sticky?"y":"")+(n.includes("s")||e.dotAll?"s":""))).lastIndex=t,e}e.RegExtras=function(){function e(n,t,r){!function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,e),this.regex=c("string"==typeof n?new RegExp(n):c(n),t||"",r)}var t,r,u;return t=e,(r=[{key:"forEach",value:function(e,n){for(var t,r,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=c(this.regex,"g"),l=0;null!==(t=i.exec(e));)r=t.splice(0,1),n.apply(u,t.concat(l++,r));return this}},{key:"some",value:function(e,n){for(var t,r,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=c(this.regex,"g"),l=0;null!==(t=i.exec(e));)if(r=t.splice(0,1),n.apply(u,t.concat(l++,r)))return!0;return!1}},{key:"every",value:function(e,n){for(var t,r,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=c(this.regex,"g"),l=0;null!==(t=i.exec(e));)if(r=t.splice(0,1),!n.apply(u,t.concat(l++,r)))return!1;return!0}},{key:"map",value:function(e,n){for(var t,r,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=[],l=c(this.regex,"g"),o=0;null!==(t=l.exec(e));)r=t.splice(0,1),i.push(n.apply(u,t.concat(o++,r)));return i}},{key:"filter",value:function(e,n){for(var t,r,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=0,l=[],o=c(this.regex,"g");null!==(t=o.exec(e));)r=t.splice(0,1),t=t.concat(i++,r),n.apply(u,t)&&l.push(r[0]);return l}},{key:"reduce",value:function(e,n,t){var r,u,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,l=0,o=c(this.regex,"g");for(t||null!==(r=o.exec(e))&&(u=r.splice(0,1),t=n.apply(i,[""].concat(r.concat(l++,u))));null!==(r=o.exec(e));)u=r.splice(0,1),t=n.apply(i,[t].concat(r.concat(l++,u)));return t}},{key:"reduceRight",value:function(e,n,t,r){var u,i,l,o=r,a=t,s=[],f=c(this.regex,"g");for(o=o||null;null!==(u=f.exec(e));)s.push(u);if(!(l=s.length)){if(arguments.length<3)throw new TypeError("reduce of empty matches array with no initial value");return a}return a||(u=s.splice(-1)[0],i=u.splice(0,1),a=n.apply(o,[""].concat(u.concat(l--,i)))),s.reduceRight((function(e,t){return i=t.splice(0,1),a=n.apply(o,[a].concat(t.concat(l--,i))),e}),s),a}},{key:"find",value:function(e,n){for(var t,r,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=0,l=c(this.regex,"g");null!==(t=l.exec(e));)if(r=t.splice(0,1),n.apply(u,t.concat(i++,r)))return r[0];return!1}},{key:"findIndex",value:function(e,n){for(var t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,u=c(this.regex,"g"),i=0;null!==(t=u.exec(e));){var l=t.splice(0,1),o=n.apply(r,t.concat(i++,l));if(o)return i-1}return-1}},{key:"findExec",value:function(e,n){for(var t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,u=c(this.regex,"g"),i=0;null!==(t=u.exec(e));){var l=t.splice(0,1),o=n.apply(r,t.concat(i++,l));if(o)return t}return!1}},{key:"filterExec",value:function(e,n){for(var t,r,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=0,l=[],o=c(this.regex,"g");null!==(t=o.exec(e));)r=t.splice(0,1),t.push(i++,r[0]),n.apply(u,t)&&l.push(t);return l}}])&&n(t.prototype,r),u&&n(t,u),e}();var i,l=e.RegExtras;e.RegExtras=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return u(l,n)},e.RegExtras.prototype=l.prototype,e.RegExtras.mixinRegex=c,(i=e.RegExtras).prototype.entries=regeneratorRuntime.mark((function e(n){var t,r,u;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=0,u=i.mixinRegex(this.regex,"g");case 2:if(null===(t=u.exec(n))){e.next=7;break}return e.next=5,[r++,t];case 5:e.next=2;break;case 7:case"end":return e.stop()}}),e,this)})),i.prototype.values=regeneratorRuntime.mark((function e(n){var t,r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){cLine truncated
+342
View File
@@ -0,0 +1,342 @@
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;
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _construct(Parent, args, Class) {
if (_isNativeReflectConstruct()) {
_construct = Reflect.construct;
} else {
_construct = function _construct(Parent, args, Class) {
var a = [null];
a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor();
if (Class) _setPrototypeOf(instance, Class.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
/* eslint-disable node/no-unsupported-features/es-syntax */
/**
* @param {RegExp} regex
* @param {string} newFlags
* @param {Integer} [newLastIndex=regex.lastIndex]
* @returns {RegExp}
*/
function mixinRegex(regex, newFlags) {
var newLastIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : regex.lastIndex;
newFlags = newFlags || '';
regex = new RegExp(regex.source, (newFlags.includes('g') ? 'g' : regex.global ? 'g' : '') + (newFlags.includes('i') ? 'i' : regex.ignoreCase ? 'i' : '') + (newFlags.includes('m') ? 'm' : regex.multiline ? 'm' : '') + (newFlags.includes('u') ? 'u' : regex.unicode ? 'u' : '') + (newFlags.includes('y') ? 'y' : regex.sticky ? 'y' : '') + (newFlags.includes('s') ? 's' : regex.dotAll ? 's' : ''));
regex.lastIndex = newLastIndex;
return regex;
}
var RegExtras = /*#__PURE__*/function () {
function RegExtras(regex, flags, newLastIndex) {
_classCallCheck(this, RegExtras);
this.regex = mixinRegex(typeof regex === 'string' ? new RegExp(regex) : mixinRegex(regex), flags || '', newLastIndex);
}
_createClass(RegExtras, [{
key: "forEach",
value: function forEach(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var regex = mixinRegex(this.regex, 'g');
var matches,
n0,
i = 0;
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
cb.apply(thisObj, matches.concat(i++, n0));
}
return this;
}
}, {
key: "some",
value: function some(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var regex = mixinRegex(this.regex, 'g');
var matches,
ret,
n0,
i = 0;
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return true;
}
}
return false;
}
}, {
key: "every",
value: function every(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var regex = mixinRegex(this.regex, 'g');
var matches,
ret,
n0,
i = 0;
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (!ret) {
return false;
}
}
return true;
}
}, {
key: "map",
value: function map(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var ret = [];
var regex = mixinRegex(this.regex, 'g');
var matches,
n0,
i = 0;
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret.push(cb.apply(thisObj, matches.concat(i++, n0)));
}
return ret;
}
}, {
key: "filter",
value: function filter(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [],
regex = mixinRegex(this.regex, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
matches = matches.concat(i++, n0);
if (cb.apply(thisObj, matches)) {
ret.push(n0[0]);
}
}
return ret;
}
}, {
key: "reduce",
value: function reduce(str, cb, prev) {
var thisObj = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
var matches,
n0,
i = 0;
var regex = mixinRegex(this.regex, 'g');
if (!prev) {
if ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [''].concat(matches.concat(i++, n0)));
}
}
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [prev].concat(matches.concat(i++, n0)));
}
return prev;
}
}, {
key: "reduceRight",
value: function reduceRight(str, cb, prevOrig, thisObjOrig) {
var matches,
n0,
i,
thisObj = thisObjOrig,
prev = prevOrig;
var matchesContainer = [],
regex = mixinRegex(this.regex, 'g');
thisObj = thisObj || null;
while ((matches = regex.exec(str)) !== null) {
matchesContainer.push(matches);
}
i = matchesContainer.length;
if (!i) {
if (arguments.length < 3) {
throw new TypeError('reduce of empty matches array with no initial value');
}
return prev;
}
if (!prev) {
matches = matchesContainer.splice(-1)[0];
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [''].concat(matches.concat(i--, n0)));
}
matchesContainer.reduceRight(function (container, mtches) {
n0 = mtches.splice(0, 1);
prev = cb.apply(thisObj, [prev].concat(mtches.concat(i--, n0)));
return container;
}, matchesContainer);
return prev;
}
}, {
key: "find",
value: function find(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
var regex = mixinRegex(this.regex, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return n0[0];
}
}
return false;
}
}, {
key: "findIndex",
value: function findIndex(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var regex = mixinRegex(this.regex, 'g');
var matches,
i = 0;
while ((matches = regex.exec(str)) !== null) {
var n0 = matches.splice(0, 1);
var ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return i - 1;
}
}
return -1;
}
}, {
key: "findExec",
value: function findExec(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var regex = mixinRegex(this.regex, 'g');
var matches,
i = 0;
while ((matches = regex.exec(str)) !== null) {
var n0 = matches.splice(0, 1);
var ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return matches;
}
}
return false;
}
}, {
key: "filterExec",
value: function filterExec(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [],
regex = mixinRegex(this.regex, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
matches.push(i++, n0[0]);
if (cb.apply(thisObj, matches)) {
ret.push(matches);
}
}
return ret;
}
}]);
return RegExtras;
}();
var _RegExtras = RegExtras;
RegExtras = function RegExtras() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
// eslint-disable-line no-class-assign
return _construct(_RegExtras, args);
};
RegExtras.prototype = _RegExtras.prototype;
RegExtras.mixinRegex = mixinRegex;
export { RegExtras, mixinRegex };
+352
View File
@@ -0,0 +1,352 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.RegExtras = {}));
}(this, (function (exports) { 'use strict';
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;
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _construct(Parent, args, Class) {
if (_isNativeReflectConstruct()) {
_construct = Reflect.construct;
} else {
_construct = function _construct(Parent, args, Class) {
var a = [null];
a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor();
if (Class) _setPrototypeOf(instance, Class.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
/* eslint-disable node/no-unsupported-features/es-syntax */
/**
* @param {RegExp} regex
* @param {string} newFlags
* @param {Integer} [newLastIndex=regex.lastIndex]
* @returns {RegExp}
*/
function mixinRegex(regex, newFlags) {
var newLastIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : regex.lastIndex;
newFlags = newFlags || '';
regex = new RegExp(regex.source, (newFlags.includes('g') ? 'g' : regex.global ? 'g' : '') + (newFlags.includes('i') ? 'i' : regex.ignoreCase ? 'i' : '') + (newFlags.includes('m') ? 'm' : regex.multiline ? 'm' : '') + (newFlags.includes('u') ? 'u' : regex.unicode ? 'u' : '') + (newFlags.includes('y') ? 'y' : regex.sticky ? 'y' : '') + (newFlags.includes('s') ? 's' : regex.dotAll ? 's' : ''));
regex.lastIndex = newLastIndex;
return regex;
}
exports.RegExtras = /*#__PURE__*/function () {
function RegExtras(regex, flags, newLastIndex) {
_classCallCheck(this, RegExtras);
this.regex = mixinRegex(typeof regex === 'string' ? new RegExp(regex) : mixinRegex(regex), flags || '', newLastIndex);
}
_createClass(RegExtras, [{
key: "forEach",
value: function forEach(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var regex = mixinRegex(this.regex, 'g');
var matches,
n0,
i = 0;
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
cb.apply(thisObj, matches.concat(i++, n0));
}
return this;
}
}, {
key: "some",
value: function some(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var regex = mixinRegex(this.regex, 'g');
var matches,
ret,
n0,
i = 0;
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return true;
}
}
return false;
}
}, {
key: "every",
value: function every(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var regex = mixinRegex(this.regex, 'g');
var matches,
ret,
n0,
i = 0;
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (!ret) {
return false;
}
}
return true;
}
}, {
key: "map",
value: function map(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var ret = [];
var regex = mixinRegex(this.regex, 'g');
var matches,
n0,
i = 0;
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret.push(cb.apply(thisObj, matches.concat(i++, n0)));
}
return ret;
}
}, {
key: "filter",
value: function filter(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [],
regex = mixinRegex(this.regex, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
matches = matches.concat(i++, n0);
if (cb.apply(thisObj, matches)) {
ret.push(n0[0]);
}
}
return ret;
}
}, {
key: "reduce",
value: function reduce(str, cb, prev) {
var thisObj = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
var matches,
n0,
i = 0;
var regex = mixinRegex(this.regex, 'g');
if (!prev) {
if ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [''].concat(matches.concat(i++, n0)));
}
}
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [prev].concat(matches.concat(i++, n0)));
}
return prev;
}
}, {
key: "reduceRight",
value: function reduceRight(str, cb, prevOrig, thisObjOrig) {
var matches,
n0,
i,
thisObj = thisObjOrig,
prev = prevOrig;
var matchesContainer = [],
regex = mixinRegex(this.regex, 'g');
thisObj = thisObj || null;
while ((matches = regex.exec(str)) !== null) {
matchesContainer.push(matches);
}
i = matchesContainer.length;
if (!i) {
if (arguments.length < 3) {
throw new TypeError('reduce of empty matches array with no initial value');
}
return prev;
}
if (!prev) {
matches = matchesContainer.splice(-1)[0];
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [''].concat(matches.concat(i--, n0)));
}
matchesContainer.reduceRight(function (container, mtches) {
n0 = mtches.splice(0, 1);
prev = cb.apply(thisObj, [prev].concat(mtches.concat(i--, n0)));
return container;
}, matchesContainer);
return prev;
}
}, {
key: "find",
value: function find(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
var regex = mixinRegex(this.regex, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return n0[0];
}
}
return false;
}
}, {
key: "findIndex",
value: function findIndex(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var regex = mixinRegex(this.regex, 'g');
var matches,
i = 0;
while ((matches = regex.exec(str)) !== null) {
var n0 = matches.splice(0, 1);
var ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return i - 1;
}
}
return -1;
}
}, {
key: "findExec",
value: function findExec(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var regex = mixinRegex(this.regex, 'g');
var matches,
i = 0;
while ((matches = regex.exec(str)) !== null) {
var n0 = matches.splice(0, 1);
var ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return matches;
}
}
return false;
}
}, {
key: "filterExec",
value: function filterExec(str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [],
regex = mixinRegex(this.regex, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
matches.push(i++, n0[0]);
if (cb.apply(thisObj, matches)) {
ret.push(matches);
}
}
return ret;
}
}]);
return RegExtras;
}();
var _RegExtras = exports.RegExtras;
exports.RegExtras = function RegExtras() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
// eslint-disable-line no-class-assign
return _construct(_RegExtras, args);
};
exports.RegExtras.prototype = _RegExtras.prototype;
exports.RegExtras.mixinRegex = mixinRegex;
exports.mixinRegex = mixinRegex;
Object.defineProperty(exports, '__esModule', { value: true });
})));
+170
View File
@@ -0,0 +1,170 @@
/* eslint-disable node/no-unsupported-features/es-syntax */
/**
* @param {RegExp} regex
* @param {string} newFlags
* @param {Integer} [newLastIndex=regex.lastIndex]
* @returns {RegExp}
*/
function mixinRegex(regex, newFlags) {
var newLastIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : regex.lastIndex;
newFlags = newFlags || '';
regex = new RegExp(regex.source, (newFlags.includes('g') ? 'g' : regex.global ? 'g' : '') + (newFlags.includes('i') ? 'i' : regex.ignoreCase ? 'i' : '') + (newFlags.includes('m') ? 'm' : regex.multiline ? 'm' : '') + (newFlags.includes('u') ? 'u' : regex.unicode ? 'u' : '') + (newFlags.includes('y') ? 'y' : regex.sticky ? 'y' : '') + (newFlags.includes('s') ? 's' : regex.dotAll ? 's' : ''));
regex.lastIndex = newLastIndex;
return regex;
}
/* eslint-disable no-extend-native,
no-use-extend-native/no-use-extend-native,
node/no-unsupported-features/es-syntax */
RegExp.prototype.forEach = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
cb.apply(thisObj, matches.concat(i++, n0));
}
return this;
};
RegExp.prototype.some = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return true;
}
}
return false;
};
RegExp.prototype.every = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (!ret) {
return false;
}
}
return true;
};
RegExp.prototype.map = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [];
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret.push(cb.apply(thisObj, matches.concat(i++, n0)));
}
return ret;
};
RegExp.prototype.filter = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [];
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
matches = matches.concat(i++, n0);
if (cb.apply(thisObj, matches)) {
ret.push(matches[0]);
}
}
return ret;
};
RegExp.prototype.reduce = function (str, cb, prev) {
var thisObj = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
var matches,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
if (!prev) {
if ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [''].concat(matches.concat(n0, i++)));
}
}
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [prev].concat(matches.concat(n0, i++)));
}
return prev;
};
RegExp.prototype.reduceRight = function (str, cb, prevOrig, thisObjOrig) {
var matches,
n0,
i,
prev = prevOrig,
thisObj = thisObjOrig;
var regex = mixinRegex(this, 'g');
var matchesContainer = [];
thisObj = thisObj || null;
while ((matches = regex.exec(str)) !== null) {
matchesContainer.push(matches);
}
i = matchesContainer.length;
if (!i) {
if (arguments.length < 3) {
throw new TypeError('reduce of empty matches array with no initial value');
}
return prev;
}
if (!prev) {
matches = matchesContainer.splice(-1)[0];
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [''].concat(matches.concat(n0, i--)));
}
matchesContainer.reduceRight(function (container, mtches) {
n0 = mtches.splice(0, 1);
prev = cb.apply(thisObj, [prev].concat(mtches.concat(n0, i--)));
return container;
}, matchesContainer);
return prev;
};
+177
View File
@@ -0,0 +1,177 @@
(function (factory) {
typeof define === 'function' && define.amd ? define(factory) :
factory();
}((function () { 'use strict';
/* eslint-disable node/no-unsupported-features/es-syntax */
/**
* @param {RegExp} regex
* @param {string} newFlags
* @param {Integer} [newLastIndex=regex.lastIndex]
* @returns {RegExp}
*/
function mixinRegex(regex, newFlags) {
var newLastIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : regex.lastIndex;
newFlags = newFlags || '';
regex = new RegExp(regex.source, (newFlags.includes('g') ? 'g' : regex.global ? 'g' : '') + (newFlags.includes('i') ? 'i' : regex.ignoreCase ? 'i' : '') + (newFlags.includes('m') ? 'm' : regex.multiline ? 'm' : '') + (newFlags.includes('u') ? 'u' : regex.unicode ? 'u' : '') + (newFlags.includes('y') ? 'y' : regex.sticky ? 'y' : '') + (newFlags.includes('s') ? 's' : regex.dotAll ? 's' : ''));
regex.lastIndex = newLastIndex;
return regex;
}
/* eslint-disable no-extend-native,
no-use-extend-native/no-use-extend-native,
node/no-unsupported-features/es-syntax */
RegExp.prototype.forEach = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
cb.apply(thisObj, matches.concat(i++, n0));
}
return this;
};
RegExp.prototype.some = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return true;
}
}
return false;
};
RegExp.prototype.every = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (!ret) {
return false;
}
}
return true;
};
RegExp.prototype.map = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [];
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret.push(cb.apply(thisObj, matches.concat(i++, n0)));
}
return ret;
};
RegExp.prototype.filter = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [];
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
matches = matches.concat(i++, n0);
if (cb.apply(thisObj, matches)) {
ret.push(matches[0]);
}
}
return ret;
};
RegExp.prototype.reduce = function (str, cb, prev) {
var thisObj = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
var matches,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
if (!prev) {
if ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [''].concat(matches.concat(n0, i++)));
}
}
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [prev].concat(matches.concat(n0, i++)));
}
return prev;
};
RegExp.prototype.reduceRight = function (str, cb, prevOrig, thisObjOrig) {
var matches,
n0,
i,
prev = prevOrig,
thisObj = thisObjOrig;
var regex = mixinRegex(this, 'g');
var matchesContainer = [];
thisObj = thisObj || null;
while ((matches = regex.exec(str)) !== null) {
matchesContainer.push(matches);
}
i = matchesContainer.length;
if (!i) {
if (arguments.length < 3) {
throw new TypeError('reduce of empty matches array with no initial value');
}
return prev;
}
if (!prev) {
matches = matchesContainer.splice(-1)[0];
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [''].concat(matches.concat(n0, i--)));
}
matchesContainer.reduceRight(function (container, mtches) {
n0 = mtches.splice(0, 1);
prev = cb.apply(thisObj, [prev].concat(mtches.concat(n0, i--)));
return container;
}, matchesContainer);
return prev;
};
})));
+250
View File
@@ -0,0 +1,250 @@
/* eslint-disable node/no-unsupported-features/es-syntax */
/**
* @param {RegExp} regex
* @param {string} newFlags
* @param {Integer} [newLastIndex=regex.lastIndex]
* @returns {RegExp}
*/
function mixinRegex(regex, newFlags) {
var newLastIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : regex.lastIndex;
newFlags = newFlags || '';
regex = new RegExp(regex.source, (newFlags.includes('g') ? 'g' : regex.global ? 'g' : '') + (newFlags.includes('i') ? 'i' : regex.ignoreCase ? 'i' : '') + (newFlags.includes('m') ? 'm' : regex.multiline ? 'm' : '') + (newFlags.includes('u') ? 'u' : regex.unicode ? 'u' : '') + (newFlags.includes('y') ? 'y' : regex.sticky ? 'y' : '') + (newFlags.includes('s') ? 's' : regex.dotAll ? 's' : ''));
regex.lastIndex = newLastIndex;
return regex;
}
/* eslint-disable no-extend-native,
no-use-extend-native/no-use-extend-native,
node/no-unsupported-features/es-syntax */
RegExp.prototype.forEach = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
cb.apply(thisObj, matches.concat(i++, n0));
}
return this;
};
RegExp.prototype.some = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return true;
}
}
return false;
};
RegExp.prototype.every = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (!ret) {
return false;
}
}
return true;
};
RegExp.prototype.map = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [];
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret.push(cb.apply(thisObj, matches.concat(i++, n0)));
}
return ret;
};
RegExp.prototype.filter = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [];
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
matches = matches.concat(i++, n0);
if (cb.apply(thisObj, matches)) {
ret.push(n0[0]);
}
}
return ret;
};
RegExp.prototype.reduce = function (str, cb, prev) {
var thisObj = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
var matches,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
if (!prev) {
if ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [''].concat(matches.concat(i++, n0)));
}
}
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [prev].concat(matches.concat(i++, n0)));
}
return prev;
};
RegExp.prototype.reduceRight = function (str, cb, prevOrig, thisObjOrig) {
var matches,
n0,
i,
prev = prevOrig,
thisObj = thisObjOrig;
var regex = mixinRegex(this, 'g');
var matchesContainer = [];
thisObj = thisObj || null;
while ((matches = regex.exec(str)) !== null) {
matchesContainer.push(matches);
}
i = matchesContainer.length;
if (!i) {
if (arguments.length < 3) {
throw new TypeError('reduce of empty matches array with no initial value');
}
return prev;
}
if (!prev) {
matches = matchesContainer.splice(-1)[0];
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [''].concat(matches.concat(i--, n0)));
}
matchesContainer.reduceRight(function (container, mtches) {
n0 = mtches.splice(0, 1);
prev = cb.apply(thisObj, [prev].concat(mtches.concat(i--, n0)));
return container;
}, matchesContainer);
return prev;
};
RegExp.prototype.find = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return n0[0];
}
}
return false;
};
RegExp.prototype.findIndex = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return i - 1;
}
}
return -1;
};
RegExp.prototype.findExec = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return matches;
}
}
return false;
};
RegExp.prototype.filterExec = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [],
regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
matches.push(i++, n0[0]);
if (cb.apply(thisObj, matches)) {
ret.push(matches);
}
}
return ret;
};
+257
View File
@@ -0,0 +1,257 @@
(function (factory) {
typeof define === 'function' && define.amd ? define(factory) :
factory();
}((function () { 'use strict';
/* eslint-disable node/no-unsupported-features/es-syntax */
/**
* @param {RegExp} regex
* @param {string} newFlags
* @param {Integer} [newLastIndex=regex.lastIndex]
* @returns {RegExp}
*/
function mixinRegex(regex, newFlags) {
var newLastIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : regex.lastIndex;
newFlags = newFlags || '';
regex = new RegExp(regex.source, (newFlags.includes('g') ? 'g' : regex.global ? 'g' : '') + (newFlags.includes('i') ? 'i' : regex.ignoreCase ? 'i' : '') + (newFlags.includes('m') ? 'm' : regex.multiline ? 'm' : '') + (newFlags.includes('u') ? 'u' : regex.unicode ? 'u' : '') + (newFlags.includes('y') ? 'y' : regex.sticky ? 'y' : '') + (newFlags.includes('s') ? 's' : regex.dotAll ? 's' : ''));
regex.lastIndex = newLastIndex;
return regex;
}
/* eslint-disable no-extend-native,
no-use-extend-native/no-use-extend-native,
node/no-unsupported-features/es-syntax */
RegExp.prototype.forEach = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
cb.apply(thisObj, matches.concat(i++, n0));
}
return this;
};
RegExp.prototype.some = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return true;
}
}
return false;
};
RegExp.prototype.every = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (!ret) {
return false;
}
}
return true;
};
RegExp.prototype.map = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [];
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret.push(cb.apply(thisObj, matches.concat(i++, n0)));
}
return ret;
};
RegExp.prototype.filter = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [];
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
matches = matches.concat(i++, n0);
if (cb.apply(thisObj, matches)) {
ret.push(n0[0]);
}
}
return ret;
};
RegExp.prototype.reduce = function (str, cb, prev) {
var thisObj = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
var matches,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
if (!prev) {
if ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [''].concat(matches.concat(i++, n0)));
}
}
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [prev].concat(matches.concat(i++, n0)));
}
return prev;
};
RegExp.prototype.reduceRight = function (str, cb, prevOrig, thisObjOrig) {
var matches,
n0,
i,
prev = prevOrig,
thisObj = thisObjOrig;
var regex = mixinRegex(this, 'g');
var matchesContainer = [];
thisObj = thisObj || null;
while ((matches = regex.exec(str)) !== null) {
matchesContainer.push(matches);
}
i = matchesContainer.length;
if (!i) {
if (arguments.length < 3) {
throw new TypeError('reduce of empty matches array with no initial value');
}
return prev;
}
if (!prev) {
matches = matchesContainer.splice(-1)[0];
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [''].concat(matches.concat(i--, n0)));
}
matchesContainer.reduceRight(function (container, mtches) {
n0 = mtches.splice(0, 1);
prev = cb.apply(thisObj, [prev].concat(mtches.concat(i--, n0)));
return container;
}, matchesContainer);
return prev;
};
RegExp.prototype.find = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return n0[0];
}
}
return false;
};
RegExp.prototype.findIndex = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return i - 1;
}
}
return -1;
};
RegExp.prototype.findExec = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
var regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return matches;
}
}
return false;
};
RegExp.prototype.filterExec = function (str, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [],
regex = mixinRegex(this, 'g');
while ((matches = regex.exec(str)) !== null) {
n0 = matches.splice(0, 1);
matches.push(i++, n0[0]);
if (cb.apply(thisObj, matches)) {
ret.push(matches);
}
}
return ret;
};
})));
+248
View File
@@ -0,0 +1,248 @@
/* eslint-disable node/no-unsupported-features/es-syntax */
/**
* @param {RegExp} regex
* @param {string} newFlags
* @param {Integer} [newLastIndex=regex.lastIndex]
* @returns {RegExp}
*/
function mixinRegex(regex, newFlags) {
var newLastIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : regex.lastIndex;
newFlags = newFlags || '';
regex = new RegExp(regex.source, (newFlags.includes('g') ? 'g' : regex.global ? 'g' : '') + (newFlags.includes('i') ? 'i' : regex.ignoreCase ? 'i' : '') + (newFlags.includes('m') ? 'm' : regex.multiline ? 'm' : '') + (newFlags.includes('u') ? 'u' : regex.unicode ? 'u' : '') + (newFlags.includes('y') ? 'y' : regex.sticky ? 'y' : '') + (newFlags.includes('s') ? 's' : regex.dotAll ? 's' : ''));
regex.lastIndex = newLastIndex;
return regex;
}
// We copy the regular expression so as to be able to always ensure the exec
String.prototype.forEach = function (regex, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
regex = mixinRegex(regex, 'g');
while ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
cb.apply(thisObj, matches.concat(i++, n0));
}
return this;
};
String.prototype.some = function (regex, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
regex = mixinRegex(regex, 'g');
while ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return true;
}
}
return false;
};
String.prototype.every = function (regex, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
regex = mixinRegex(regex, 'g');
while ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (!ret) {
return false;
}
}
return true;
};
String.prototype.map = function (regex, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [];
regex = mixinRegex(regex, 'g');
while ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
ret.push(cb.apply(thisObj, matches.concat(i++, n0)));
}
return ret;
};
String.prototype.filter = function (regex, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [];
regex = mixinRegex(regex, 'g');
while ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
matches = matches.concat(i++, n0);
if (cb.apply(thisObj, matches)) {
ret.push(n0[0]);
}
}
return ret;
};
String.prototype.reduce = function (regex, cb, prev) {
var thisObj = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
var matches,
n0,
i = 0;
regex = mixinRegex(regex, 'g');
if (!prev) {
if ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [''].concat(matches.concat(i++, n0)));
}
}
while ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [prev].concat(matches.concat(i++, n0)));
}
return prev;
};
String.prototype.reduceRight = function (regex, cb, prevOrig, thisObjOrig) {
var matches,
n0,
i,
prev = prevOrig,
thisObj = thisObjOrig;
var matchesContainer = [];
regex = mixinRegex(regex, 'g');
thisObj = thisObj || null;
while ((matches = regex.exec(this)) !== null) {
matchesContainer.push(matches);
}
i = matchesContainer.length;
if (!i) {
if (arguments.length < 3) {
throw new TypeError('reduce of empty matches array with no initial value');
}
return prev;
}
if (!prev) {
matches = matchesContainer.splice(-1)[0];
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [''].concat(matches.concat(i--, n0)));
}
matchesContainer.reduceRight(function (container, mtches) {
n0 = mtches.splice(0, 1);
prev = cb.apply(thisObj, [prev].concat(mtches.concat(i--, n0)));
return container;
}, matchesContainer);
return prev;
};
String.prototype.find = function (regex, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
regex = mixinRegex(regex, 'g');
while ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return n0[0];
}
}
return false;
};
String.prototype.findIndex = function (regex, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
regex = mixinRegex(regex, 'g');
while ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return i - 1;
}
}
return -1;
};
String.prototype.findExec = function (regex, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
regex = mixinRegex(regex, 'g');
while ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return matches;
}
}
return false;
};
String.prototype.filterExec = function (regex, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [];
regex = mixinRegex(regex, 'g');
while ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
matches.push(i++, n0[0]);
if (cb.apply(thisObj, matches)) {
ret.push(matches);
}
}
return ret;
};
+255
View File
@@ -0,0 +1,255 @@
(function (factory) {
typeof define === 'function' && define.amd ? define(factory) :
factory();
}((function () { 'use strict';
/* eslint-disable node/no-unsupported-features/es-syntax */
/**
* @param {RegExp} regex
* @param {string} newFlags
* @param {Integer} [newLastIndex=regex.lastIndex]
* @returns {RegExp}
*/
function mixinRegex(regex, newFlags) {
var newLastIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : regex.lastIndex;
newFlags = newFlags || '';
regex = new RegExp(regex.source, (newFlags.includes('g') ? 'g' : regex.global ? 'g' : '') + (newFlags.includes('i') ? 'i' : regex.ignoreCase ? 'i' : '') + (newFlags.includes('m') ? 'm' : regex.multiline ? 'm' : '') + (newFlags.includes('u') ? 'u' : regex.unicode ? 'u' : '') + (newFlags.includes('y') ? 'y' : regex.sticky ? 'y' : '') + (newFlags.includes('s') ? 's' : regex.dotAll ? 's' : ''));
regex.lastIndex = newLastIndex;
return regex;
}
// We copy the regular expression so as to be able to always ensure the exec
String.prototype.forEach = function (regex, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
regex = mixinRegex(regex, 'g');
while ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
cb.apply(thisObj, matches.concat(i++, n0));
}
return this;
};
String.prototype.some = function (regex, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
regex = mixinRegex(regex, 'g');
while ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return true;
}
}
return false;
};
String.prototype.every = function (regex, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
regex = mixinRegex(regex, 'g');
while ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (!ret) {
return false;
}
}
return true;
};
String.prototype.map = function (regex, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [];
regex = mixinRegex(regex, 'g');
while ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
ret.push(cb.apply(thisObj, matches.concat(i++, n0)));
}
return ret;
};
String.prototype.filter = function (regex, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [];
regex = mixinRegex(regex, 'g');
while ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
matches = matches.concat(i++, n0);
if (cb.apply(thisObj, matches)) {
ret.push(n0[0]);
}
}
return ret;
};
String.prototype.reduce = function (regex, cb, prev) {
var thisObj = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
var matches,
n0,
i = 0;
regex = mixinRegex(regex, 'g');
if (!prev) {
if ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [''].concat(matches.concat(i++, n0)));
}
}
while ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [prev].concat(matches.concat(i++, n0)));
}
return prev;
};
String.prototype.reduceRight = function (regex, cb, prevOrig, thisObjOrig) {
var matches,
n0,
i,
prev = prevOrig,
thisObj = thisObjOrig;
var matchesContainer = [];
regex = mixinRegex(regex, 'g');
thisObj = thisObj || null;
while ((matches = regex.exec(this)) !== null) {
matchesContainer.push(matches);
}
i = matchesContainer.length;
if (!i) {
if (arguments.length < 3) {
throw new TypeError('reduce of empty matches array with no initial value');
}
return prev;
}
if (!prev) {
matches = matchesContainer.splice(-1)[0];
n0 = matches.splice(0, 1);
prev = cb.apply(thisObj, [''].concat(matches.concat(i--, n0)));
}
matchesContainer.reduceRight(function (container, mtches) {
n0 = mtches.splice(0, 1);
prev = cb.apply(thisObj, [prev].concat(mtches.concat(i--, n0)));
return container;
}, matchesContainer);
return prev;
};
String.prototype.find = function (regex, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
regex = mixinRegex(regex, 'g');
while ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return n0[0];
}
}
return false;
};
String.prototype.findIndex = function (regex, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
regex = mixinRegex(regex, 'g');
while ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return i - 1;
}
}
return -1;
};
String.prototype.findExec = function (regex, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
ret,
n0,
i = 0;
regex = mixinRegex(regex, 'g');
while ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
ret = cb.apply(thisObj, matches.concat(i++, n0));
if (ret) {
return matches;
}
}
return false;
};
String.prototype.filterExec = function (regex, cb) {
var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var matches,
n0,
i = 0;
var ret = [];
regex = mixinRegex(regex, 'g');
while ((matches = regex.exec(this)) !== null) {
n0 = matches.splice(0, 1);
matches.push(i++, n0[0]);
if (cb.apply(thisObj, matches)) {
ret.push(matches);
}
}
return ret;
};
})));