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

compose-regexp

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

compose-regexp - npm Package Compare versions

Comparing version 0.7.0 to 0.7.1

6

CHANGELOG.md
# Change Log
## v0.7.1
*2023-03-19*
- Fix the error message for lone quantifier brackets
## v0.7.0

@@ -4,0 +10,0 @@

2

commonjs/compose-regexp.js

@@ -439,3 +439,3 @@ (function (global, factory) {

else if (result[1] === ']') continue
else return true
else return result[1]
}

@@ -442,0 +442,0 @@ }

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

!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define("compose-regexp",["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).composeRegexp={})}(this,(function(n){"use strict";const e=[];"dgimsuy".split("").forEach((function(n){try{new RegExp("",n),e.push(n)}catch(n){}}));const t=-1!==e.indexOf("u"),r=(()=>{try{return new RegExp("(?<=)"),!0}catch(n){return!1}})(),u={}.hasOwnProperty;function o(n){return n}const i=[].map,c=RegExp;function s(n){return-1===n.indexOf("\\")?n:JSON.parse('"'+n.replace(/$|"|\\x([\dA-Fa-f]{2})|\\u\{([\dA-Fa-f]{1,6})\}/g,(function(n,e,t){return""===n?'"':'"'===n?'\\"':String.fromCodePoint(parseInt(e||t,16))})))}const f={value:void 0,writable:!1,enumerable:!1,configurable:!1};function l(){return"_"+Math.floor(Math.random()*Math.pow(2,32)).toString(36)}const a="undefined"!=typeof WeakMap?new WeakMap:{key:"__$$__compose_regexp__$$__"+l()+l()+l()+l(),set:function(n,e){const t=typeof n;if(null==n||"object"!==t&&"function"!==t)throw new TypeError("Bad WeakMap key");const r=n[a.key];if(!r)return f.value={keys:[this],values:[e]},Object.defineProperty(n,a.key,f),this;const u=r.keys.indexOf(this);return 0===u?(r.keys.push(this),r.values.push(e),this):(r.values[u]=e,this)},get:function(n){const e=n[a.key];if(e){const n=e.keys.indexOf(this);if(-1!==n)return e.values[n]}}},d=/\\[^]|\(\?(?::|<?[=!])|[\[\](]/g,p=/\\.|\.|\(\?:\^\|\(\?<=\[\\n\\r\\u2028\\u2029\]\)\)|\(\?:\$\|\(\?=\[\\n\\r\\u2028\\u2029\]\)\)|\[|\]|\^|\$/g,g=t&&new RegExp("^[_$\\p{ID_Start}][$\\p{ID_Continue}]*$","u"),h=/\\.|\{\d+(?:,\d*)?\}|(\[|\]|\{|\})/g,y=/(?:$|(?=[\n\r\u2028\u2029]))/,x=/(?:^|(?<=[\n\r\u2028\u2029]))/,k=/\\[^1-9]|[\[\]]|\\(\d{1,2})|\$d:(\d+),n:(\d+)\^/g,w=/^(?:\\.|\[(?:[^\]\\]|\\.)*\])$/,$=/^\\p\{[A-Za-z][A-Za-z=]*\}$/,m=/[.?*+^$[\]\\(){}|]/g,E=/^(?:[+*?]|\{(\d+)(?:,(\d*))?\})\??$/,b=/(\\.)|[-()|\[\]]((?=\?<?[=!]))?/g,R=/\\u[0-9A-Fa-f]{4}|\\x[0-9A-Fa-f]{2}|\\c[A-Za-z]|\\([^.?*+^$[\]\\(){}|\/DSWdswfnrtv-])|(\\[DSWdsw]-[^\]]|.-\\[DSWdsw])|\\.|\]/g,S=/\\u[0-9A-Fa-f]{4}|\\x[0-9A-Fa-f]{2}|\\c[A-Za-z]|\\k<(.*?)>|\\([^.?*+^$[\]\\(){}|\/DSWdswBbfnrtv])|\\.|\.|\[\^\]|\[|(\((?:\?[^])?)|(\)(?:[+?*]|\{\d+,?\d*\})?)/g;function A(n){if(n instanceof c){let e=a.get(n);return null==e&&a.set(n,e={captureCount:null,direction:0,hasRefs:null,hasFinalRef:null,isDisjunction:null,isOneGroupOrAssertion:null,source:null,unicode:null}),e}return n||{captureCount:null,direction:0,hasRefs:null,hasFinalRef:null,isDisjunction:null,isOneGroupOrAssertion:null,source:null,unicode:null}}const O=function(n,e,t){const r=A(n);return"object"==typeof e?Object.assign(r,e):r[e]=t},I=function(n,e){return A(n)[e]};function j(n,e){return Object.defineProperty((function(t){const r=I(t.key,n);return null!=r?r:O(t.key,n,e(t))}),"name",{value:n})}const B=[];const F=j("captureCount",(function(n){let e,t=0;for(d.lastIndex=0;e=d.exec(n.source);)"("===e[0]&&(t+=1);return t})),v=j("hasRefs",(function(n){let e,t=!1,r=!1,u=!1;for(k.lastIndex=0;e=k.exec(n.source);)u||null==e[1]&&null==e[2]?"["===e[0]?u=!0:"]"===e[0]&&(u=!1):(t=!0,k.lastIndex===n.source.length&&(r=!0));return O(n.key,"hasFinalRef",r),t})),C=j("isDisjunction",(function(n){if(-1===n.source.indexOf("|"))return!1;let e,t=0,r=!1;for(b.lastIndex=0;e=b.exec(n.source);)if(null==e[1]&&(r||"("!==e[0]||t++,r||")"!==e[0]||t--,r||"["!==e[0]&&"[-"!==e[0]||(r=!0),r&&"]"===e[0]&&(r=!1),0===t&&!r&&"|"===e[0]))return!0;return!1})),_=j("isOneGroupOrAssertion",(function(n){const e=n.source;if("("!==e.charAt(0)||")"!==e.charAt(e.length-1))return!1;let t,r=0,u=!1;for(b.lastIndex=0;t=b.exec(e);)if(null==t[1]){if(u||"("!==t[0]||r++,!u&&")"===t[0]&&(r--,0===r&&t.index!==e.length-1))return!1;u||"["!==t[0]&&"[-"!==t||(u=!0),u&&"]"===t[0]&&(u=!1)}else if(t.index===e.length-2)return!1;return!0}));function M(n){const e=n.source;if(null==e||"^"===e||"$"===e||"\\b"===e||"\\B"===e)throw new SyntaxError(`Nothing to repeat: / ${e||"(?:)"}/`);if(1===e.length||w.test(e)||z.U&&$.test(e))return!1;if(!_(n))return!0;if(/^\(\?<?[!=]/.test(e))throw new SyntaxError(`Nothing to repeat: /${e}/`);return!1}const D=j("hasLoneQuantifierBracket",(function(n){let e,t=!1;for(h.lastIndex=0;e=h.exec(n.source);)if(null!=e[1])if(t)"]"===e[1]&&(t=!1);else{if("["!==e[1]){if("]"===e[1])continue;return!0}t=!0}return!1}));function U(n){const e=n.source;if(z.U&&("regexp"===n.kind&&!n.key.unicode||"result"===n.kind&&!I(n.key,"unicode"))){if(function(n){let e,t=S;function r(n){n.lastIndex=t.lastIndex,t=n}for(B.length=0,S.lastIndex=0;e=t.exec(n);)if(t===S)if("["===e[0])r(R);else{if("."===e[0]||"[^]"===e[0]||null!=e[1]&&!g.test(s(e[1]))||null!=e[2])return!0;if(null!=e[3])B.unshift(e[3]);else if(null!=e[4]){if(("(?="===B[0]||"(?!"===B[0])&&")"!==e[4])return!0;B.shift()}}else if("]"===e[0])r(S);else if(null!=e[1]||null!=e[2])return!0;return!1}(e))throw new SyntaxError(`Can't upgrade the RegExp to Unicode /${e}/${"regexp"===n.kind?n.key.flags:""}`);n.source=function(n){let e=!1;return n.replace(h,(function(n,t){if("]"===n){if(!e)return"\\]";e=!1}else if(!e&&null!=t){if("["!==t)return"\\"+t;e=!0}return n}))}(e)}let t=!1;return"regexp"===n.kind&&(n.key.dotAll||n.key.multiline)&&(n.source=e.replace(p,(function(e){return t?("]"===e&&(t=!1),e):("["===e&&(t=!0),n.key.dotAll&&"."===e?"[^]":n.key.multiline&&"^"===e&&r?x.source:n.key.multiline&&"$"===e&&r?y.source:e)}))),n}const N=new RegExp(`^(?:([${e.join("")}])(?!.*\\1))*$`),T=new RegExp(`[${e.join()}]`,"g");const W={"-1":"backward",1:"forward"};let z,P,Z={current:1};function q(){P={hasRefs:!1,hasFinalRef:!1,captureCount:0},z={U:!1,I:null,M:null}}function G(n,e){return e.condition&&!e.condition(n)||(n.source=e.open+(n.source||"")+")"),e.suffix&&(n.source+=e.suffix),n}function L(n){return G(n,{condition:function(n){return("regexp"===n.kind||"result"===n.kind)&&C(n)},open:"(?:"})}function J(n,e,t,u){return t=t||n.length>1,i.call(n,(function n(u){return(!e&&t?L:o)(Array.isArray(u)?J(u,!1,t,0):"function"==typeof u?n(function(n){const e=P,t=z;try{return n()}finally{P=e,z=t}}(u)):u instanceof c?function(n){if(null==n||"regexp"!==n.kind||n.key.unicode)return n;const e=D(n);if(!1===e)return n;throw new SyntaxError(`Lone quantifier bracket ${e} in /${n.source}/${n.key.flags}`)}(function(n){const e=I(n.key,"direction");if(e*Z.current==-1)throw new TypeError(`Illegal ${W[e]} RegExp argument while building a ${W[Z.current]} one: /${n.source}/`);return 0!==e&&(P.hasRefs=!0),n}(function(n){const e=n.key.flags;if(!N.test(e))throw new TypeError(`Unkown flag(s): ${e.replace(T,"")}`);const t=!!n.key.unicode,u=n.key.ignoreCase,o=n.key.multiline;if(null!=z.I&&u!==z.I)throw new SyntaxError("Can't combine i and non-i regexps: "+n.key);if(!r&&null!=z.M&&o!==z.M)throw new SyntaxError("Can't combine m and non-m regexps: "+n.key);return z.I=u,z.M=o,z.U=z.U||t,n}({key:u,kind:"regexp",source:(i=u,I(i,"source")||O(i,"source",i.source))}))):function(n){if("number"==typeof n||"string"==typeof n)return{key:null,kind:"string",source:String(n).replace(m,"\\$&")};throw new TypeError(`Can't compose type ${typeof n} as RegExp`)}(u));var i})).map(U).map(function(n){let e=n;return function(t){if("regexp"===t.kind||"result"===t.kind){if(v(t)){P.hasRefs=!0;let r=!1;t.source=t.source.replace(k,(function(t,u,o,i){if(!r){if(null!=u){const n=Number(u)+e;if(n>99)throw new RangeError("Back reference index larger than 99");return"\\"+String(n)}if(null!=o){if("0"===o){const e=Number(i)+n;if(e>99)throw new RangeError("Back reference index larger than 99");return"\\"+String(e)}return`$d:${Number(o)-1},n:${i}^`}}return"["===t?r=!0:"]"===t&&(r=!1),t}))}P.hasFinalRef=!!I(t.key,"hasFinalRef"),e+=F(t)}return P.captureCount=e,t}}(u)).reduceRight(e?function(n,e){return n.source=null==n.source?e.source:`${e.source}|${n.source}`,n}:function(n,e){return n.source=null==n.source?e.source:e.source+("string"!==e.kind&&v(e)&&I(e.key,"hasFinalRef")&&/^\d/.test(n.source)?"(?:)":"")+n.source,n},{key:O(null,Object.assign({direction:P.hasRefs?Z.current:0,isDisjunction:e&&(n.length>1||1===n.length&&n[0]instanceof c&&I(n[0],"isDisjunction")),unicode:z.U},P)),kind:"result",source:null})}function Q(){return(z.I?"i":"")+(r?"":z.M?"m":"")+(z.U?"u":"")}function H(n,e){e=e||{};const t=u.call(e,"flags")?e.flagsOp(Q(),e.flags):Q(),r=e.either,o=new RegExp(r?n.source||"[]":n.source||"",t);return O(o,O(n.key,{})),O(o,"source",n.source),u.call(e,"direction")&&O(o,"direction",e.direction),o}const K=/(?:)/,V=/[]/;function X(n){if(!r)throw new Error("no support for /(?<=...)/ which is required by "+n+"()")}function Y(...n){return 0===n.length?V:(q(),H(J(n,!0,!1,0),{either:!0}))}function nn(...n){return J(n,!1,!1,0)}function en(...n){return 0===n.length?K:(q(),H(nn(...n)))}function tn(n,e,t,r,u){return function(...o){if(null!=r&&r(u),!o.length)return t;const i=Z.current;Z.current=e;try{q();return H(G(nn(...o),{open:n}),{direction:0})}finally{Z.current=i}}}const rn=tn("(?=",1,K),un=tn("(?!",1,V),on=tn("(?<=",-1,K,X,"lookBehind"),cn=tn("(?<!",-1,V,X,"notBehind");function sn(n,...e){if(q(),0===e.length)throw new SyntaxError("Suffix to an empty prefix");return H(G(nn(...e),{condition:M,open:"(?:",suffix:n}))}function fn(n,...e){"string"!=typeof n&&(n="{"+String(n)+"}");const t=n.match(E);if(!t||t[2]&&Number(t[2])<Number(t[1]))throw new SyntaxError("Invalid suffix '"+n+"'.");return 0===e.length?sn.bind(null,n):sn(n,...e)}sn.call;const ln=fn("?");function an(n){return!t||g.test(s(n))}function dn(n,e){if(!function(n){const e=typeof n;return"string"===e&&an(n)||"number"===e&&0<n&&Math.round(n)===n}(n))throw new SyntaxError("Bad ref: "+n);if(null!=e&&("number"!=typeof e||e<1||e!=e|0))throw new RangeError("Bad depth: "+e);if("string"==typeof n)return new RegExp("\\k<"+n+">");const t=new RegExp("$d:"+(e||"0")+",n:"+n+"^");return O(t,{direction:Z.current,hasFinalRef:!0,hasRefs:!0}),t}function pn(...n){q();return H(G(J(n,!1,!1,1),{open:"("}))}function gn(n,...e){if("string"!=typeof n)throw new TypeError("String expected, got "+typeof n);an(n),q();return H(G(J(e,!1,!1,1),{open:"(?<"+n+">"}))}function hn(n,e){return n=n.split(""),e.split("").forEach((function(e){-1===n.indexOf(e)&&n.push(e)})),n.sort().join("")}function yn(n,...e){q(),-1!==n.indexOf("u")&&(z.U=!0);return H(nn(...e),{flagsOp:hn,flags:n})}const xn={add:function(n,...e){if("string"!=typeof n)throw TypeError("String expected as first argument, got "+typeof n);if(!N.test(n))throw new SyntaxError("Invalid flags: "+n);return 0===e.length?yn.bind(null,n):yn(n,...e)}};const kn=t&&new RegExp("[^]","u");function wn(n,e){return en(un(e),n)}const $n={difference:wn,intersection:function(n,e){return en(rn(e),n)},complement:function(n){return wn(t&&n.unicode?kn:/[^]/,n)},union:Y};n.atomic=function(...n){return 1===Z.current?en(rn(pn(...n)),dn(1)):en(dn(1),on(pn(...n)))},n.bound=function(n){return X("bound"),Y([cn(n),rn(n)],[on(n),un(n)])},n.capture=pn,n.charSet=$n,n.either=Y,n.flags=xn,n.lookAhead=rn,n.lookBehind=on,n.maybe=ln,n.namedCapture=function(n,...e){return 0===e.length?gn.bind(null,n):gn(n,...e)},n.noBound=function(n){return X("noBound"),Y([cn(n),un(n)],[on(n),rn(n)])},n.notAhead=un,n.notBehind=cn,n.ref=dn,n.sequence=en,n.suffix=fn}));
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define("compose-regexp",["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).composeRegexp={})}(this,(function(n){"use strict";const e=[];"dgimsuy".split("").forEach((function(n){try{new RegExp("",n),e.push(n)}catch(n){}}));const t=-1!==e.indexOf("u"),r=(()=>{try{return new RegExp("(?<=)"),!0}catch(n){return!1}})(),u={}.hasOwnProperty;function o(n){return n}const i=[].map,c=RegExp;function s(n){return-1===n.indexOf("\\")?n:JSON.parse('"'+n.replace(/$|"|\\x([\dA-Fa-f]{2})|\\u\{([\dA-Fa-f]{1,6})\}/g,(function(n,e,t){return""===n?'"':'"'===n?'\\"':String.fromCodePoint(parseInt(e||t,16))})))}const f={value:void 0,writable:!1,enumerable:!1,configurable:!1};function l(){return"_"+Math.floor(Math.random()*Math.pow(2,32)).toString(36)}const a="undefined"!=typeof WeakMap?new WeakMap:{key:"__$$__compose_regexp__$$__"+l()+l()+l()+l(),set:function(n,e){const t=typeof n;if(null==n||"object"!==t&&"function"!==t)throw new TypeError("Bad WeakMap key");const r=n[a.key];if(!r)return f.value={keys:[this],values:[e]},Object.defineProperty(n,a.key,f),this;const u=r.keys.indexOf(this);return 0===u?(r.keys.push(this),r.values.push(e),this):(r.values[u]=e,this)},get:function(n){const e=n[a.key];if(e){const n=e.keys.indexOf(this);if(-1!==n)return e.values[n]}}},d=/\\[^]|\(\?(?::|<?[=!])|[\[\](]/g,p=/\\.|\.|\(\?:\^\|\(\?<=\[\\n\\r\\u2028\\u2029\]\)\)|\(\?:\$\|\(\?=\[\\n\\r\\u2028\\u2029\]\)\)|\[|\]|\^|\$/g,g=t&&new RegExp("^[_$\\p{ID_Start}][$\\p{ID_Continue}]*$","u"),h=/\\.|\{\d+(?:,\d*)?\}|(\[|\]|\{|\})/g,y=/(?:$|(?=[\n\r\u2028\u2029]))/,x=/(?:^|(?<=[\n\r\u2028\u2029]))/,k=/\\[^1-9]|[\[\]]|\\(\d{1,2})|\$d:(\d+),n:(\d+)\^/g,w=/^(?:\\.|\[(?:[^\]\\]|\\.)*\])$/,$=/^\\p\{[A-Za-z][A-Za-z=]*\}$/,m=/[.?*+^$[\]\\(){}|]/g,E=/^(?:[+*?]|\{(\d+)(?:,(\d*))?\})\??$/,b=/(\\.)|[-()|\[\]]((?=\?<?[=!]))?/g,R=/\\u[0-9A-Fa-f]{4}|\\x[0-9A-Fa-f]{2}|\\c[A-Za-z]|\\([^.?*+^$[\]\\(){}|\/DSWdswfnrtv-])|(\\[DSWdsw]-[^\]]|.-\\[DSWdsw])|\\.|\]/g,S=/\\u[0-9A-Fa-f]{4}|\\x[0-9A-Fa-f]{2}|\\c[A-Za-z]|\\k<(.*?)>|\\([^.?*+^$[\]\\(){}|\/DSWdswBbfnrtv])|\\.|\.|\[\^\]|\[|(\((?:\?[^])?)|(\)(?:[+?*]|\{\d+,?\d*\})?)/g;function A(n){if(n instanceof c){let e=a.get(n);return null==e&&a.set(n,e={captureCount:null,direction:0,hasRefs:null,hasFinalRef:null,isDisjunction:null,isOneGroupOrAssertion:null,source:null,unicode:null}),e}return n||{captureCount:null,direction:0,hasRefs:null,hasFinalRef:null,isDisjunction:null,isOneGroupOrAssertion:null,source:null,unicode:null}}const O=function(n,e,t){const r=A(n);return"object"==typeof e?Object.assign(r,e):r[e]=t},I=function(n,e){return A(n)[e]};function j(n,e){return Object.defineProperty((function(t){const r=I(t.key,n);return null!=r?r:O(t.key,n,e(t))}),"name",{value:n})}const B=[];const F=j("captureCount",(function(n){let e,t=0;for(d.lastIndex=0;e=d.exec(n.source);)"("===e[0]&&(t+=1);return t})),v=j("hasRefs",(function(n){let e,t=!1,r=!1,u=!1;for(k.lastIndex=0;e=k.exec(n.source);)u||null==e[1]&&null==e[2]?"["===e[0]?u=!0:"]"===e[0]&&(u=!1):(t=!0,k.lastIndex===n.source.length&&(r=!0));return O(n.key,"hasFinalRef",r),t})),C=j("isDisjunction",(function(n){if(-1===n.source.indexOf("|"))return!1;let e,t=0,r=!1;for(b.lastIndex=0;e=b.exec(n.source);)if(null==e[1]&&(r||"("!==e[0]||t++,r||")"!==e[0]||t--,r||"["!==e[0]&&"[-"!==e[0]||(r=!0),r&&"]"===e[0]&&(r=!1),0===t&&!r&&"|"===e[0]))return!0;return!1})),_=j("isOneGroupOrAssertion",(function(n){const e=n.source;if("("!==e.charAt(0)||")"!==e.charAt(e.length-1))return!1;let t,r=0,u=!1;for(b.lastIndex=0;t=b.exec(e);)if(null==t[1]){if(u||"("!==t[0]||r++,!u&&")"===t[0]&&(r--,0===r&&t.index!==e.length-1))return!1;u||"["!==t[0]&&"[-"!==t||(u=!0),u&&"]"===t[0]&&(u=!1)}else if(t.index===e.length-2)return!1;return!0}));function M(n){const e=n.source;if(null==e||"^"===e||"$"===e||"\\b"===e||"\\B"===e)throw new SyntaxError(`Nothing to repeat: / ${e||"(?:)"}/`);if(1===e.length||w.test(e)||z.U&&$.test(e))return!1;if(!_(n))return!0;if(/^\(\?<?[!=]/.test(e))throw new SyntaxError(`Nothing to repeat: /${e}/`);return!1}const D=j("hasLoneQuantifierBracket",(function(n){let e,t=!1;for(h.lastIndex=0;e=h.exec(n.source);)if(null!=e[1])if(t)"]"===e[1]&&(t=!1);else{if("["!==e[1]){if("]"===e[1])continue;return e[1]}t=!0}return!1}));function U(n){const e=n.source;if(z.U&&("regexp"===n.kind&&!n.key.unicode||"result"===n.kind&&!I(n.key,"unicode"))){if(function(n){let e,t=S;function r(n){n.lastIndex=t.lastIndex,t=n}for(B.length=0,S.lastIndex=0;e=t.exec(n);)if(t===S)if("["===e[0])r(R);else{if("."===e[0]||"[^]"===e[0]||null!=e[1]&&!g.test(s(e[1]))||null!=e[2])return!0;if(null!=e[3])B.unshift(e[3]);else if(null!=e[4]){if(("(?="===B[0]||"(?!"===B[0])&&")"!==e[4])return!0;B.shift()}}else if("]"===e[0])r(S);else if(null!=e[1]||null!=e[2])return!0;return!1}(e))throw new SyntaxError(`Can't upgrade the RegExp to Unicode /${e}/${"regexp"===n.kind?n.key.flags:""}`);n.source=function(n){let e=!1;return n.replace(h,(function(n,t){if("]"===n){if(!e)return"\\]";e=!1}else if(!e&&null!=t){if("["!==t)return"\\"+t;e=!0}return n}))}(e)}let t=!1;return"regexp"===n.kind&&(n.key.dotAll||n.key.multiline)&&(n.source=e.replace(p,(function(e){return t?("]"===e&&(t=!1),e):("["===e&&(t=!0),n.key.dotAll&&"."===e?"[^]":n.key.multiline&&"^"===e&&r?x.source:n.key.multiline&&"$"===e&&r?y.source:e)}))),n}const N=new RegExp(`^(?:([${e.join("")}])(?!.*\\1))*$`),T=new RegExp(`[${e.join()}]`,"g");const W={"-1":"backward",1:"forward"};let z,P,Z={current:1};function q(){P={hasRefs:!1,hasFinalRef:!1,captureCount:0},z={U:!1,I:null,M:null}}function G(n,e){return e.condition&&!e.condition(n)||(n.source=e.open+(n.source||"")+")"),e.suffix&&(n.source+=e.suffix),n}function L(n){return G(n,{condition:function(n){return("regexp"===n.kind||"result"===n.kind)&&C(n)},open:"(?:"})}function J(n,e,t,u){return t=t||n.length>1,i.call(n,(function n(u){return(!e&&t?L:o)(Array.isArray(u)?J(u,!1,t,0):"function"==typeof u?n(function(n){const e=P,t=z;try{return n()}finally{P=e,z=t}}(u)):u instanceof c?function(n){if(null==n||"regexp"!==n.kind||n.key.unicode)return n;const e=D(n);if(!1===e)return n;throw new SyntaxError(`Lone quantifier bracket ${e} in /${n.source}/${n.key.flags}`)}(function(n){const e=I(n.key,"direction");if(e*Z.current==-1)throw new TypeError(`Illegal ${W[e]} RegExp argument while building a ${W[Z.current]} one: /${n.source}/`);return 0!==e&&(P.hasRefs=!0),n}(function(n){const e=n.key.flags;if(!N.test(e))throw new TypeError(`Unkown flag(s): ${e.replace(T,"")}`);const t=!!n.key.unicode,u=n.key.ignoreCase,o=n.key.multiline;if(null!=z.I&&u!==z.I)throw new SyntaxError("Can't combine i and non-i regexps: "+n.key);if(!r&&null!=z.M&&o!==z.M)throw new SyntaxError("Can't combine m and non-m regexps: "+n.key);return z.I=u,z.M=o,z.U=z.U||t,n}({key:u,kind:"regexp",source:(i=u,I(i,"source")||O(i,"source",i.source))}))):function(n){if("number"==typeof n||"string"==typeof n)return{key:null,kind:"string",source:String(n).replace(m,"\\$&")};throw new TypeError(`Can't compose type ${typeof n} as RegExp`)}(u));var i})).map(U).map(function(n){let e=n;return function(t){if("regexp"===t.kind||"result"===t.kind){if(v(t)){P.hasRefs=!0;let r=!1;t.source=t.source.replace(k,(function(t,u,o,i){if(!r){if(null!=u){const n=Number(u)+e;if(n>99)throw new RangeError("Back reference index larger than 99");return"\\"+String(n)}if(null!=o){if("0"===o){const e=Number(i)+n;if(e>99)throw new RangeError("Back reference index larger than 99");return"\\"+String(e)}return`$d:${Number(o)-1},n:${i}^`}}return"["===t?r=!0:"]"===t&&(r=!1),t}))}P.hasFinalRef=!!I(t.key,"hasFinalRef"),e+=F(t)}return P.captureCount=e,t}}(u)).reduceRight(e?function(n,e){return n.source=null==n.source?e.source:`${e.source}|${n.source}`,n}:function(n,e){return n.source=null==n.source?e.source:e.source+("string"!==e.kind&&v(e)&&I(e.key,"hasFinalRef")&&/^\d/.test(n.source)?"(?:)":"")+n.source,n},{key:O(null,Object.assign({direction:P.hasRefs?Z.current:0,isDisjunction:e&&(n.length>1||1===n.length&&n[0]instanceof c&&I(n[0],"isDisjunction")),unicode:z.U},P)),kind:"result",source:null})}function Q(){return(z.I?"i":"")+(r?"":z.M?"m":"")+(z.U?"u":"")}function H(n,e){e=e||{};const t=u.call(e,"flags")?e.flagsOp(Q(),e.flags):Q(),r=e.either,o=new RegExp(r?n.source||"[]":n.source||"",t);return O(o,O(n.key,{})),O(o,"source",n.source),u.call(e,"direction")&&O(o,"direction",e.direction),o}const K=/(?:)/,V=/[]/;function X(n){if(!r)throw new Error("no support for /(?<=...)/ which is required by "+n+"()")}function Y(...n){return 0===n.length?V:(q(),H(J(n,!0,!1,0),{either:!0}))}function nn(...n){return J(n,!1,!1,0)}function en(...n){return 0===n.length?K:(q(),H(nn(...n)))}function tn(n,e,t,r,u){return function(...o){if(null!=r&&r(u),!o.length)return t;const i=Z.current;Z.current=e;try{q();return H(G(nn(...o),{open:n}),{direction:0})}finally{Z.current=i}}}const rn=tn("(?=",1,K),un=tn("(?!",1,V),on=tn("(?<=",-1,K,X,"lookBehind"),cn=tn("(?<!",-1,V,X,"notBehind");function sn(n,...e){if(q(),0===e.length)throw new SyntaxError("Suffix to an empty prefix");return H(G(nn(...e),{condition:M,open:"(?:",suffix:n}))}function fn(n,...e){"string"!=typeof n&&(n="{"+String(n)+"}");const t=n.match(E);if(!t||t[2]&&Number(t[2])<Number(t[1]))throw new SyntaxError("Invalid suffix '"+n+"'.");return 0===e.length?sn.bind(null,n):sn(n,...e)}sn.call;const ln=fn("?");function an(n){return!t||g.test(s(n))}function dn(n,e){if(!function(n){const e=typeof n;return"string"===e&&an(n)||"number"===e&&0<n&&Math.round(n)===n}(n))throw new SyntaxError("Bad ref: "+n);if(null!=e&&("number"!=typeof e||e<1||e!=e|0))throw new RangeError("Bad depth: "+e);if("string"==typeof n)return new RegExp("\\k<"+n+">");const t=new RegExp("$d:"+(e||"0")+",n:"+n+"^");return O(t,{direction:Z.current,hasFinalRef:!0,hasRefs:!0}),t}function pn(...n){q();return H(G(J(n,!1,!1,1),{open:"("}))}function gn(n,...e){if("string"!=typeof n)throw new TypeError("String expected, got "+typeof n);an(n),q();return H(G(J(e,!1,!1,1),{open:"(?<"+n+">"}))}function hn(n,e){return n=n.split(""),e.split("").forEach((function(e){-1===n.indexOf(e)&&n.push(e)})),n.sort().join("")}function yn(n,...e){q(),-1!==n.indexOf("u")&&(z.U=!0);return H(nn(...e),{flagsOp:hn,flags:n})}const xn={add:function(n,...e){if("string"!=typeof n)throw TypeError("String expected as first argument, got "+typeof n);if(!N.test(n))throw new SyntaxError("Invalid flags: "+n);return 0===e.length?yn.bind(null,n):yn(n,...e)}};const kn=t&&new RegExp("[^]","u");function wn(n,e){return en(un(e),n)}const $n={difference:wn,intersection:function(n,e){return en(rn(e),n)},complement:function(n){return wn(t&&n.unicode?kn:/[^]/,n)},union:Y};n.atomic=function(...n){return 1===Z.current?en(rn(pn(...n)),dn(1)):en(dn(1),on(pn(...n)))},n.bound=function(n){return X("bound"),Y([cn(n),rn(n)],[on(n),un(n)])},n.capture=pn,n.charSet=$n,n.either=Y,n.flags=xn,n.lookAhead=rn,n.lookBehind=on,n.maybe=ln,n.namedCapture=function(n,...e){return 0===e.length?gn.bind(null,n):gn(n,...e)},n.noBound=function(n){return X("noBound"),Y([cn(n),un(n)],[on(n),rn(n)])},n.notAhead=un,n.notBehind=cn,n.ref=dn,n.sequence=en,n.suffix=fn}));
{
"name": "compose-regexp",
"version": "0.7.0",
"version": "0.7.1",
"description": "A set of functions to build and compose complex regular expressions",

@@ -53,3 +53,3 @@ "type": "module",

"rollup": "^3.11.0",
"stable-version": "npm:compose-regexp@0.6.31",
"stable-version": "npm:compose-regexp@0.7.0",
"terser": "^5.16.1"

@@ -56,0 +56,0 @@ },

@@ -333,3 +333,3 @@

else if (result[1] === ']') continue
else return true
else return result[1]
}

@@ -336,0 +336,0 @@ }

@@ -547,3 +547,5 @@ import o from 'ospec'

o(()=>sequence(/{/, 'x')).throws(SyntaxError)
o(()=>sequence(/{/, 'x')).throws("Lone quantifier bracket { in /{/")
o(()=>sequence('x', /}/)).throws(SyntaxError)
o(()=>sequence('x', /}/)).throws("Lone quantifier bracket } in /}/")
})

@@ -550,0 +552,0 @@

Sorry, the diff of this file is not supported yet

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