string-match-left-right 9.2.0 → 9.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name string-match-left-right
|
|
3
3
|
* @fileoverview Match substrings on the left or right of a given index, ignoring whitespace
|
|
4
|
-
* @version 9.2.
|
|
4
|
+
* @version 9.2.1
|
|
5
5
|
* @author Roy Revelt
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/string-match-left-right/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import{arrayiffy as N}from"arrayiffy-if-string";import{formatDiagnosticValue as O,hasOwnProp as L,isPlainObject as R,isStr as T}from"codsen-utils";var w="9.2.
|
|
10
|
+
import{arrayiffy as N}from"arrayiffy-if-string";import{formatDiagnosticValue as O,hasOwnProp as L,isPlainObject as R,isStr as T}from"codsen-utils";var w="9.2.1";var H=w,S={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},A=e=>e+1;function I(e,s,n,a,u=!1,r=A){let i=typeof n=="function"?n():n;if(+s<0&&u&&i==="EOL")return i;let o={...S,...a};if(s>=e.length&&!u)return!1;let c=u?1:n.length,E=0,h=!1,l=!1,g=!1,b=o.maxMismatches,t=s,$=!1,f=!1,m=!1;function D(){return E===1&&b<o.maxMismatches-1}for(;e[t];){let p=r(t);if(o.trimBeforeMatching&&e[t].trim()===""){if(!e[p]&&u&&n==="EOL")return!0;t=r(t);continue}if(o&&!o.i&&o?.trimCharsBeforeMatching?.includes(e[t])||o?.i&&o.trimCharsBeforeMatching&&o.trimCharsBeforeMatching.map(d=>d.toLowerCase()).includes(e[t].toLowerCase())){if(u&&n==="EOL"&&!e[p])return!0;t=r(t);continue}let M=p>t?n[n.length-c]:n[c-1];if(!o.i&&e[t]===M||o.i&&M!==void 0&&e[t].toLowerCase()===M.toLowerCase()){if($||($=!0),g||(g=!0),c===n.length){if(f=!0,b!==o.maxMismatches)return!1}else c===1&&(m=!0);if(c-=1,E++,D())return!1;if(!c)return E!==n.length||b===o.maxMismatches||!h?t:!1}else if(!h&&!E&&(h=!0),o.maxMismatches&&b&&t){b-=1;for(let d=0;d<=b;d++){let C=p>t?n[n.length-c+1+d]:n[c-2-d],y=e[r(t)];if(C&&(!o.i&&e[t]===C||o.i&&e[t].toLowerCase()===C.toLowerCase())&&(!o.firstMustMatch||c!==n.length)){if(E++,D())return!1;c-=2,$=!0;break}else if(y&&C&&(!o.i&&y===C||o.i&&y.toLowerCase()===C.toLowerCase())&&(!o.firstMustMatch||c!==n.length)){if(!E&&!o.hungry)return!1;c-=1,$=!0;break}else if(C===void 0&&b>=0&&$&&(!o.firstMustMatch||f)&&(!o.lastMustMatch||m))return t}$||(l=t)}else return t===0&&c===1&&!o.lastMustMatch&&g?0:!1;if(l!==!1&&l!==t&&(l=!1),c<1)return t;t=r(t)}if(c>0)return u&&i==="EOL"?!0:o&&o.maxMismatches>=c&&g?l||0:!1}function V(e,s,n,a,u){if(R(u)&&L(u,"trimBeforeMatching")&&u&&typeof u.trimBeforeMatching!="boolean")throw new Error(`string-match-left-right/${e}(): [THROW_ID_01] opts.trimBeforeMatching should be boolean!${Array.isArray(u.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""}`);let r={...S,...u};if(typeof r.trimCharsBeforeMatching=="string"&&(r.trimCharsBeforeMatching=N(r.trimCharsBeforeMatching)),r.trimCharsBeforeMatching=r.trimCharsBeforeMatching.map(h=>T(h)?h:String(h)),!T(s)||!s.length)return!1;if(!Number.isInteger(n)||n<0)throw new Error(`string-match-left-right/${e}(): [THROW_ID_02] the second argument should be a natural number. Currently it's of a type: ${typeof n}, equal to:
|
|
11
11
|
${O(n,4)}`);let i,o;if(T(a))i=[a];else if(Array.isArray(a))i=a;else if(!a)i=a;else if(typeof a=="function")i=[],i.push(a);else throw new Error(`string-match-left-right/${e}(): [THROW_ID_03] the third argument, whatToMatch, is neither string nor array of strings! It's ${typeof a}, equal to:
|
|
12
12
|
${O(a,4)}`);if(u&&!R(u))throw new Error(`string-match-left-right/${e}(): [THROW_ID_04] the fourth argument, options object, should be a plain object. Currently it's of a type "${typeof u}", and equal to:
|
|
13
13
|
${O(u,4)}`);let c=0,E="";if(r?.trimCharsBeforeMatching?.some((h,l)=>h.length>1?(c=l,E=h,!0):!1))throw new Error(`string-match-left-right/${e}(): [THROW_ID_05] the fourth argument, options object contains trimCharsBeforeMatching. It was meant to list the single characters but one of the entries at index ${c} is longer than 1 character, ${E.length} (equals to ${E}). Please split it into separate characters and put into array as separate elements.`);if(!i||!Array.isArray(i)||Array.isArray(i)&&!i.length||Array.isArray(i)&&i.length===1&&T(i[0])&&!i[0].trim()){if(typeof r.cb=="function"){let l,g=n;if((e==="matchLeftIncl"||e==="matchRight")&&(g+=1),e[5]==="L")for(let f=g;f--;){let m=s[f];if((!r.trimBeforeMatching||r.trimBeforeMatching&&m?.trim())&&(!r.trimCharsBeforeMatching?.length||m!==void 0&&!r.trimCharsBeforeMatching.includes(m))){l=f;break}}else if(e.startsWith("matchRight"))for(let f=g;f<s.length;f++){let m=s[f];if((!r.trimBeforeMatching||r.trimBeforeMatching&&m.trim())&&(!r.trimCharsBeforeMatching?.length||!r.trimCharsBeforeMatching.includes(m))){l=f;break}}if(l===void 0)return!1;let b=s[l],t=l+1,$="";return t&&t>0&&($=s.slice(0,t)),e[5]==="L"||l&&l>0&&($=s.slice(l)),r.cb(b,$,l)}let h="";throw u||(h=" More so, the whole options object, the fourth input argument, is missing!"),new Error(`string-match-left-right/${e}(): [THROW_ID_06] the third argument, "whatToMatch", was given as an empty string. This means, you intend to match purely by a callback. The callback was not set though, the opts key "cb" is not set!${h}`)}for(let h=0,l=i.length;h<l;h++){o=typeof i[h]=="function";let g=i[h],b,t,$="",f=n;e==="matchRight"?f+=1:e==="matchLeft"&&(f-=1);let m=I(s,f,g,r,o,D=>e[5]==="L"?D-1:D+1);if(m&&o&&typeof g=="function"&&g()==="EOL")return g()&&(!r.cb||r.cb(b,$,t))?g():!1;if(Number.isInteger(m)&&(t=e.startsWith("matchLeft")?m-1:m+1,e[5]==="L"?$=s.slice(0,m):$=s.slice(t)),t<0&&(t=void 0),s[t]&&(b=s[t]),Number.isInteger(m)&&(!r.cb||r.cb(b,$,t)))return g}return!1}function j(e,s,n,a){return V("matchLeftIncl",e,s,n,a)}function P(e,s,n,a){return V("matchLeft",e,s,n,a)}function v(e,s,n,a){return V("matchRightIncl",e,s,n,a)}function U(e,s,n,a){return V("matchRight",e,s,n,a)}export{A as defaultGetNextIdx,S as defaults,P as matchLeft,j as matchLeftIncl,U as matchRight,v as matchRightIncl,H as version};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name string-match-left-right
|
|
3
3
|
* @fileoverview Match substrings on the left or right of a given index, ignoring whitespace
|
|
4
|
-
* @version 9.2.
|
|
4
|
+
* @version 9.2.1
|
|
5
5
|
* @author Roy Revelt
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/string-match-left-right/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
"use strict";var stringMatchLeftRight=(()=>{var w=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames,L=Object.getOwnPropertySymbols;var B=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable;var N=(e,r,t)=>r in e?w(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,V=(e,r)=>{for(var t in r||(r={}))B.call(r,t)&&N(e,t,r[t]);if(L)for(var t of L(r))_.call(r,t)&&N(e,t,r[t]);return e};var q=(e,r)=>{for(var t in r)w(e,t,{get:r[t],enumerable:!0})},Q=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of H(r))!B.call(e,a)&&a!==t&&w(e,a,{get:()=>r[a],enumerable:!(o=J(r,a))||o.enumerable});return e};var Y=e=>Q(w({},"__esModule",{value:!0}),e);var ie={};q(ie,{defaultGetNextIdx:()=>U,defaults:()=>x,matchLeft:()=>re,matchLeftIncl:()=>ne,matchRight:()=>se,matchRightIncl:()=>oe,version:()=>ee});function I(e){return typeof e!="string"?e:e.length?[e]:[]}function G(){let e=[],r=0,t=!1;return{append(o){return t?!1:r+o.length>1999?(e.push("\u2026"),r+=1,t=!0,!1):(e.push(o),r+=o.length,!0)},result(){return e.join("")},stopped(){return t}}}function K(e){return"\\u".concat(e.toString(16).padStart(4,"0"))}function A(e,r){if(e.append('"')){for(let t=0;t<r.length&&!e.stopped();t+=1){let o=r.charCodeAt(t);o===34?e.append('\\"'):o===92?e.append("\\\\"):o===8?e.append("\\b"):o===9?e.append("\\t"):o===10?e.append("\\n"):o===12?e.append("\\f"):o===13?e.append("\\r"):o<32||o===8232||o===8233||o>=55296&&o<=57343?e.append(K(o)):e.append(r[t])}e.append('"')}}function z(e){return e.get&&e.set?"[Getter/Setter]":e.get?"[Getter]":e.set?"[Setter]":"[Accessor]"}function W(e,r){e.append("Symbol(");let t=String(r);t.length>8&&A(e,t.slice(7,-1)),e.append(")")}function j(e,r){typeof r=="symbol"?W(e,r):A(e,String(r))}function O(e,r=0){let t=G(),o=r===4?4:0,a=new WeakSet,l=0;function h(n){o&&t.append(" ".repeat(n*o))}function s(n,i){n&&t.append(","),o&&(t.append("\n"),h(i+1))}function m(n,i,$){o&&i&&(t.append("\n"),h($)),t.append(n)}function b(n,i){Object.prototype.hasOwnProperty.call(n,"value")?c(n.value,i):t.append(z(n))}function C(n,i){let $;try{$=Reflect.getOwnPropertyDescriptor(n,"length")}catch(g){t.append("[Uninspectable]");return}let u=$==null?void 0:$.value;if(!Number.isSafeInteger(u)||u<0){t.append("[Uninspectable]");return}t.append("[");let p=!1;for(let g=0;g<u&&!t.stopped();g+=1){if(s(p,i),p=!0,l>=50){t.append("[MaxEntries]");break}l+=1;let f;try{f=Reflect.getOwnPropertyDescriptor(n,String(g))}catch(E){t.append("[Uninspectable]");continue}f!=null&&f.enumerable?b(f,i+1):t.append("[Empty]")}m("]",p,i)}function d(n,i){let $;try{$=Reflect.ownKeys(n)}catch(p){t.append("[Uninspectable]");return}t.append("{");let u=!1;for(let p of $){if(t.stopped())break;if(l>=50){s(u,i),u=!0,A(t,"\u2026"),t.append(o?": ":":"),t.append("[MaxEntries]");break}l+=1;let g;try{g=Reflect.getOwnPropertyDescriptor(n,p)}catch(f){s(u,i),u=!0,j(t,p),t.append(o?": ":":"),t.append("[Uninspectable]");continue}g!=null&&g.enumerable&&(s(u,i),u=!0,j(t,p),t.append(o?": ":":"),b(g,i+1))}m("}",u,i)}function y(n,i){if(a.has(n)){t.append("[Circular]");return}if(i>=5){t.append("[MaxDepth]");return}let $;try{$=Array.isArray(n)}catch(u){t.append("[Uninspectable]");return}a.add(n);try{$?C(n,i):d(n,i)}finally{a.delete(n)}}function c(n,i){n===null?t.append("null"):typeof n=="string"?A(t,n):typeof n=="number"?t.append(Object.is(n,-0)?"-0":String(n)):typeof n=="boolean"?t.append(n?"true":"false"):typeof n>"u"?t.append("undefined"):typeof n=="bigint"?t.append("".concat(n,"n")):typeof n=="symbol"?W(t,n):typeof n=="function"?t.append("[Function]"):y(n,i)}try{return c(e,0),t.result()}catch(n){return"[Uninspectable]"}}var ce=new Set([..."\u060B$\u20BC\u17DB\xA5\u20A1\u20B1\xA3\u20AC\xA2\u20B9\uFDFC\u20AA\u20A9\u20AD\u20A8\u20AE\u20A6\u20BD\u20AB\u0E3F\u20A9\u20BA\u20B4","$U","$b","B/.","BZ$","Br","Bs","C$","CHF","Ft","Gs","J$","KM","K\u010D","L","MT","NT$","P","Q","R","R$","RD$","RM","Rp","S","S/.","TT$","Z$","kn","kr","lei","z\u0142","\u0192","\u0414\u0438\u043D.","\u0434\u0435\u043D","\u043B\u0432","\u062F.\u0625","Lek"]),Z=Object.prototype.hasOwnProperty;function S(e){if(e==null||typeof e!="object")return!1;let r=Object.getPrototypeOf(e);return r!==null&&r!==Object.prototype&&Object.getPrototypeOf(r)!==null?!1:!(Symbol.iterator in e)&&!(Symbol.toStringTag in e)}function T(e){return typeof e=="string"}function F(e,r){return S(e)&&T(r)&&Z.call(e,r)}var P="9.2.
|
|
10
|
+
"use strict";var stringMatchLeftRight=(()=>{var w=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames,L=Object.getOwnPropertySymbols;var B=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable;var N=(e,r,t)=>r in e?w(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,V=(e,r)=>{for(var t in r||(r={}))B.call(r,t)&&N(e,t,r[t]);if(L)for(var t of L(r))_.call(r,t)&&N(e,t,r[t]);return e};var q=(e,r)=>{for(var t in r)w(e,t,{get:r[t],enumerable:!0})},Q=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of H(r))!B.call(e,a)&&a!==t&&w(e,a,{get:()=>r[a],enumerable:!(o=J(r,a))||o.enumerable});return e};var Y=e=>Q(w({},"__esModule",{value:!0}),e);var ie={};q(ie,{defaultGetNextIdx:()=>U,defaults:()=>x,matchLeft:()=>re,matchLeftIncl:()=>ne,matchRight:()=>se,matchRightIncl:()=>oe,version:()=>ee});function I(e){return typeof e!="string"?e:e.length?[e]:[]}function G(){let e=[],r=0,t=!1;return{append(o){return t?!1:r+o.length>1999?(e.push("\u2026"),r+=1,t=!0,!1):(e.push(o),r+=o.length,!0)},result(){return e.join("")},stopped(){return t}}}function K(e){return"\\u".concat(e.toString(16).padStart(4,"0"))}function A(e,r){if(e.append('"')){for(let t=0;t<r.length&&!e.stopped();t+=1){let o=r.charCodeAt(t);o===34?e.append('\\"'):o===92?e.append("\\\\"):o===8?e.append("\\b"):o===9?e.append("\\t"):o===10?e.append("\\n"):o===12?e.append("\\f"):o===13?e.append("\\r"):o<32||o===8232||o===8233||o>=55296&&o<=57343?e.append(K(o)):e.append(r[t])}e.append('"')}}function z(e){return e.get&&e.set?"[Getter/Setter]":e.get?"[Getter]":e.set?"[Setter]":"[Accessor]"}function W(e,r){e.append("Symbol(");let t=String(r);t.length>8&&A(e,t.slice(7,-1)),e.append(")")}function j(e,r){typeof r=="symbol"?W(e,r):A(e,String(r))}function O(e,r=0){let t=G(),o=r===4?4:0,a=new WeakSet,l=0;function h(n){o&&t.append(" ".repeat(n*o))}function s(n,i){n&&t.append(","),o&&(t.append("\n"),h(i+1))}function m(n,i,$){o&&i&&(t.append("\n"),h($)),t.append(n)}function b(n,i){Object.prototype.hasOwnProperty.call(n,"value")?c(n.value,i):t.append(z(n))}function C(n,i){let $;try{$=Reflect.getOwnPropertyDescriptor(n,"length")}catch(g){t.append("[Uninspectable]");return}let u=$==null?void 0:$.value;if(!Number.isSafeInteger(u)||u<0){t.append("[Uninspectable]");return}t.append("[");let p=!1;for(let g=0;g<u&&!t.stopped();g+=1){if(s(p,i),p=!0,l>=50){t.append("[MaxEntries]");break}l+=1;let f;try{f=Reflect.getOwnPropertyDescriptor(n,String(g))}catch(E){t.append("[Uninspectable]");continue}f!=null&&f.enumerable?b(f,i+1):t.append("[Empty]")}m("]",p,i)}function d(n,i){let $;try{$=Reflect.ownKeys(n)}catch(p){t.append("[Uninspectable]");return}t.append("{");let u=!1;for(let p of $){if(t.stopped())break;if(l>=50){s(u,i),u=!0,A(t,"\u2026"),t.append(o?": ":":"),t.append("[MaxEntries]");break}l+=1;let g;try{g=Reflect.getOwnPropertyDescriptor(n,p)}catch(f){s(u,i),u=!0,j(t,p),t.append(o?": ":":"),t.append("[Uninspectable]");continue}g!=null&&g.enumerable&&(s(u,i),u=!0,j(t,p),t.append(o?": ":":"),b(g,i+1))}m("}",u,i)}function y(n,i){if(a.has(n)){t.append("[Circular]");return}if(i>=5){t.append("[MaxDepth]");return}let $;try{$=Array.isArray(n)}catch(u){t.append("[Uninspectable]");return}a.add(n);try{$?C(n,i):d(n,i)}finally{a.delete(n)}}function c(n,i){n===null?t.append("null"):typeof n=="string"?A(t,n):typeof n=="number"?t.append(Object.is(n,-0)?"-0":String(n)):typeof n=="boolean"?t.append(n?"true":"false"):typeof n>"u"?t.append("undefined"):typeof n=="bigint"?t.append("".concat(n,"n")):typeof n=="symbol"?W(t,n):typeof n=="function"?t.append("[Function]"):y(n,i)}try{return c(e,0),t.result()}catch(n){return"[Uninspectable]"}}var ce=new Set([..."\u060B$\u20BC\u17DB\xA5\u20A1\u20B1\xA3\u20AC\xA2\u20B9\uFDFC\u20AA\u20A9\u20AD\u20A8\u20AE\u20A6\u20BD\u20AB\u0E3F\u20A9\u20BA\u20B4","$U","$b","B/.","BZ$","Br","Bs","C$","CHF","Ft","Gs","J$","KM","K\u010D","L","MT","NT$","P","Q","R","R$","RD$","RM","Rp","S","S/.","TT$","Z$","kn","kr","lei","z\u0142","\u0192","\u0414\u0438\u043D.","\u0434\u0435\u043D","\u043B\u0432","\u062F.\u0625","Lek"]),Z=Object.prototype.hasOwnProperty;function S(e){if(e==null||typeof e!="object")return!1;let r=Object.getPrototypeOf(e);return r!==null&&r!==Object.prototype&&Object.getPrototypeOf(r)!==null?!1:!(Symbol.iterator in e)&&!(Symbol.toStringTag in e)}function T(e){return typeof e=="string"}function F(e,r){return S(e)&&T(r)&&Z.call(e,r)}var P="9.2.1";var ee=P,x={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},U=e=>e+1;function te(e,r,t,o,a=!1,l=U){var f;let h=typeof t=="function"?t():t;if(+r<0&&a&&h==="EOL")return h;let s=V(V({},x),o);if(r>=e.length&&!a)return!1;let m=a?1:t.length,b=0,C=!1,d=!1,y=!1,c=s.maxMismatches,n=r,i=!1,$=!1,u=!1;function p(){return b===1&&c<s.maxMismatches-1}for(;e[n];){let E=l(n);if(s.trimBeforeMatching&&e[n].trim()===""){if(!e[E]&&a&&t==="EOL")return!0;n=l(n);continue}if(s&&!s.i&&((f=s==null?void 0:s.trimCharsBeforeMatching)!=null&&f.includes(e[n]))||s!=null&&s.i&&s.trimCharsBeforeMatching&&s.trimCharsBeforeMatching.map(M=>M.toLowerCase()).includes(e[n].toLowerCase())){if(a&&t==="EOL"&&!e[E])return!0;n=l(n);continue}let R=E>n?t[t.length-m]:t[m-1];if(!s.i&&e[n]===R||s.i&&R!==void 0&&e[n].toLowerCase()===R.toLowerCase()){if(i||(i=!0),y||(y=!0),m===t.length){if($=!0,c!==s.maxMismatches)return!1}else m===1&&(u=!0);if(m-=1,b++,p())return!1;if(!m)return b!==t.length||c===s.maxMismatches||!C?n:!1}else if(!C&&!b&&(C=!0),s.maxMismatches&&c&&n){c-=1;for(let M=0;M<=c;M++){let D=E>n?t[t.length-m+1+M]:t[m-2-M],v=e[l(n)];if(D&&(!s.i&&e[n]===D||s.i&&e[n].toLowerCase()===D.toLowerCase())&&(!s.firstMustMatch||m!==t.length)){if(b++,p())return!1;m-=2,i=!0;break}else if(v&&D&&(!s.i&&v===D||s.i&&v.toLowerCase()===D.toLowerCase())&&(!s.firstMustMatch||m!==t.length)){if(!b&&!s.hungry)return!1;m-=1,i=!0;break}else if(D===void 0&&c>=0&&i&&(!s.firstMustMatch||$)&&(!s.lastMustMatch||u))return n}i||(d=n)}else return n===0&&m===1&&!s.lastMustMatch&&y?0:!1;if(d!==!1&&d!==n&&(d=!1),m<1)return n;n=l(n)}if(m>0)return a&&h==="EOL"?!0:s&&s.maxMismatches>=m&&y?d||0:!1}function k(e,r,t,o,a){var C,d,y;if(S(a)&&F(a,"trimBeforeMatching")&&a&&typeof a.trimBeforeMatching!="boolean")throw new Error("string-match-left-right/".concat(e,"(): [THROW_ID_01] opts.trimBeforeMatching should be boolean!").concat(Array.isArray(a.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""));let l=V(V({},x),a);if(typeof l.trimCharsBeforeMatching=="string"&&(l.trimCharsBeforeMatching=I(l.trimCharsBeforeMatching)),l.trimCharsBeforeMatching=l.trimCharsBeforeMatching.map(c=>T(c)?c:String(c)),!T(r)||!r.length)return!1;if(!Number.isInteger(t)||t<0)throw new Error("string-match-left-right/".concat(e,"(): [THROW_ID_02] the second argument should be a natural number. Currently it's of a type: ").concat(typeof t,", equal to:\n").concat(O(t,4)));let h,s;if(T(o))h=[o];else if(Array.isArray(o))h=o;else if(!o)h=o;else if(typeof o=="function")h=[],h.push(o);else throw new Error("string-match-left-right/".concat(e,"(): [THROW_ID_03] the third argument, whatToMatch, is neither string nor array of strings! It's ").concat(typeof o,", equal to:\n").concat(O(o,4)));if(a&&!S(a))throw new Error("string-match-left-right/".concat(e,"(): [THROW_ID_04] the fourth argument, options object, should be a plain object. Currently it's of a type \"").concat(typeof a,'", and equal to:\n').concat(O(a,4)));let m=0,b="";if((C=l==null?void 0:l.trimCharsBeforeMatching)!=null&&C.some((c,n)=>c.length>1?(m=n,b=c,!0):!1))throw new Error("string-match-left-right/".concat(e,"(): [THROW_ID_05] the fourth argument, options object contains trimCharsBeforeMatching. It was meant to list the single characters but one of the entries at index ").concat(m," is longer than 1 character, ").concat(b.length," (equals to ").concat(b,"). Please split it into separate characters and put into array as separate elements."));if(!h||!Array.isArray(h)||Array.isArray(h)&&!h.length||Array.isArray(h)&&h.length===1&&T(h[0])&&!h[0].trim()){if(typeof l.cb=="function"){let n,i=t;if((e==="matchLeftIncl"||e==="matchRight")&&(i+=1),e[5]==="L")for(let g=i;g--;){let f=r[g];if((!l.trimBeforeMatching||l.trimBeforeMatching&&(f!=null&&f.trim()))&&(!((d=l.trimCharsBeforeMatching)!=null&&d.length)||f!==void 0&&!l.trimCharsBeforeMatching.includes(f))){n=g;break}}else if(e.startsWith("matchRight"))for(let g=i;g<r.length;g++){let f=r[g];if((!l.trimBeforeMatching||l.trimBeforeMatching&&f.trim())&&(!((y=l.trimCharsBeforeMatching)!=null&&y.length)||!l.trimCharsBeforeMatching.includes(f))){n=g;break}}if(n===void 0)return!1;let $=r[n],u=n+1,p="";return u&&u>0&&(p=r.slice(0,u)),e[5]==="L"||n&&n>0&&(p=r.slice(n)),l.cb($,p,n)}let c="";throw a||(c=" More so, the whole options object, the fourth input argument, is missing!"),new Error("string-match-left-right/".concat(e,'(): [THROW_ID_06] the third argument, "whatToMatch", was given as an empty string. This means, you intend to match purely by a callback. The callback was not set though, the opts key "cb" is not set!').concat(c))}for(let c=0,n=h.length;c<n;c++){s=typeof h[c]=="function";let i=h[c],$,u,p="",g=t;e==="matchRight"?g+=1:e==="matchLeft"&&(g-=1);let f=te(r,g,i,l,s,E=>e[5]==="L"?E-1:E+1);if(f&&s&&typeof i=="function"&&i()==="EOL")return i()&&(!l.cb||l.cb($,p,u))?i():!1;if(Number.isInteger(f)&&(u=e.startsWith("matchLeft")?f-1:f+1,e[5]==="L"?p=r.slice(0,f):p=r.slice(u)),u<0&&(u=void 0),r[u]&&($=r[u]),Number.isInteger(f)&&(!l.cb||l.cb($,p,u)))return i}return!1}function ne(e,r,t,o){return k("matchLeftIncl",e,r,t,o)}function re(e,r,t,o){return k("matchLeft",e,r,t,o)}function oe(e,r,t,o){return k("matchRightIncl",e,r,t,o)}function se(e,r,t,o){return k("matchRight",e,r,t,o)}return Y(ie);})();
|
|
11
11
|
/**
|
|
12
12
|
* @name arrayiffy-if-string
|
|
13
13
|
* @fileoverview Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else.
|
|
14
|
-
* @version 5.2.
|
|
14
|
+
* @version 5.2.1
|
|
15
15
|
* @author Roy Revelt
|
|
16
16
|
* @license MIT
|
|
17
17
|
* {@link https://codsen.com/os/arrayiffy-if-string/}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "string-match-left-right",
|
|
3
|
-
"version": "9.2.
|
|
3
|
+
"version": "9.2.1",
|
|
4
4
|
"description": "Match substrings on the left or right of a given index, ignoring whitespace",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"left",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"arrayiffy-if-string": "^5.2.
|
|
67
|
+
"arrayiffy-if-string": "^5.2.1",
|
|
68
68
|
"codsen-utils": "^1.8.0"
|
|
69
69
|
},
|
|
70
70
|
"engines": {
|