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

regex

Package Overview
Dependencies
Maintainers
0
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regex - npm Package Compare versions

Comparing version 4.2.1 to 4.3.0

18

dist/regex.min.js

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

var Regex=(()=>{var H=Object.defineProperty;var Ce=Object.getOwnPropertyDescriptor;var Ie=Object.getOwnPropertyNames;var Le=Object.prototype.hasOwnProperty;var _e=(e,t)=>{for(var n in t)H(e,n,{get:t[n],enumerable:!0})},be=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ie(t))!Le.call(e,o)&&o!==n&&H(e,o,{get:()=>t[o],enumerable:!(r=Ce(t,o))||r.enumerable});return e};var Oe=e=>be(H({},"__esModule",{value:!0}),e);var ze={};_e(ze,{pattern:()=>V,processRegex:()=>qe,regex:()=>je,rewrite:()=>qe});var E=Object.freeze({DEFAULT:"DEFAULT",CHAR_CLASS:"CHAR_CLASS"});function N(e,t,n,r){let o=new RegExp(String.raw`${t}|(?<$skip>\[\^?|\\?.)`,"gsu"),i=[!1],s=0,a="";for(let u of e.matchAll(o)){let{0:c,groups:{$skip:p}}=u;if(!p&&(!r||r===E.DEFAULT==!s)){n instanceof Function?a+=n(u,{context:s?E.CHAR_CLASS:E.DEFAULT,negated:i[i.length-1]}):a+=n;continue}c[0]==="["?(s++,i.push(c[1]==="^")):c==="]"&&s&&(s--,i.pop()),a+=c}return a}function k(e,t,n,r){N(e,t,n,r)}function y(e,t,n=0,r){if(!new RegExp(t,"su").test(e))return null;let o=new RegExp(`${t}|(?<$skip>\\\\?.)`,"gsu");o.lastIndex=n;let i=0,s;for(;s=o.exec(e);){let{0:a,groups:{$skip:u}}=s;if(!u&&(!r||r===E.DEFAULT==!i))return s;a==="["?i++:a==="]"&&i&&i--,o.lastIndex==s.index&&o.lastIndex++}return null}function v(e,t,n){return!!y(e,t,0,n)}function W(e,t){let n=/\\?./gsu;n.lastIndex=t;let r=e.length,o=0,i=1,s;for(;s=n.exec(e);){let[a]=s;if(a==="[")o++;else if(o)a==="]"&&o--;else if(a==="(")i++;else if(a===")"&&(i--,!i)){r=s.index;break}}return e.slice(t,r)}var $=class{#e;constructor(t){this.#e=t}toString(){return String(this.#e)}};function V(e,...t){if(Array.isArray(e?.raw))return new $(e.raw.flatMap((n,r)=>r<e.raw.length-1?[n,t[r]]:n).join(""));if(!t.length)return new $(e??"");throw new Error(`Unexpected arguments: ${JSON.stringify([e,...t])}`)}var f={DEFAULT:"R_DEFAULT",CHAR_CLASS:"R_CHAR_CLASS",GROUP_NAME:"R_GROUP_NAME",ENCLOSED_TOKEN:"R_ENCLOSED_TOKEN",INTERVAL_QUANTIFIER:"R_INTERVAL_QUANTIFIER",INVALID_INCOMPLETE_TOKEN:"R_INVALID_INCOMPLETE_TOKEN"},d={DEFAULT:"CC_DEFAULT",RANGE:"CC_RANGE",ENCLOSED_TOKEN:"CC_ENCLOSED_TOKEN",Q_TOKEN:"CC_Q_TOKEN",INVALID_INCOMPLETE_TOKEN:"CC_INVALID_INCOMPLETE_TOKEN"},x=(()=>{try{new RegExp("(?i:)")}catch{return!1}return!0})(),oe=(()=>{try{new RegExp("","v")}catch{return!1}return!0})(),b="&!#$%*+,.:;<=>?@^`~",C="$E$",Q=String.raw`\(\?<(?![=!])(?<captureName>[^>]+)>`,O=String.raw`\((?!\?)(?!(?<=\(\?\()DEFINE\))|${Q}`,R=String.raw`\(\?(?:[:=!>A-Za-z\-]|<[=!]|\(DEFINE\))`;function B(e,t){return t===E.CHAR_CLASS?e.replace(new RegExp(String.raw`[()\[\]{}|\\/\-${b}]`,"g"),"\\$&"):e.replace(/[()\[\]{}|\\^$*+?.]/g,"\\$&")}function j(e){return e.replace(new RegExp(`^([${b}])(?!\\1)`),(t,n,r)=>`\\${t}${r+1===e.length?"":t}`)}function se(e){return e.replace(/^\^/,"\\^^")}function G(e,t){return N(e,String.raw`\\0(?!\d)`,"\\u{0}",t)}function ne(e,t,n){let r=0;for(let[o]of e.matchAll(new RegExp(`[${B(t+n,E.CHAR_CLASS)}]`,"g")))if(r+=o===t?1:-1,r<0)return n;return r>0?t:""}function ie(e,t,n){let r=e.replace(/\\./gsu,"");if(r.endsWith("\\"))return"\\";if(t===f.DEFAULT)return ne(r,"(",")");if(t===f.CHAR_CLASS&&!(n===d.ENCLOSED_TOKEN||n===d.Q_TOKEN))return ne(r,"[","]");if(t===f.ENCLOSED_TOKEN||t===f.INTERVAL_QUANTIFIER||n===d.ENCLOSED_TOKEN||n===d.Q_TOKEN){if(r.includes("}"))return"}"}else if(t===f.GROUP_NAME&&r.includes(">"))return">";return""}var re=new RegExp(String.raw`
var Regex=(()=>{var H=Object.defineProperty;var Ce=Object.getOwnPropertyDescriptor;var Ie=Object.getOwnPropertyNames;var Le=Object.prototype.hasOwnProperty;var _e=(e,t)=>{for(var n in t)H(e,n,{get:t[n],enumerable:!0})},be=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ie(t))!Le.call(e,o)&&o!==n&&H(e,o,{get:()=>t[o],enumerable:!(r=Ce(t,o))||r.enumerable});return e};var Oe=e=>be(H({},"__esModule",{value:!0}),e);var ze={};_e(ze,{pattern:()=>V,regex:()=>je,rewrite:()=>qe});var E=Object.freeze({DEFAULT:"DEFAULT",CHAR_CLASS:"CHAR_CLASS"});function N(e,t,n,r){let o=new RegExp(String.raw`${t}|(?<$skip>\[\^?|\\?.)`,"gsu"),i=[!1],s=0,a="";for(let u of e.matchAll(o)){let{0:c,groups:{$skip:p}}=u;if(!p&&(!r||r===E.DEFAULT==!s)){n instanceof Function?a+=n(u,{context:s?E.CHAR_CLASS:E.DEFAULT,negated:i[i.length-1]}):a+=n;continue}c[0]==="["?(s++,i.push(c[1]==="^")):c==="]"&&s&&(s--,i.pop()),a+=c}return a}function k(e,t,n,r){N(e,t,n,r)}function y(e,t,n=0,r){if(!new RegExp(t,"su").test(e))return null;let o=new RegExp(`${t}|(?<$skip>\\\\?.)`,"gsu");o.lastIndex=n;let i=0,s;for(;s=o.exec(e);){let{0:a,groups:{$skip:u}}=s;if(!u&&(!r||r===E.DEFAULT==!i))return s;a==="["?i++:a==="]"&&i&&i--,o.lastIndex==s.index&&o.lastIndex++}return null}function v(e,t,n){return!!y(e,t,0,n)}function W(e,t){let n=/\\?./gsu;n.lastIndex=t;let r=e.length,o=0,i=1,s;for(;s=n.exec(e);){let[a]=s;if(a==="[")o++;else if(o)a==="]"&&o--;else if(a==="(")i++;else if(a===")"&&(i--,!i)){r=s.index;break}}return e.slice(t,r)}var $=class{#e;constructor(t){this.#e=t}toString(){return String(this.#e)}};function V(e,...t){if(Array.isArray(e?.raw))return new $(e.raw.flatMap((n,r)=>r<e.raw.length-1?[n,t[r]]:n).join(""));if(!t.length)return new $(e??"");throw new Error(`Unexpected arguments: ${JSON.stringify([e,...t])}`)}var f={DEFAULT:"R_DEFAULT",CHAR_CLASS:"R_CHAR_CLASS",GROUP_NAME:"R_GROUP_NAME",ENCLOSED_TOKEN:"R_ENCLOSED_TOKEN",INTERVAL_QUANTIFIER:"R_INTERVAL_QUANTIFIER",INVALID_INCOMPLETE_TOKEN:"R_INVALID_INCOMPLETE_TOKEN"},d={DEFAULT:"CC_DEFAULT",RANGE:"CC_RANGE",ENCLOSED_TOKEN:"CC_ENCLOSED_TOKEN",Q_TOKEN:"CC_Q_TOKEN",INVALID_INCOMPLETE_TOKEN:"CC_INVALID_INCOMPLETE_TOKEN"},x=(()=>{try{new RegExp("(?i:)")}catch{return!1}return!0})(),oe=(()=>{try{new RegExp("","v")}catch{return!1}return!0})(),b="&!#$%*+,.:;<=>?@^`~",C="$E$",Q=String.raw`\(\?<(?![=!])(?<captureName>[^>]+)>`,O=String.raw`\((?!\?)(?!(?<=\(\?\()DEFINE\))|${Q}`,D=String.raw`\(\?(?:[:=!>A-Za-z\-]|<[=!]|\(DEFINE\))`;function B(e,t){return t===E.CHAR_CLASS?e.replace(new RegExp(String.raw`[()\[\]{}|\\/\-${b}]`,"g"),"\\$&"):e.replace(/[()\[\]{}|\\^$*+?.]/g,"\\$&")}function j(e){return e.replace(new RegExp(`^([${b}])(?!\\1)`),(t,n,r)=>`\\${t}${r+1===e.length?"":t}`)}function se(e){return e.replace(/^\^/,"\\^^")}function G(e,t){return N(e,String.raw`\\0(?!\d)`,"\\x00",t)}function ne(e,t,n){let r=0;for(let[o]of e.matchAll(new RegExp(`[${B(t+n,E.CHAR_CLASS)}]`,"g")))if(r+=o===t?1:-1,r<0)return n;return r>0?t:""}function ie(e,t,n){let r=e.replace(/\\./gsu,"");if(r.endsWith("\\"))return"\\";if(t===f.DEFAULT)return ne(r,"(",")");if(t===f.CHAR_CLASS&&!(n===d.ENCLOSED_TOKEN||n===d.Q_TOKEN))return ne(r,"[","]");if(t===f.ENCLOSED_TOKEN||t===f.INTERVAL_QUANTIFIER||n===d.ENCLOSED_TOKEN||n===d.Q_TOKEN){if(r.includes("}"))return"}"}else if(t===f.GROUP_NAME&&r.includes(">"))return">";return""}var re=new RegExp(String.raw`
(?<groupN>\(\?<(?![=!])|\\[gk]<)

@@ -14,5 +14,5 @@ | (?<enclosedT>\\[pPu]\{)

| \\?.
`.replace(/\s+/g,""),"gsu");function D(e,{regexContext:t=f.DEFAULT,charClassContext:n=d.DEFAULT,charClassDepth:r=0,lastPos:o=0}={}){re.lastIndex=o;let i;for(;i=re.exec(e);){let{0:s,groups:{groupN:a,enclosedT:u,qT:c,intervalQ:p,incompleteT:g}}=i;s==="["?(r++,t=f.CHAR_CLASS,n=d.DEFAULT):s==="]"&&t===f.CHAR_CLASS?(r&&r--,r||(t=f.DEFAULT),n=d.DEFAULT):t===f.CHAR_CLASS?g?n=d.INVALID_INCOMPLETE_TOKEN:s==="-"?n=d.RANGE:u?n=d.ENCLOSED_TOKEN:c?n=d.Q_TOKEN:(s==="}"&&(n===d.ENCLOSED_TOKEN||n===d.Q_TOKEN)||n===d.INVALID_INCOMPLETE_TOKEN||n===d.RANGE)&&(n=d.DEFAULT):g?t=f.INVALID_INCOMPLETE_TOKEN:a?t=f.GROUP_NAME:u?t=f.ENCLOSED_TOKEN:p?t=f.INTERVAL_QUANTIFIER:(s===">"&&t===f.GROUP_NAME||s==="}"&&(t===f.ENCLOSED_TOKEN||t===f.INTERVAL_QUANTIFIER)||t===f.INVALID_INCOMPLETE_TOKEN)&&(t=f.DEFAULT)}return{regexContext:t,charClassContext:n,charClassDepth:r,lastPos:e.length}}function U(e){let t=0;return k(e,O,()=>t++,E.DEFAULT),t}function ae(e,t){return N(e,String.raw`\\(?<num>[1-9]\d*)`,({groups:{num:n}})=>`\\${+n+t}`,E.DEFAULT)}var Re=["Basic_Emoji","Emoji_Keycap_Sequence","RGI_Emoji_Modifier_Sequence","RGI_Emoji_Flag_Sequence","RGI_Emoji_Tag_Sequence","RGI_Emoji_ZWJ_Sequence","RGI_Emoji"].join("|"),De=new RegExp(String.raw`
`.replace(/\s+/g,""),"gsu");function R(e,{regexContext:t=f.DEFAULT,charClassContext:n=d.DEFAULT,charClassDepth:r=0,lastPos:o=0}={}){re.lastIndex=o;let i;for(;i=re.exec(e);){let{0:s,groups:{groupN:a,enclosedT:u,qT:c,intervalQ:p,incompleteT:g}}=i;s==="["?(r++,t=f.CHAR_CLASS,n=d.DEFAULT):s==="]"&&t===f.CHAR_CLASS?(r&&r--,r||(t=f.DEFAULT),n=d.DEFAULT):t===f.CHAR_CLASS?g?n=d.INVALID_INCOMPLETE_TOKEN:s==="-"?n=d.RANGE:u?n=d.ENCLOSED_TOKEN:c?n=d.Q_TOKEN:(s==="}"&&(n===d.ENCLOSED_TOKEN||n===d.Q_TOKEN)||n===d.INVALID_INCOMPLETE_TOKEN||n===d.RANGE)&&(n=d.DEFAULT):g?t=f.INVALID_INCOMPLETE_TOKEN:a?t=f.GROUP_NAME:u?t=f.ENCLOSED_TOKEN:p?t=f.INTERVAL_QUANTIFIER:(s===">"&&t===f.GROUP_NAME||s==="}"&&(t===f.ENCLOSED_TOKEN||t===f.INTERVAL_QUANTIFIER)||t===f.INVALID_INCOMPLETE_TOKEN)&&(t=f.DEFAULT)}return{regexContext:t,charClassContext:n,charClassDepth:r,lastPos:e.length}}function U(e){let t=0;return k(e,O,()=>t++,E.DEFAULT),t}function ae(e,t){return N(e,String.raw`\\(?<num>[1-9]\d*)`,({groups:{num:n}})=>`\\${+n+t}`,E.DEFAULT)}var De=["Basic_Emoji","Emoji_Keycap_Sequence","RGI_Emoji_Modifier_Sequence","RGI_Emoji_Flag_Sequence","RGI_Emoji_Tag_Sequence","RGI_Emoji_ZWJ_Sequence","RGI_Emoji"].join("|"),Re=new RegExp(String.raw`
\\(?: c[A-Za-z]
| p\{(?<pStrProp>${Re})\}
| p\{(?<pStrProp>${De})\}
| [pP]\{[^\}]+\}

@@ -27,8 +27,8 @@ | (?<qStrProp>q)

| .
`.replace(/\s+/g,""),"gsu");function z(e){let t=!1,n;for(let{0:r,groups:o}of e.matchAll(De)){if(o.pStrProp||o.qStrProp||r==="["&&t)return!0;if(["-","--","&&"].includes(r))t=!1;else if(r!=="["&&r!=="]"){if(t||n==="]")return!0;t=!0}n=r}return!1}function ue(e,t,n,r){let o={raw:[]},i=[],s;return e.raw.forEach((a,u)=>{let c=n(a,{...s,lastPos:0},r);if(o.raw.push(c.transformed),s=c.runningContext,u<e.raw.length-1){let p=t[u];if(p instanceof $){let g=n(p,{...s,lastPos:0},r);i.push(V(g.transformed)),s=g.runningContext}else i.push(p)}}),{template:o,substitutions:i}}var Ue=new RegExp(String.raw`
${R}
`.replace(/\s+/g,""),"gsu");function z(e){let t=!1,n;for(let{0:r,groups:o}of e.matchAll(Re)){if(o.pStrProp||o.qStrProp||r==="["&&t)return!0;if(["-","--","&&"].includes(r))t=!1;else if(r!=="["&&r!=="]"){if(t||n==="]")return!0;t=!0}n=r}return!1}function ue(e,t,n,r){let o={raw:[]},i=[],s;return e.raw.forEach((a,u)=>{let c=n(a,{...s,lastPos:0},r);if(o.raw.push(c.transformed),s=c.runningContext,u<e.raw.length-1){let p=t[u];if(p instanceof $){let g=n(p,{...s,lastPos:0},r);i.push(V(g.transformed)),s=g.runningContext}else i.push(p)}}),{template:o,substitutions:i}}var Ue=new RegExp(String.raw`
${D}
| \(\?<
| (?<backrefNum>\\[1-9]\d*)
| \\?.
`.replace(/\s+/g,""),"gsu");function le(e,t){e=String(e);let n="",r="";for(let{0:o,groups:{backrefNum:i}}of e.matchAll(Ue)){n+=o,t=D(n,t);let{regexContext:s}=t;if(s===f.DEFAULT)if(o==="(")r+="(?:";else{if(i)throw new Error(`Invalid decimal escape "${o}" with implicit flag n; replace with named backreference`);r+=o}else r+=o}return{transformed:r,runningContext:t}}var ce=/^\s$/,Fe=/^\\[\s#]$/,Z=/^[ \t]$/,Pe=/^\\[ \t]$/,ke=new RegExp(String.raw`
`.replace(/\s+/g,""),"gsu");function le(e,t){e=String(e);let n="",r="";for(let{0:o,groups:{backrefNum:i}}of e.matchAll(Ue)){n+=o,t=R(n,t);let{regexContext:s}=t;if(s===f.DEFAULT)if(o==="(")r+="(?:";else{if(i)throw new Error(`Invalid decimal escape "${o}" with implicit flag n; replace with named backreference`);r+=o}else r+=o}return{transformed:r,runningContext:t}}var ce=/^\s$/,Fe=/^\\[\s#]$/,Z=/^[ \t]$/,Pe=/^\\[ \t]$/,ke=new RegExp(String.raw`
\\(?: [gk]<

@@ -42,3 +42,3 @@ | [pPu]\{

| \[\^
| ${R}
| ${D}
| \(\?<

@@ -49,3 +49,3 @@ | (?<dp>[${b}])\k<dp>

`.replace(/\s+/g,""),"gsu");function fe(e,t,n){e=String(e);let r=!1,o=!1,i=!1,s="",a="",u="",c="",p=!1,g=(l,{prefix:m=!0,postfix:A=!1}={})=>(l=(p&&m?"(?:)":"")+l+(A?"(?:)":""),p=!1,l);for(let{0:l,index:m}of e.matchAll(ke)){if(i){l===`
`&&(i=!1,p=!0);continue}if(r){if(ce.test(l))continue;r=!1,p=!0}else if(o){if(Z.test(l))continue;o=!1}s+=l,t=D(s,t);let{regexContext:A,charClassContext:h}=t;if(l==="-"&&A===f.CHAR_CLASS&&c===d.RANGE&&(n.unicodeSetsPlugin||n.flags.includes("v")))throw new Error("Invalid unescaped hyphen as the end value for a range");if(A===f.DEFAULT&&/^(?:[?*+]|\?\?)$/.test(l)||A===f.INTERVAL_QUANTIFIER&&l==="{")a+=g(l,{prefix:!1,postfix:u==="("&&l==="?"});else if(A===f.DEFAULT)ce.test(l)?r=!0:l.startsWith("#")?i=!0:Fe.test(l)?a+=g(l[1],{prefix:!1}):a+=g(l);else if(A===f.CHAR_CLASS&&l!=="["&&l!=="[^")if(Z.test(l)&&(h===d.DEFAULT||h===d.RANGE||h===d.Q_TOKEN))o=!0;else{if(h===d.INVALID_INCOMPLETE_TOKEN)throw new Error(`Invalid incomplete token in character class: "${l}"`);if(Pe.test(l)&&(h===d.DEFAULT||h===d.Q_TOKEN))a+=g(l[1],{prefix:!1});else if(h===d.DEFAULT){let T=e[m+1]??"",S=G(l);(Z.test(T)||l==="^")&&(S=j(S)),a+=g(S)}else a+=g(l)}else a+=g(l);r||o||i||(u=l,c=h)}return{transformed:a,runningContext:t}}function pe(e){let t=String.raw`\(\?:\)`;e=N(e,`(?:${t}){2,}`,"(?:)",E.DEFAULT);let n=C.replace(/\$/g,"\\$");return e=N(e,String.raw`(?:${t}(?=[)|.[$\\]|\((?!DEFINE)|$)|(?<=[()|.\]^>]|\\[bBdDfnrsStvwW]|\(\?(?:[:=!]|<[=!])|^)${t}(?![?*+{]))(?!${n})`,"",E.DEFAULT),e}var Ee=new RegExp(String.raw`(?<noncapturingStart>${R})|(?<capturingStart>\((?:\?<[^>]+>)?)|\\?.`,"gsu");function de(e,t){if(!/\(\?>/.test(e))return e;let n="(?>",r=`(?:(?=(${t.useEmulationGroups?C:""}`,o=[0],i=0,s=0,a=NaN,u;do{u=!1;let c=0,p=0,g=!1,l;for(Ee.lastIndex=Number.isNaN(a)?0:a+r.length;l=Ee.exec(e);){let{0:m,index:A,groups:{capturingStart:h,noncapturingStart:T}}=l;if(m==="[")c++;else if(c)m==="]"&&c--;else if(m===n&&!g)a=A,g=!0;else if(g&&T)p++;else if(h)g?p++:(i++,o.push(i+s));else if(m===")"&&g){if(!p){s++,e=`${e.slice(0,a)}${r}${e.slice(a+n.length,A)}))<$$${s+i}>)${e.slice(A+1)}`,u=!0;break}p--}}}while(u);return e=N(e,String.raw`\\(?<backrefNum>[1-9]\d*)|<\$\$(?<wrappedBackrefNum>\d+)>`,({0:c,groups:{backrefNum:p,wrappedBackrefNum:g}})=>{if(p){let l=+p;if(l>o.length-1)throw new Error(`Backref "${c}" greater than number of captures`);return`\\${o[l]}`}return`\\${g}`},E.DEFAULT),e}var ge=String.raw`(?:[?*+]|\{\d+(?:,\d*)?\})`,xe=new RegExp(String.raw`
`&&(i=!1,p=!0);continue}if(r){if(ce.test(l))continue;r=!1,p=!0}else if(o){if(Z.test(l))continue;o=!1}s+=l,t=R(s,t);let{regexContext:A,charClassContext:h}=t;if(l==="-"&&A===f.CHAR_CLASS&&c===d.RANGE&&(n.flags.includes("v")||n.unicodeSetsPlugin))throw new Error("Invalid unescaped hyphen as the end value for a range");if(A===f.DEFAULT&&/^(?:[?*+]|\?\?)$/.test(l)||A===f.INTERVAL_QUANTIFIER&&l==="{")a+=g(l,{prefix:!1,postfix:u==="("&&l==="?"});else if(A===f.DEFAULT)ce.test(l)?r=!0:l.startsWith("#")?i=!0:Fe.test(l)?a+=g(l[1],{prefix:!1}):a+=g(l);else if(A===f.CHAR_CLASS&&l!=="["&&l!=="[^")if(Z.test(l)&&(h===d.DEFAULT||h===d.RANGE||h===d.Q_TOKEN))o=!0;else{if(h===d.INVALID_INCOMPLETE_TOKEN)throw new Error(`Invalid incomplete token in character class: "${l}"`);if(Pe.test(l)&&(h===d.DEFAULT||h===d.Q_TOKEN))a+=g(l[1],{prefix:!1});else if(h===d.DEFAULT){let T=e[m+1]??"",S=G(l);(Z.test(T)||l==="^")&&(S=j(S)),a+=g(S)}else a+=g(l)}else a+=g(l);r||o||i||(u=l,c=h)}return{transformed:a,runningContext:t}}function pe(e){let t=String.raw`\(\?:\)`;e=N(e,`(?:${t}){2,}`,"(?:)",E.DEFAULT);let n=C.replace(/\$/g,"\\$");return e=N(e,String.raw`(?:${t}(?=[)|.[$\\]|\((?!DEFINE)|$)|(?<=[()|.\]^>]|\\[bBdDfnrsStvwW]|\(\?(?:[:=!]|<[=!])|^)${t}(?![?*+{]))(?!${n})`,"",E.DEFAULT),e}var Ee=new RegExp(String.raw`(?<noncapturingStart>${D})|(?<capturingStart>\((?:\?<[^>]+>)?)|\\?.`,"gsu");function de(e,t){if(!/\(\?>/.test(e))return e;let n="(?>",r=`(?:(?=(${t.useEmulationGroups?C:""}`,o=[0],i=0,s=0,a=NaN,u;do{u=!1;let c=0,p=0,g=!1,l;for(Ee.lastIndex=Number.isNaN(a)?0:a+r.length;l=Ee.exec(e);){let{0:m,index:A,groups:{capturingStart:h,noncapturingStart:T}}=l;if(m==="[")c++;else if(c)m==="]"&&c--;else if(m===n&&!g)a=A,g=!0;else if(g&&T)p++;else if(h)g?p++:(i++,o.push(i+s));else if(m===")"&&g){if(!p){s++,e=`${e.slice(0,a)}${r}${e.slice(a+n.length,A)}))<$$${s+i}>)${e.slice(A+1)}`,u=!0;break}p--}}}while(u);return e=N(e,String.raw`\\(?<backrefNum>[1-9]\d*)|<\$\$(?<wrappedBackrefNum>\d+)>`,({0:c,groups:{backrefNum:p,wrappedBackrefNum:g}})=>{if(p){let l=+p;if(l>o.length-1)throw new Error(`Backref "${c}" greater than number of captures`);return`\\${o[l]}`}return`\\${g}`},E.DEFAULT),e}var ge=String.raw`(?:[?*+]|\{\d+(?:,\d*)?\})`,xe=new RegExp(String.raw`
\\(?: \d+

@@ -79,3 +79,3 @@ | c[A-Za-z]

| \\?.
`.replace(/\s+/g,""),"gsu");function we(e){let t='Invalid unescaped "-" in character class',n=!1,r="";for(let{0:o,groups:{dp:i,vOnlyEscape:s}}of e.matchAll(Qe)){if(o[0]==="["){if(n)throw new Error("Invalid nested character class when flag v not supported; possibly from interpolation");if(o.endsWith("-"))throw new Error(t);n=!0}else if(o.endsWith("]")){if(o[0]==="-")throw new Error(t);n=!1}else if(n){if(o==="&&"||o==="--")throw new Error(`Invalid set operator "${o}" when flag v not supported`);if(i)throw new Error(`Invalid double punctuator "${o}", reserved by flag v`);if("(){}/|".includes(o))throw new Error(`Invalid unescaped "${o}" in character class`);if(s){r+=s;continue}}r+=o}return r}var je=(e,...t)=>{if(Array.isArray(e?.raw))return ee({},e,...t);if((typeof e=="string"||e===void 0)&&!t.length)return ee.bind(null,{flags:e??""});if({}.toString.call(e)==="[object Object]"&&!t.length)return ee.bind(null,e);throw new Error(`Unexpected arguments: ${JSON.stringify([e,...t])}`)},ee=(e,t,...n)=>{let r=Se(e),o=Te(t,n,r),i=0,s="",a;if(o.template.raw.forEach((u,c)=>{let p=!!(o.template.raw[c]||o.template.raw[c+1]);i+=U(u),s+=G(u,E.CHAR_CLASS),a=D(s,a);let{regexContext:g,charClassContext:l}=a;if(c<o.template.raw.length-1){let m=o.substitutions[c];s+=He(m,r.flags,g,l,p,i),m instanceof RegExp?i+=U(m.source):m instanceof $&&(i+=U(String(m)))}}),s=$e(s,r),r.subclass){let u=Be(s);return new te(u.expression,r.flags,{captureMap:u.captureMap})}return new RegExp(s,r.flags)};function qe(e,t={}){let n=Se(t);if(n.subclass)throw new Error("Cannot use option subclass");return e===void 0&&(e=""),{expression:$e(Te({raw:[e]},[],n).template.raw[0],n),flags:n.flags}}function Se(e){let t={flags:"",subclass:!1,plugins:[],unicodeSetsPlugin:we,disable:{},force:{},...e};if(/[nuvx]/.test(t.flags))throw new Error("Implicit flags v/u/x/n cannot be explicitly added");let n=t.force.v||(t.disable.v?!1:oe);return t.flags+=n?"v":"u",t}function Te(e,t,n){let r=[];n.disable.x||r.push(fe),n.disable.n||r.push(le);for(let o of r)({template:e,substitutions:t}=ue(e,t,o,n));return{template:e,substitutions:t}}function $e(e,t){let{flags:n,plugins:r,unicodeSetsPlugin:o,disable:i,subclass:s}=t;return[...r,...i.subroutines?[]:[Ne],...i.atomic?[]:[me,de],...i.x?[]:[pe],...!o||n.includes("v")?[]:[o]].forEach(a=>e=a(e,{flags:n,useEmulationGroups:s})),e}var te=class e extends RegExp{#e;constructor(t,n,r){super(t,n),r?this.#e=r.captureMap:t instanceof e&&(this.#e=t.#e)}exec(t){let n=RegExp.prototype.exec.call(this,t);if(!n||!this.#e)return n;let r=[...n];n.length=1;for(let o=1;o<r.length;o++)this.#e[o]&&n.push(r[o]);return n}};function He(e,t,n,r,o,i){if(e instanceof RegExp&&n!==f.DEFAULT)throw new Error("Cannot interpolate a RegExp at this position because the syntax context does not match");if(n===f.INVALID_INCOMPLETE_TOKEN||r===d.INVALID_INCOMPLETE_TOKEN)throw new Error("Interpolation preceded by invalid incomplete token");let s=e instanceof $,a="";if(!(e instanceof RegExp)){e=String(e),s||(a=B(e,n===f.CHAR_CLASS?E.CHAR_CLASS:E.DEFAULT));let u=ie(a||e,n,r);if(u)throw new Error(`Unescaped stray "${u}" in the interpolated value would have side effects outside it`)}if(n===f.ENCLOSED_TOKEN||n===f.INTERVAL_QUANTIFIER||n===f.GROUP_NAME||r===d.ENCLOSED_TOKEN||r===d.Q_TOKEN)return s?String(e):a;if(n===f.CHAR_CLASS){if(s){if(v(String(e),"^-|^&&|-$|&&$"))throw new Error("Cannot use range or set operator at boundary of interpolated pattern; move the operation into the pattern or the operator outside of it");let u=se(j(e));return z(e)?`[${u}]`:G(u)}return z(a)?`[${a}]`:a}if(e instanceof RegExp){let u=We(e,t),c=ae(u.value,i);return u.usedModifier?c:`(?:${c})`}return s?`(?:${e})`:o?`(?:${a})`:a}function We(e,t){let n={i:null,m:null,s:null},r="\\n\\r\\u2028\\u2029",o=e.source;if(e.ignoreCase!==t.includes("i"))if(x)n.i=e.ignoreCase;else throw new Error("Pattern modifiers not supported, so flag i on the outer and interpolated regex must match");if(e.dotAll!==t.includes("s")&&(x?n.s=e.dotAll:o=N(o,"\\.",e.dotAll?"[^]":`[^${r}]`,E.DEFAULT)),e.multiline!==t.includes("m")&&(x?n.m=e.multiline:(o=N(o,"\\^",e.multiline?`(?<=^|[${r}])`:"(?<![^])",E.DEFAULT),o=N(o,"\\$",e.multiline?`(?=$|[${r}])`:"(?![^])",E.DEFAULT))),x){let i=Object.keys(n),s=i.filter(u=>n[u]===!0).join(""),a=i.filter(u=>n[u]===!1).join("");if(a&&(s+=`-${a}`),s)return{value:`(?${s}:${o})`,usedModifier:!0}}return{value:o}}function Be(e){let t=C.replace(/\$/g,"\\$"),n=[!0];return e=N(e,`(?:${O})(?<mark>${t})?`,({0:r,groups:{mark:o}})=>o?(n.push(!1),r.slice(0,-C.length)):(n.push(!0),r),E.DEFAULT),{captureMap:n,expression:e}}return Oe(ze);})();
`.replace(/\s+/g,""),"gsu");function we(e){let t='Invalid unescaped "-" in character class',n=!1,r="";for(let{0:o,groups:{dp:i,vOnlyEscape:s}}of e.matchAll(Qe)){if(o[0]==="["){if(n)throw new Error("Invalid nested character class when flag v not supported; possibly from interpolation");if(o.endsWith("-"))throw new Error(t);n=!0}else if(o.endsWith("]")){if(o[0]==="-")throw new Error(t);n=!1}else if(n){if(o==="&&"||o==="--")throw new Error(`Invalid set operator "${o}" when flag v not supported`);if(i)throw new Error(`Invalid double punctuator "${o}", reserved by flag v`);if("(){}/|".includes(o))throw new Error(`Invalid unescaped "${o}" in character class`);if(s){r+=s;continue}}r+=o}return r}var je=(e,...t)=>{if(Array.isArray(e?.raw))return ee({},e,...t);if((typeof e=="string"||e===void 0)&&!t.length)return ee.bind(null,{flags:e??""});if({}.toString.call(e)==="[object Object]"&&!t.length)return ee.bind(null,e);throw new Error(`Unexpected arguments: ${JSON.stringify([e,...t])}`)},ee=(e,t,...n)=>{let r=Se(e),o=Te(t,n,r),i=0,s="",a;if(o.template.raw.forEach((u,c)=>{let p=!!(o.template.raw[c]||o.template.raw[c+1]);i+=U(u),s+=G(u,E.CHAR_CLASS),a=R(s,a);let{regexContext:g,charClassContext:l}=a;if(c<o.template.raw.length-1){let m=o.substitutions[c];s+=He(m,r.flags,g,l,p,i),m instanceof RegExp?i+=U(m.source):m instanceof $&&(i+=U(String(m)))}}),s=$e(s,r),r.subclass){let u=Be(s);return new te(u.expression,r.flags,{captureMap:u.captureMap})}return new RegExp(s,r.flags)};function qe(e="",t={}){let n=Se(t);if(n.subclass)throw new Error("Cannot use option subclass");return{expression:$e(Te({raw:[e]},[],n).template.raw[0],n),flags:n.flags}}function Se(e){let t={flags:"",subclass:!1,plugins:[],unicodeSetsPlugin:we,disable:{},force:{},...e};if(/[nuvx]/.test(t.flags))throw new Error("Implicit flags v/u/x/n cannot be explicitly added");let n=t.force.v||(t.disable.v?!1:oe);return t.flags+=n?"v":"u",n&&(t.unicodeSetsPlugin=null),t}function Te(e,t,n){let r=[];n.disable.x||r.push(fe),n.disable.n||r.push(le);for(let o of r)({template:e,substitutions:t}=ue(e,t,o,n));return{template:e,substitutions:t}}function $e(e,t){let{flags:n,plugins:r,unicodeSetsPlugin:o,disable:i,subclass:s}=t;return[...r,...i.subroutines?[]:[Ne],...i.atomic?[]:[me,de],...i.x?[]:[pe],...o?[o]:[]].forEach(a=>e=a(e,{flags:n,useEmulationGroups:s})),e}var te=class e extends RegExp{#e;constructor(t,n,r){super(t,n),r?this.#e=r.captureMap:t instanceof e&&(this.#e=t.#e)}exec(t){let n=RegExp.prototype.exec.call(this,t);if(!n||!this.#e)return n;let r=[...n];n.length=1;for(let o=1;o<r.length;o++)this.#e[o]&&n.push(r[o]);return n}};function He(e,t,n,r,o,i){if(e instanceof RegExp&&n!==f.DEFAULT)throw new Error("Cannot interpolate a RegExp at this position because the syntax context does not match");if(n===f.INVALID_INCOMPLETE_TOKEN||r===d.INVALID_INCOMPLETE_TOKEN)throw new Error("Interpolation preceded by invalid incomplete token");let s=e instanceof $,a="";if(!(e instanceof RegExp)){e=String(e),s||(a=B(e,n===f.CHAR_CLASS?E.CHAR_CLASS:E.DEFAULT));let u=ie(a||e,n,r);if(u)throw new Error(`Unescaped stray "${u}" in the interpolated value would have side effects outside it`)}if(n===f.ENCLOSED_TOKEN||n===f.INTERVAL_QUANTIFIER||n===f.GROUP_NAME||r===d.ENCLOSED_TOKEN||r===d.Q_TOKEN)return s?String(e):a;if(n===f.CHAR_CLASS){if(s){if(v(String(e),"^-|^&&|-$|&&$"))throw new Error("Cannot use range or set operator at boundary of interpolated pattern; move the operation into the pattern or the operator outside of it");let u=se(j(e));return z(e)?`[${u}]`:G(u)}return z(a)?`[${a}]`:a}if(e instanceof RegExp){let u=We(e,t),c=ae(u.value,i);return u.usedModifier?c:`(?:${c})`}return s?`(?:${e})`:o?`(?:${a})`:a}function We(e,t){let n={i:null,m:null,s:null},r="\\n\\r\\u2028\\u2029",o=e.source;if(e.ignoreCase!==t.includes("i"))if(x)n.i=e.ignoreCase;else throw new Error("Pattern modifiers not supported, so flag i on the outer and interpolated regex must match");if(e.dotAll!==t.includes("s")&&(x?n.s=e.dotAll:o=N(o,"\\.",e.dotAll?"[^]":`[^${r}]`,E.DEFAULT)),e.multiline!==t.includes("m")&&(x?n.m=e.multiline:(o=N(o,"\\^",e.multiline?`(?<=^|[${r}])`:"(?<![^])",E.DEFAULT),o=N(o,"\\$",e.multiline?`(?=$|[${r}])`:"(?![^])",E.DEFAULT))),x){let i=Object.keys(n),s=i.filter(u=>n[u]===!0).join(""),a=i.filter(u=>n[u]===!1).join("");if(a&&(s+=`-${a}`),s)return{value:`(?${s}:${o})`,usedModifier:!0}}return{value:o}}function Be(e){let t=C.replace(/\$/g,"\\$"),n=[!0];return e=N(e,`(?:${O})(?<mark>${t})?`,({0:r,groups:{mark:o}})=>o?(n.push(!1),r.slice(0,-C.length)):(n.push(!0),r),E.DEFAULT),{captureMap:n,expression:e}}return Oe(ze);})();
//# sourceMappingURL=regex.min.js.map
{
"name": "regex",
"version": "4.2.1",
"version": "4.3.0",
"description": "Regex template tag with extended syntax, context-aware interpolation, and always-on best practices",

@@ -5,0 +5,0 @@ "author": "Steven Levithan",

@@ -121,3 +121,3 @@ <div align="center">

<script type="module">
import {regex, pattern} from 'https://cdn.jsdelivr.net/npm/regex@4.2.1/+esm';
import {regex, pattern} from 'https://cdn.jsdelivr.net/npm/regex@4.3.0/+esm';
// …

@@ -131,3 +131,3 @@ </script>

```html
<script src="https://cdn.jsdelivr.net/npm/regex@4.2.1/dist/regex.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/regex@4.3.0/dist/regex.min.js"></script>
<script>

@@ -830,6 +830,6 @@ const {regex, pattern} = Regex;

`regex` was crafted by [Steven Levithan](https://github.com/slevithan) and [contributors](https://github.com/slevithan/regex/graphs/contributors), with love for regular expressions and their enthusiasts. Inspiration included [PCRE](https://github.com/PCRE2Project/pcre2), [XRegExp](https://github.com/slevithan/xregexp), and [regexp-make-js](https://github.com/mikesamuel/regexp-make-js).
`regex` was created by [Steven Levithan](https://github.com/slevithan) and [contributors](https://github.com/slevithan/regex/graphs/contributors). Inspiration included [PCRE](https://github.com/PCRE2Project/pcre2), [XRegExp](https://github.com/slevithan/xregexp), and [regexp-make-js](https://github.com/mikesamuel/regexp-make-js).
If you want to support this project, I'd love your help by contributing improvements, sharing it with others, or [sponsoring](https://github.com/sponsors/slevithan) future development.
MIT License.
© 2024–present. MIT License.

@@ -87,3 +87,3 @@ export type InterpolatedValue = string | RegExp | Pattern | number;

*/
export function rewrite(expression: string, options?: RegexTagOptions): {
export function rewrite(expression?: string, options?: RegexTagOptions): {
expression: string;

@@ -104,2 +104,2 @@ flags: string;

}
export { pattern, rewrite as processRegex };
export { pattern };

@@ -11,3 +11,3 @@ /**

/**
Converts `\0` tokens to `\u{0}` in the given context.
Converts `\0` tokens to `\x00` in the given context.
@param {string} str

@@ -14,0 +14,0 @@ @param {'DEFAULT' | 'CHAR_CLASS'} [context] `Context` option from lib `regex-utilities`

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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