-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroxp.min.js
1 lines (1 loc) · 3.79 KB
/
roxp.min.js
1
"use strict";!function(r,e){var v=["<",">","<=",">=","=","times","inRange","onceOrNever","onceOrMore","zeroOrMore","lazy","group","mustNotMatch","repeatMatch","eitherOne","prefixGroups"],t={letter:"\\w",digit:"\\d",space:"\\s",wordBoundary:"\\b",bound:"\\b",notLetter:"\\W",notDigit:"\\D",notSpace:"\\S",notWordBoundary:"\\B",notBound:"\\B",start:"^",end:"$",anything:".",any:".",tab:"\\t",newLine:"\\n",lf:"\\n",cr:"\\r",feed:"\\f",dot:"\\.","\\":"\\\\",".":"\\.",$:"\\$","^":"\\^","|":"\\|","?":"\\?","*":"\\*","+":"\\+","(":"\\(",")":"\\)","{":"\\{","}":"\\}","[":"\\[","]":"\\]"},o={};function n(){return new a(arguments)}function a(r,e){var t=function p(f){var r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};var g=[];var l=[];var h={};var e=function(r){var e=f[r],t=x(f[r+1])&&!y(f[r+1])?f[++r]:{};!function(r){for(var e in r)if(!~v.indexOf(e))throw TypeError("'"+e+"' isn't a valid option to pass into Roxp constructor")}(t);var n=function(r){if(y(r))return"instance";if(d(r)&&d(r[0])&&1===r.length)return"grouping";if(d(r)&&x(r[0])&&1===r.length)return"backreference";if(d(r))return"characterSet";return"string"}(e),o="",a={};switch(n){case"grouping":a=p(e[0],t),o=a.regExpStr;break;case"instance":a={groups:e.groups.slice()},o=e.regExpStr;break;case"backreference":var c=e[0].repeatMatch,i="UNIQUE_STR_ID_PREFIX_YOURE_SUPPOSED_TO_NEVER_MEET_"+c+"_"+Date.now();o=i,h[c]=i;break;case"characterSet":o="["+(t.mustNotMatch?"^":"")+e.join("")+"]";break;default:o=e}var s,u=function(r){var e=["{",null,",",null,"}"],t="";for(var n in r){var o=r[n];switch(n){case">":e[1]=++o;break;case"<":e[3]=--o;break;case">=":e[1]=o;break;case"<=":e[3]=o;break;case"=":case"times":e[1]=e[3]=o;break;case"inRange":e[1]=o[0],e[3]=o[1];break;case"onceOrNever":e[1]=e[3]=null,t="?";break;case"onceOrMore":e[1]=e[3]=null,t="+";break;case"zeroOrMore":e[1]=e[3]=null,t="*"}"lazy"===o&&(t+="?")}var a=e[1]||e[3]?e.join(""):t;r.lazy&&(a+="?");return a}(t);t.mustNotMatch&&"characterSet"!==n?o="(?!"+o+")":t.group?(o="("+o+")",l.push(t.group)):(u&&"grouping"===n||u&&"string"===n&&(2!==(s=o).length||0!==s.indexOf("\\"))&&1<o.length)&&(o="(?:"+o+")"),o+=u,g.push(o),a.groups&&(t.prefixGroups&&(a.groups=a.groups.map(function(r){return t.prefixGroups+((e=r)[0].toUpperCase()+e.substr(1));var e})),l.splice.apply(l,[l.length,0].concat(a.groups))),a.backreferences&&Object.assign(h,a.backreferences),b=r};for(var b=0;b<f.length;b++)e(b);var t=r.eitherOne?"|":"";return{regExpStr:g.join(t),groups:l,backreferences:h}}(r);this.groups=t.groups,this.backreferences=t.backreferences,this.regExpStr=function(r,e,t){for(var n in t){var o=e.indexOf(n)+1;if(!o)throw Error("Trying to setup a backreference to not existing group '"+n+"'");r=r.replace(t[n],"\\"+o)}return r}(t.regExpStr,t.groups,t.backreferences);var n=e||function(r){var e="";for(var t in r)r[t]&&(e+=t);return e}(o);this.regExp=new RegExp(this.regExpStr,n)}function d(r){return"[object Array]"===Object.prototype.toString.call(r)}function x(r){return"[object Object]"===Object.prototype.toString.call(r)}function y(r){return r instanceof a}function c(t,n){var o={};return t.forEach(function(r,e){n[e+1]&&(o[t[e]]=n[e+1])}),o}n.specialCharacters=function(){return t},n.setFlagsGlobally=function(r){return Object.assign(o,r)},n.withFlags=function(r){return function(){return new a(arguments,r)}},e?r.exports=n:r.Roxp=n,a.prototype.test=a.prototype.check=function(r){return this.regExp.test(r)},a.prototype.find=a.prototype.exec=a.prototype.search=function(r){var e=this.regExp.exec(r);return e&&Object.assign(e,c(this.groups,e)),e},a.prototype.replace=function(e,t){var n=this;return e.replace(this.regExp,function(){var r=Array.prototype.slice.call(arguments,0,-2);return Object.assign(r,c(n.groups,r),{index:arguments[arguments.length-2],input:e}),t.call(this,r)})}}("undefined"!=typeof module?module:window,"undefined"!=typeof module);