string-match-left-right 9.0.13 → 9.0.14

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.0.13
4
+ * @version 9.0.14
5
5
  * @author Roy Revelt, Codsen Ltd
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{isPlainObject as R,isStr as d,hasOwnProp as k}from"codsen-utils";var O="9.0.13";var F=O,w={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},L=t=>t+1;function A(t,s,n,a,u=!1,o=L){let l=typeof n=="function"?n():n;if(+s<0&&u&&l==="EOL")return l;let r={...w,...a};if(s>=t.length&&!u)return!1;let c=u?1:n.length,E=0,h=!1,i=!1,g=!1,b=r.maxMismatches,e=s,m=!1,f=!1,$=!1;function p(){return E===1&&b<r.maxMismatches-1}for(;t[e];){let T=o(e);if(r.trimBeforeMatching&&t[e].trim()===""){if(!t[T]&&u&&n==="EOL")return!0;e=o(e);continue}if(r&&!r.i&&r.trimCharsBeforeMatching&&r.trimCharsBeforeMatching.includes(t[e])||r?.i&&r.trimCharsBeforeMatching&&r.trimCharsBeforeMatching.map(D=>D.toLowerCase()).includes(t[e].toLowerCase())){if(u&&n==="EOL"&&!t[T])return!0;e=o(e);continue}let y=T>e?n[n.length-c]:n[c-1];if(!r.i&&t[e]===y||r.i&&t[e].toLowerCase()===y.toLowerCase()){if(m||(m=!0),g||(g=!0),c===n.length){if(f=!0,b!==r.maxMismatches)return!1}else c===1&&($=!0);if(c-=1,E++,p())return!1;if(!c)return E!==n.length||b===r.maxMismatches||!h?e:!1}else if(!h&&!E&&(h=!0),r.maxMismatches&&b&&e){b-=1;for(let D=0;D<=b;D++){let C=T>e?n[n.length-c+1+D]:n[c-2-D],M=t[o(e)];if(C&&(!r.i&&t[e]===C||r.i&&t[e].toLowerCase()===C.toLowerCase())&&(!r.firstMustMatch||c!==n.length)){if(E++,p())return!1;c-=2,m=!0;break}else if(M&&C&&(!r.i&&M===C||r.i&&M.toLowerCase()===C.toLowerCase())&&(!r.firstMustMatch||c!==n.length)){if(!E&&!r.hungry)return!1;c-=1,m=!0;break}else if(C===void 0&&b>=0&&m&&(!r.firstMustMatch||f)&&(!r.lastMustMatch||$))return e}m||(i=e)}else return e===0&&c===1&&!r.lastMustMatch&&g?0:!1;if(i!==!1&&i!==e&&(i=!1),c<1)return e;e=o(e)}if(c>0)return u&&l==="EOL"?!0:r&&r.maxMismatches>=c&&g?i||0:!1}function V(t,s,n,a,u){if(R(u)&&k(u,"trimBeforeMatching")&&u&&typeof u.trimBeforeMatching!="boolean")throw new Error(`string-match-left-right/${t}(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!${Array.isArray(u.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""}`);let o={...w,...u};if(typeof o.trimCharsBeforeMatching=="string"&&(o.trimCharsBeforeMatching=N(o.trimCharsBeforeMatching)),o.trimCharsBeforeMatching=o.trimCharsBeforeMatching.map(h=>d(h)?h:String(h)),!d(s)||!s.length)return!1;if(!Number.isInteger(n)||n<0)throw new Error(`string-match-left-right/${t}(): [THROW_ID_03] the second argument should be a natural number. Currently it's of a type: ${typeof n}, equal to:
10
+ import{arrayiffy as N}from"arrayiffy-if-string";import{isPlainObject as R,isStr as d,hasOwnProp as k}from"codsen-utils";var O="9.0.14";var F=O,w={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},L=t=>t+1;function A(t,s,n,a,u=!1,o=L){let l=typeof n=="function"?n():n;if(+s<0&&u&&l==="EOL")return l;let r={...w,...a};if(s>=t.length&&!u)return!1;let c=u?1:n.length,E=0,h=!1,i=!1,g=!1,b=r.maxMismatches,e=s,$=!1,f=!1,m=!1;function p(){return E===1&&b<r.maxMismatches-1}for(;t[e];){let T=o(e);if(r.trimBeforeMatching&&t[e].trim()===""){if(!t[T]&&u&&n==="EOL")return!0;e=o(e);continue}if(r&&!r.i&&r.trimCharsBeforeMatching&&r.trimCharsBeforeMatching.includes(t[e])||r?.i&&r.trimCharsBeforeMatching&&r.trimCharsBeforeMatching.map(D=>D.toLowerCase()).includes(t[e].toLowerCase())){if(u&&n==="EOL"&&!t[T])return!0;e=o(e);continue}let y=T>e?n[n.length-c]:n[c-1];if(!r.i&&t[e]===y||r.i&&t[e].toLowerCase()===y.toLowerCase()){if($||($=!0),g||(g=!0),c===n.length){if(f=!0,b!==r.maxMismatches)return!1}else c===1&&(m=!0);if(c-=1,E++,p())return!1;if(!c)return E!==n.length||b===r.maxMismatches||!h?e:!1}else if(!h&&!E&&(h=!0),r.maxMismatches&&b&&e){b-=1;for(let D=0;D<=b;D++){let C=T>e?n[n.length-c+1+D]:n[c-2-D],M=t[o(e)];if(C&&(!r.i&&t[e]===C||r.i&&t[e].toLowerCase()===C.toLowerCase())&&(!r.firstMustMatch||c!==n.length)){if(E++,p())return!1;c-=2,$=!0;break}else if(M&&C&&(!r.i&&M===C||r.i&&M.toLowerCase()===C.toLowerCase())&&(!r.firstMustMatch||c!==n.length)){if(!E&&!r.hungry)return!1;c-=1,$=!0;break}else if(C===void 0&&b>=0&&$&&(!r.firstMustMatch||f)&&(!r.lastMustMatch||m))return e}$||(i=e)}else return e===0&&c===1&&!r.lastMustMatch&&g?0:!1;if(i!==!1&&i!==e&&(i=!1),c<1)return e;e=o(e)}if(c>0)return u&&l==="EOL"?!0:r&&r.maxMismatches>=c&&g?i||0:!1}function V(t,s,n,a,u){if(R(u)&&k(u,"trimBeforeMatching")&&u&&typeof u.trimBeforeMatching!="boolean")throw new Error(`string-match-left-right/${t}(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!${Array.isArray(u.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""}`);let o={...w,...u};if(typeof o.trimCharsBeforeMatching=="string"&&(o.trimCharsBeforeMatching=N(o.trimCharsBeforeMatching)),o.trimCharsBeforeMatching=o.trimCharsBeforeMatching.map(h=>d(h)?h:String(h)),!d(s)||!s.length)return!1;if(!Number.isInteger(n)||n<0)throw new Error(`string-match-left-right/${t}(): [THROW_ID_03] the second argument should be a natural number. Currently it's of a type: ${typeof n}, equal to:
11
11
  ${JSON.stringify(n,null,4)}`);let l,r;if(d(a))l=[a];else if(Array.isArray(a))l=a;else if(!a)l=a;else if(typeof a=="function")l=[],l.push(a);else throw new Error(`string-match-left-right/${t}(): [THROW_ID_05] the third argument, whatToMatch, is neither string nor array of strings! It's ${typeof a}, equal to:
12
12
  ${JSON.stringify(a,null,4)}`);if(u&&!R(u))throw new Error(`string-match-left-right/${t}(): [THROW_ID_06] the fourth argument, options object, should be a plain object. Currently it's of a type "${typeof u}", and equal to:
13
- ${JSON.stringify(u,null,4)}`);let c=0,E="";if(o?.trimCharsBeforeMatching&&o.trimCharsBeforeMatching.some((h,i)=>h.length>1?(c=i,E=h,!0):!1))throw new Error(`string-match-left-right/${t}(): [THROW_ID_07] 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(!l||!Array.isArray(l)||Array.isArray(l)&&!l.length||Array.isArray(l)&&l.length===1&&d(l[0])&&!l[0].trim()){if(typeof o.cb=="function"){let i,g=n;if((t==="matchLeftIncl"||t==="matchRight")&&(g+=1),t[5]==="L")for(let f=g;f--;){let $=s[f];if((!o.trimBeforeMatching||o.trimBeforeMatching&&$!==void 0&&$.trim())&&(!o.trimCharsBeforeMatching?.length||$!==void 0&&!o.trimCharsBeforeMatching.includes($))){i=f;break}}else if(t.startsWith("matchRight"))for(let f=g;f<s.length;f++){let $=s[f];if((!o.trimBeforeMatching||o.trimBeforeMatching&&$.trim())&&(!o.trimCharsBeforeMatching?.length||!o.trimCharsBeforeMatching.includes($))){i=f;break}}if(i===void 0)return!1;let b=s[i],e=i+1,m="";return e&&e>0&&(m=s.slice(0,e)),t[5]==="L"||i&&i>0&&(m=s.slice(i)),o.cb(b,m,i)}let h="";throw u||(h=" More so, the whole options object, the fourth input argument, is missing!"),new Error(`string-match-left-right/${t}(): [THROW_ID_08] 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,i=l.length;h<i;h++){r=typeof l[h]=="function";let g=l[h],b,e,m="",f=n;t==="matchRight"?f+=1:t==="matchLeft"&&(f-=1);let $=A(s,f,g,o,r,p=>t[5]==="L"?p-1:p+1);if($&&r&&typeof g=="function"&&g()==="EOL")return g()&&(!o.cb||o.cb(b,m,e))?g():!1;if(Number.isInteger($)&&(e=t.startsWith("matchLeft")?$-1:$+1,t[5]==="L"?m=s.slice(0,$):m=s.slice(e)),e<0&&(e=void 0),s[e]&&(b=s[e]),Number.isInteger($)&&(!o.cb||o.cb(b,m,e)))return g}return!1}function H(t,s,n,a){return V("matchLeftIncl",t,s,n,a)}function P(t,s,n,a){return V("matchLeft",t,s,n,a)}function j(t,s,n,a){return V("matchRightIncl",t,s,n,a)}function U(t,s,n,a){return V("matchRight",t,s,n,a)}export{L as defaultGetNextIdx,w as defaults,P as matchLeft,H as matchLeftIncl,U as matchRight,j as matchRightIncl,F as version};
13
+ ${JSON.stringify(u,null,4)}`);let c=0,E="";if(o?.trimCharsBeforeMatching&&o.trimCharsBeforeMatching.some((h,i)=>h.length>1?(c=i,E=h,!0):!1))throw new Error(`string-match-left-right/${t}(): [THROW_ID_07] 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(!l||!Array.isArray(l)||Array.isArray(l)&&!l.length||Array.isArray(l)&&l.length===1&&d(l[0])&&!l[0].trim()){if(typeof o.cb=="function"){let i,g=n;if((t==="matchLeftIncl"||t==="matchRight")&&(g+=1),t[5]==="L")for(let f=g;f--;){let m=s[f];if((!o.trimBeforeMatching||o.trimBeforeMatching&&m?.trim())&&(!o.trimCharsBeforeMatching?.length||m!==void 0&&!o.trimCharsBeforeMatching.includes(m))){i=f;break}}else if(t.startsWith("matchRight"))for(let f=g;f<s.length;f++){let m=s[f];if((!o.trimBeforeMatching||o.trimBeforeMatching&&m.trim())&&(!o.trimCharsBeforeMatching?.length||!o.trimCharsBeforeMatching.includes(m))){i=f;break}}if(i===void 0)return!1;let b=s[i],e=i+1,$="";return e&&e>0&&($=s.slice(0,e)),t[5]==="L"||i&&i>0&&($=s.slice(i)),o.cb(b,$,i)}let h="";throw u||(h=" More so, the whole options object, the fourth input argument, is missing!"),new Error(`string-match-left-right/${t}(): [THROW_ID_08] 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,i=l.length;h<i;h++){r=typeof l[h]=="function";let g=l[h],b,e,$="",f=n;t==="matchRight"?f+=1:t==="matchLeft"&&(f-=1);let m=A(s,f,g,o,r,p=>t[5]==="L"?p-1:p+1);if(m&&r&&typeof g=="function"&&g()==="EOL")return g()&&(!o.cb||o.cb(b,$,e))?g():!1;if(Number.isInteger(m)&&(e=t.startsWith("matchLeft")?m-1:m+1,t[5]==="L"?$=s.slice(0,m):$=s.slice(e)),e<0&&(e=void 0),s[e]&&(b=s[e]),Number.isInteger(m)&&(!o.cb||o.cb(b,$,e)))return g}return!1}function H(t,s,n,a){return V("matchLeftIncl",t,s,n,a)}function P(t,s,n,a){return V("matchLeft",t,s,n,a)}function j(t,s,n,a){return V("matchRightIncl",t,s,n,a)}function U(t,s,n,a){return V("matchRight",t,s,n,a)}export{L as defaultGetNextIdx,w as defaults,P as matchLeft,H as matchLeftIncl,U as matchRight,j as matchRightIncl,F as version};
@@ -1,20 +1,20 @@
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.0.13
4
+ * @version 9.0.14
5
5
  * @author Roy Revelt, Codsen Ltd
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 U=Object.create;var V=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames,N=Object.getOwnPropertySymbols,q=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable;var L=(e,n,s)=>n in e?V(e,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[n]=s,w=(e,n)=>{for(var s in n||(n={}))x.call(n,s)&&L(e,s,n[s]);if(N)for(var s of N(n))Q.call(n,s)&&L(e,s,n[s]);return e};var Y=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports),K=(e,n)=>{for(var s in n)V(e,s,{get:n[s],enumerable:!0})},v=(e,n,s,u)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of _(n))!x.call(e,a)&&a!==s&&V(e,a,{get:()=>n[a],enumerable:!(u=W(n,a))||u.enumerable});return e};var G=(e,n,s)=>(s=e!=null?U(q(e)):{},v(n||!e||!e.__esModule?V(s,"default",{value:e,enumerable:!0}):s,e)),Z=e=>v(V({},"__esModule",{value:!0}),e);var J=Y((ce,j)=>{"use strict";j.exports=z;function M(e){return e instanceof Buffer?Buffer.from(e):new e.constructor(e.buffer.slice(),e.byteOffset,e.length)}function z(e){if(e=e||{},e.circles)return X(e);return e.proto?u:s;function n(a,o){for(var r=Object.keys(a),t=new Array(r.length),l=0;l<r.length;l++){var i=r[l],h=a[i];typeof h!="object"||h===null?t[i]=h:h instanceof Date?t[i]=new Date(h):ArrayBuffer.isView(h)?t[i]=M(h):t[i]=o(h)}return t}function s(a){if(typeof a!="object"||a===null)return a;if(a instanceof Date)return new Date(a);if(Array.isArray(a))return n(a,s);if(a instanceof Map)return new Map(n(Array.from(a),s));if(a instanceof Set)return new Set(n(Array.from(a),s));var o={};for(var r in a)if(Object.hasOwnProperty.call(a,r)!==!1){var t=a[r];typeof t!="object"||t===null?o[r]=t:t instanceof Date?o[r]=new Date(t):t instanceof Map?o[r]=new Map(n(Array.from(t),s)):t instanceof Set?o[r]=new Set(n(Array.from(t),s)):ArrayBuffer.isView(t)?o[r]=M(t):o[r]=s(t)}return o}function u(a){if(typeof a!="object"||a===null)return a;if(a instanceof Date)return new Date(a);if(Array.isArray(a))return n(a,u);if(a instanceof Map)return new Map(n(Array.from(a),u));if(a instanceof Set)return new Set(n(Array.from(a),u));var o={};for(var r in a){var t=a[r];typeof t!="object"||t===null?o[r]=t:t instanceof Date?o[r]=new Date(t):t instanceof Map?o[r]=new Map(n(Array.from(t),u)):t instanceof Set?o[r]=new Set(n(Array.from(t),u)):ArrayBuffer.isView(t)?o[r]=M(t):o[r]=u(t)}return o}}function X(e){var n=[],s=[];return e.proto?o:a;function u(r,t){for(var l=Object.keys(r),i=new Array(l.length),h=0;h<l.length;h++){var m=l[h],f=r[m];if(typeof f!="object"||f===null)i[m]=f;else if(f instanceof Date)i[m]=new Date(f);else if(ArrayBuffer.isView(f))i[m]=M(f);else{var $=n.indexOf(f);$!==-1?i[m]=s[$]:i[m]=t(f)}}return i}function a(r){if(typeof r!="object"||r===null)return r;if(r instanceof Date)return new Date(r);if(Array.isArray(r))return u(r,a);if(r instanceof Map)return new Map(u(Array.from(r),a));if(r instanceof Set)return new Set(u(Array.from(r),a));var t={};n.push(r),s.push(t);for(var l in r)if(Object.hasOwnProperty.call(r,l)!==!1){var i=r[l];if(typeof i!="object"||i===null)t[l]=i;else if(i instanceof Date)t[l]=new Date(i);else if(i instanceof Map)t[l]=new Map(u(Array.from(i),a));else if(i instanceof Set)t[l]=new Set(u(Array.from(i),a));else if(ArrayBuffer.isView(i))t[l]=M(i);else{var h=n.indexOf(i);h!==-1?t[l]=s[h]:t[l]=a(i)}}return n.pop(),s.pop(),t}function o(r){if(typeof r!="object"||r===null)return r;if(r instanceof Date)return new Date(r);if(Array.isArray(r))return u(r,o);if(r instanceof Map)return new Map(u(Array.from(r),o));if(r instanceof Set)return new Set(u(Array.from(r),o));var t={};n.push(r),s.push(t);for(var l in r){var i=r[l];if(typeof i!="object"||i===null)t[l]=i;else if(i instanceof Date)t[l]=new Date(i);else if(i instanceof Map)t[l]=new Map(u(Array.from(i),o));else if(i instanceof Set)t[l]=new Set(u(Array.from(i),o));else if(ArrayBuffer.isView(i))t[l]=M(i);else{var h=n.indexOf(i);h!==-1?t[l]=s[h]:t[l]=o(i)}}return n.pop(),s.pop(),t}}});var ie={};K(ie,{defaultGetNextIdx:()=>H,defaults:()=>R,matchLeft:()=>se,matchLeftIncl:()=>re,matchRight:()=>oe,matchRightIncl:()=>ae,version:()=>te});function I(e){return typeof e!="string"?e:e.length?[e]:[]}var F=G(J(),1);var fe=(0,F.default)();function A(e){if(e==null||typeof e!="object")return!1;let n=Object.getPrototypeOf(e);return n!==null&&n!==Object.prototype&&Object.getPrototypeOf(n)!==null?!1:!(Symbol.iterator in e)&&!(Symbol.toStringTag in e)}function T(e){return typeof e=="string"}function k(e,n){return A(e)&&T(n)&&n in e}var P="9.0.13";var te=P,R={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},H=e=>e+1;function ne(e,n,s,u,a=!1,o=H){let r=typeof s=="function"?s():s;if(+n<0&&a&&r==="EOL")return r;let t=w(w({},R),u);if(n>=e.length&&!a)return!1;let l=a?1:s.length,i=0,h=!1,m=!1,f=!1,$=t.maxMismatches,c=n,C=!1,g=!1,E=!1;function b(){return i===1&&$<t.maxMismatches-1}for(;e[c];){let y=o(c);if(t.trimBeforeMatching&&e[c].trim()===""){if(!e[y]&&a&&s==="EOL")return!0;c=o(c);continue}if(t&&!t.i&&t.trimCharsBeforeMatching&&t.trimCharsBeforeMatching.includes(e[c])||t!=null&&t.i&&t.trimCharsBeforeMatching&&t.trimCharsBeforeMatching.map(D=>D.toLowerCase()).includes(e[c].toLowerCase())){if(a&&s==="EOL"&&!e[y])return!0;c=o(c);continue}let B=y>c?s[s.length-l]:s[l-1];if(!t.i&&e[c]===B||t.i&&e[c].toLowerCase()===B.toLowerCase()){if(C||(C=!0),f||(f=!0),l===s.length){if(g=!0,$!==t.maxMismatches)return!1}else l===1&&(E=!0);if(l-=1,i++,b())return!1;if(!l)return i!==s.length||$===t.maxMismatches||!h?c:!1}else if(!h&&!i&&(h=!0),t.maxMismatches&&$&&c){$-=1;for(let D=0;D<=$;D++){let d=y>c?s[s.length-l+1+D]:s[l-2-D],O=e[o(c)];if(d&&(!t.i&&e[c]===d||t.i&&e[c].toLowerCase()===d.toLowerCase())&&(!t.firstMustMatch||l!==s.length)){if(i++,b())return!1;l-=2,C=!0;break}else if(O&&d&&(!t.i&&O===d||t.i&&O.toLowerCase()===d.toLowerCase())&&(!t.firstMustMatch||l!==s.length)){if(!i&&!t.hungry)return!1;l-=1,C=!0;break}else if(d===void 0&&$>=0&&C&&(!t.firstMustMatch||g)&&(!t.lastMustMatch||E))return c}C||(m=c)}else return c===0&&l===1&&!t.lastMustMatch&&f?0:!1;if(m!==!1&&m!==c&&(m=!1),l<1)return c;c=o(c)}if(l>0)return a&&r==="EOL"?!0:t&&t.maxMismatches>=l&&f?m||0:!1}function S(e,n,s,u,a){var h,m;if(A(a)&&k(a,"trimBeforeMatching")&&a&&typeof a.trimBeforeMatching!="boolean")throw new Error(`string-match-left-right/${e}(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!${Array.isArray(a.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""}`);let o=w(w({},R),a);if(typeof o.trimCharsBeforeMatching=="string"&&(o.trimCharsBeforeMatching=I(o.trimCharsBeforeMatching)),o.trimCharsBeforeMatching=o.trimCharsBeforeMatching.map(f=>T(f)?f:String(f)),!T(n)||!n.length)return!1;if(!Number.isInteger(s)||s<0)throw new Error(`string-match-left-right/${e}(): [THROW_ID_03] the second argument should be a natural number. Currently it's of a type: ${typeof s}, equal to:
10
+ "use strict";var stringMatchLeftRight=(()=>{var U=Object.create;var V=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames,N=Object.getOwnPropertySymbols,q=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable;var L=(e,n,s)=>n in e?V(e,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[n]=s,w=(e,n)=>{for(var s in n||(n={}))x.call(n,s)&&L(e,s,n[s]);if(N)for(var s of N(n))Q.call(n,s)&&L(e,s,n[s]);return e};var Y=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports),K=(e,n)=>{for(var s in n)V(e,s,{get:n[s],enumerable:!0})},v=(e,n,s,u)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of _(n))!x.call(e,o)&&o!==s&&V(e,o,{get:()=>n[o],enumerable:!(u=W(n,o))||u.enumerable});return e};var G=(e,n,s)=>(s=e!=null?U(q(e)):{},v(n||!e||!e.__esModule?V(s,"default",{value:e,enumerable:!0}):s,e)),Z=e=>v(V({},"__esModule",{value:!0}),e);var J=Y((ce,j)=>{"use strict";j.exports=z;function M(e){return e instanceof Buffer?Buffer.from(e):new e.constructor(e.buffer.slice(),e.byteOffset,e.length)}function z(e){if(e=e||{},e.circles)return X(e);return e.proto?u:s;function n(o,a){for(var r=Object.keys(o),t=new Array(r.length),l=0;l<r.length;l++){var i=r[l],h=o[i];typeof h!="object"||h===null?t[i]=h:h instanceof Date?t[i]=new Date(h):ArrayBuffer.isView(h)?t[i]=M(h):t[i]=a(h)}return t}function s(o){if(typeof o!="object"||o===null)return o;if(o instanceof Date)return new Date(o);if(Array.isArray(o))return n(o,s);if(o instanceof Map)return new Map(n(Array.from(o),s));if(o instanceof Set)return new Set(n(Array.from(o),s));var a={};for(var r in o)if(Object.hasOwnProperty.call(o,r)!==!1){var t=o[r];typeof t!="object"||t===null?a[r]=t:t instanceof Date?a[r]=new Date(t):t instanceof Map?a[r]=new Map(n(Array.from(t),s)):t instanceof Set?a[r]=new Set(n(Array.from(t),s)):ArrayBuffer.isView(t)?a[r]=M(t):a[r]=s(t)}return a}function u(o){if(typeof o!="object"||o===null)return o;if(o instanceof Date)return new Date(o);if(Array.isArray(o))return n(o,u);if(o instanceof Map)return new Map(n(Array.from(o),u));if(o instanceof Set)return new Set(n(Array.from(o),u));var a={};for(var r in o){var t=o[r];typeof t!="object"||t===null?a[r]=t:t instanceof Date?a[r]=new Date(t):t instanceof Map?a[r]=new Map(n(Array.from(t),u)):t instanceof Set?a[r]=new Set(n(Array.from(t),u)):ArrayBuffer.isView(t)?a[r]=M(t):a[r]=u(t)}return a}}function X(e){var n=[],s=[];return e.proto?a:o;function u(r,t){for(var l=Object.keys(r),i=new Array(l.length),h=0;h<l.length;h++){var m=l[h],f=r[m];if(typeof f!="object"||f===null)i[m]=f;else if(f instanceof Date)i[m]=new Date(f);else if(ArrayBuffer.isView(f))i[m]=M(f);else{var $=n.indexOf(f);$!==-1?i[m]=s[$]:i[m]=t(f)}}return i}function o(r){if(typeof r!="object"||r===null)return r;if(r instanceof Date)return new Date(r);if(Array.isArray(r))return u(r,o);if(r instanceof Map)return new Map(u(Array.from(r),o));if(r instanceof Set)return new Set(u(Array.from(r),o));var t={};n.push(r),s.push(t);for(var l in r)if(Object.hasOwnProperty.call(r,l)!==!1){var i=r[l];if(typeof i!="object"||i===null)t[l]=i;else if(i instanceof Date)t[l]=new Date(i);else if(i instanceof Map)t[l]=new Map(u(Array.from(i),o));else if(i instanceof Set)t[l]=new Set(u(Array.from(i),o));else if(ArrayBuffer.isView(i))t[l]=M(i);else{var h=n.indexOf(i);h!==-1?t[l]=s[h]:t[l]=o(i)}}return n.pop(),s.pop(),t}function a(r){if(typeof r!="object"||r===null)return r;if(r instanceof Date)return new Date(r);if(Array.isArray(r))return u(r,a);if(r instanceof Map)return new Map(u(Array.from(r),a));if(r instanceof Set)return new Set(u(Array.from(r),a));var t={};n.push(r),s.push(t);for(var l in r){var i=r[l];if(typeof i!="object"||i===null)t[l]=i;else if(i instanceof Date)t[l]=new Date(i);else if(i instanceof Map)t[l]=new Map(u(Array.from(i),a));else if(i instanceof Set)t[l]=new Set(u(Array.from(i),a));else if(ArrayBuffer.isView(i))t[l]=M(i);else{var h=n.indexOf(i);h!==-1?t[l]=s[h]:t[l]=a(i)}}return n.pop(),s.pop(),t}}});var ie={};K(ie,{defaultGetNextIdx:()=>H,defaults:()=>R,matchLeft:()=>se,matchLeftIncl:()=>re,matchRight:()=>ae,matchRightIncl:()=>oe,version:()=>te});function I(e){return typeof e!="string"?e:e.length?[e]:[]}var F=G(J(),1);var fe=(0,F.default)();function A(e){if(e==null||typeof e!="object")return!1;let n=Object.getPrototypeOf(e);return n!==null&&n!==Object.prototype&&Object.getPrototypeOf(n)!==null?!1:!(Symbol.iterator in e)&&!(Symbol.toStringTag in e)}function T(e){return typeof e=="string"}function k(e,n){return A(e)&&T(n)&&n in e}var P="9.0.14";var te=P,R={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},H=e=>e+1;function ne(e,n,s,u,o=!1,a=H){let r=typeof s=="function"?s():s;if(+n<0&&o&&r==="EOL")return r;let t=w(w({},R),u);if(n>=e.length&&!o)return!1;let l=o?1:s.length,i=0,h=!1,m=!1,f=!1,$=t.maxMismatches,c=n,E=!1,g=!1,C=!1;function b(){return i===1&&$<t.maxMismatches-1}for(;e[c];){let y=a(c);if(t.trimBeforeMatching&&e[c].trim()===""){if(!e[y]&&o&&s==="EOL")return!0;c=a(c);continue}if(t&&!t.i&&t.trimCharsBeforeMatching&&t.trimCharsBeforeMatching.includes(e[c])||t!=null&&t.i&&t.trimCharsBeforeMatching&&t.trimCharsBeforeMatching.map(d=>d.toLowerCase()).includes(e[c].toLowerCase())){if(o&&s==="EOL"&&!e[y])return!0;c=a(c);continue}let B=y>c?s[s.length-l]:s[l-1];if(!t.i&&e[c]===B||t.i&&e[c].toLowerCase()===B.toLowerCase()){if(E||(E=!0),f||(f=!0),l===s.length){if(g=!0,$!==t.maxMismatches)return!1}else l===1&&(C=!0);if(l-=1,i++,b())return!1;if(!l)return i!==s.length||$===t.maxMismatches||!h?c:!1}else if(!h&&!i&&(h=!0),t.maxMismatches&&$&&c){$-=1;for(let d=0;d<=$;d++){let D=y>c?s[s.length-l+1+d]:s[l-2-d],O=e[a(c)];if(D&&(!t.i&&e[c]===D||t.i&&e[c].toLowerCase()===D.toLowerCase())&&(!t.firstMustMatch||l!==s.length)){if(i++,b())return!1;l-=2,E=!0;break}else if(O&&D&&(!t.i&&O===D||t.i&&O.toLowerCase()===D.toLowerCase())&&(!t.firstMustMatch||l!==s.length)){if(!i&&!t.hungry)return!1;l-=1,E=!0;break}else if(D===void 0&&$>=0&&E&&(!t.firstMustMatch||g)&&(!t.lastMustMatch||C))return c}E||(m=c)}else return c===0&&l===1&&!t.lastMustMatch&&f?0:!1;if(m!==!1&&m!==c&&(m=!1),l<1)return c;c=a(c)}if(l>0)return o&&r==="EOL"?!0:t&&t.maxMismatches>=l&&f?m||0:!1}function S(e,n,s,u,o){var h,m;if(A(o)&&k(o,"trimBeforeMatching")&&o&&typeof o.trimBeforeMatching!="boolean")throw new Error(`string-match-left-right/${e}(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!${Array.isArray(o.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""}`);let a=w(w({},R),o);if(typeof a.trimCharsBeforeMatching=="string"&&(a.trimCharsBeforeMatching=I(a.trimCharsBeforeMatching)),a.trimCharsBeforeMatching=a.trimCharsBeforeMatching.map(f=>T(f)?f:String(f)),!T(n)||!n.length)return!1;if(!Number.isInteger(s)||s<0)throw new Error(`string-match-left-right/${e}(): [THROW_ID_03] the second argument should be a natural number. Currently it's of a type: ${typeof s}, equal to:
11
11
  ${JSON.stringify(s,null,4)}`);let r,t;if(T(u))r=[u];else if(Array.isArray(u))r=u;else if(!u)r=u;else if(typeof u=="function")r=[],r.push(u);else throw new Error(`string-match-left-right/${e}(): [THROW_ID_05] the third argument, whatToMatch, is neither string nor array of strings! It's ${typeof u}, equal to:
12
- ${JSON.stringify(u,null,4)}`);if(a&&!A(a))throw new Error(`string-match-left-right/${e}(): [THROW_ID_06] the fourth argument, options object, should be a plain object. Currently it's of a type "${typeof a}", and equal to:
13
- ${JSON.stringify(a,null,4)}`);let l=0,i="";if(o!=null&&o.trimCharsBeforeMatching&&o.trimCharsBeforeMatching.some((f,$)=>f.length>1?(l=$,i=f,!0):!1))throw new Error(`string-match-left-right/${e}(): [THROW_ID_07] the fourth argument, options object contains trimCharsBeforeMatching. It was meant to list the single characters but one of the entries at index ${l} is longer than 1 character, ${i.length} (equals to ${i}). Please split it into separate characters and put into array as separate elements.`);if(!r||!Array.isArray(r)||Array.isArray(r)&&!r.length||Array.isArray(r)&&r.length===1&&T(r[0])&&!r[0].trim()){if(typeof o.cb=="function"){let $,c=s;if((e==="matchLeftIncl"||e==="matchRight")&&(c+=1),e[5]==="L")for(let b=c;b--;){let p=n[b];if((!o.trimBeforeMatching||o.trimBeforeMatching&&p!==void 0&&p.trim())&&(!((h=o.trimCharsBeforeMatching)!=null&&h.length)||p!==void 0&&!o.trimCharsBeforeMatching.includes(p))){$=b;break}}else if(e.startsWith("matchRight"))for(let b=c;b<n.length;b++){let p=n[b];if((!o.trimBeforeMatching||o.trimBeforeMatching&&p.trim())&&(!((m=o.trimCharsBeforeMatching)!=null&&m.length)||!o.trimCharsBeforeMatching.includes(p))){$=b;break}}if($===void 0)return!1;let C=n[$],g=$+1,E="";return g&&g>0&&(E=n.slice(0,g)),e[5]==="L"||$&&$>0&&(E=n.slice($)),o.cb(C,E,$)}let f="";throw a||(f=" More so, the whole options object, the fourth input argument, is missing!"),new Error(`string-match-left-right/${e}(): [THROW_ID_08] 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!${f}`)}for(let f=0,$=r.length;f<$;f++){t=typeof r[f]=="function";let c=r[f],C,g,E="",b=s;e==="matchRight"?b+=1:e==="matchLeft"&&(b-=1);let p=ne(n,b,c,o,t,y=>e[5]==="L"?y-1:y+1);if(p&&t&&typeof c=="function"&&c()==="EOL")return c()&&(!o.cb||o.cb(C,E,g))?c():!1;if(Number.isInteger(p)&&(g=e.startsWith("matchLeft")?p-1:p+1,e[5]==="L"?E=n.slice(0,p):E=n.slice(g)),g<0&&(g=void 0),n[g]&&(C=n[g]),Number.isInteger(p)&&(!o.cb||o.cb(C,E,g)))return c}return!1}function re(e,n,s,u){return S("matchLeftIncl",e,n,s,u)}function se(e,n,s,u){return S("matchLeft",e,n,s,u)}function ae(e,n,s,u){return S("matchRightIncl",e,n,s,u)}function oe(e,n,s,u){return S("matchRight",e,n,s,u)}return Z(ie);})();
12
+ ${JSON.stringify(u,null,4)}`);if(o&&!A(o))throw new Error(`string-match-left-right/${e}(): [THROW_ID_06] the fourth argument, options object, should be a plain object. Currently it's of a type "${typeof o}", and equal to:
13
+ ${JSON.stringify(o,null,4)}`);let l=0,i="";if(a!=null&&a.trimCharsBeforeMatching&&a.trimCharsBeforeMatching.some((f,$)=>f.length>1?(l=$,i=f,!0):!1))throw new Error(`string-match-left-right/${e}(): [THROW_ID_07] the fourth argument, options object contains trimCharsBeforeMatching. It was meant to list the single characters but one of the entries at index ${l} is longer than 1 character, ${i.length} (equals to ${i}). Please split it into separate characters and put into array as separate elements.`);if(!r||!Array.isArray(r)||Array.isArray(r)&&!r.length||Array.isArray(r)&&r.length===1&&T(r[0])&&!r[0].trim()){if(typeof a.cb=="function"){let $,c=s;if((e==="matchLeftIncl"||e==="matchRight")&&(c+=1),e[5]==="L")for(let b=c;b--;){let p=n[b];if((!a.trimBeforeMatching||a.trimBeforeMatching&&(p!=null&&p.trim()))&&(!((h=a.trimCharsBeforeMatching)!=null&&h.length)||p!==void 0&&!a.trimCharsBeforeMatching.includes(p))){$=b;break}}else if(e.startsWith("matchRight"))for(let b=c;b<n.length;b++){let p=n[b];if((!a.trimBeforeMatching||a.trimBeforeMatching&&p.trim())&&(!((m=a.trimCharsBeforeMatching)!=null&&m.length)||!a.trimCharsBeforeMatching.includes(p))){$=b;break}}if($===void 0)return!1;let E=n[$],g=$+1,C="";return g&&g>0&&(C=n.slice(0,g)),e[5]==="L"||$&&$>0&&(C=n.slice($)),a.cb(E,C,$)}let f="";throw o||(f=" More so, the whole options object, the fourth input argument, is missing!"),new Error(`string-match-left-right/${e}(): [THROW_ID_08] 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!${f}`)}for(let f=0,$=r.length;f<$;f++){t=typeof r[f]=="function";let c=r[f],E,g,C="",b=s;e==="matchRight"?b+=1:e==="matchLeft"&&(b-=1);let p=ne(n,b,c,a,t,y=>e[5]==="L"?y-1:y+1);if(p&&t&&typeof c=="function"&&c()==="EOL")return c()&&(!a.cb||a.cb(E,C,g))?c():!1;if(Number.isInteger(p)&&(g=e.startsWith("matchLeft")?p-1:p+1,e[5]==="L"?C=n.slice(0,p):C=n.slice(g)),g<0&&(g=void 0),n[g]&&(E=n[g]),Number.isInteger(p)&&(!a.cb||a.cb(E,C,g)))return c}return!1}function re(e,n,s,u){return S("matchLeftIncl",e,n,s,u)}function se(e,n,s,u){return S("matchLeft",e,n,s,u)}function oe(e,n,s,u){return S("matchRightIncl",e,n,s,u)}function ae(e,n,s,u){return S("matchRight",e,n,s,u)}return Z(ie);})();
14
14
  /**
15
15
  * @name arrayiffy-if-string
16
16
  * @fileoverview Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else.
17
- * @version 5.0.5
17
+ * @version 5.0.6
18
18
  * @author Roy Revelt, Codsen Ltd
19
19
  * @license MIT
20
20
  * {@link https://codsen.com/os/arrayiffy-if-string/}
@@ -22,7 +22,7 @@ ${JSON.stringify(a,null,4)}`);let l=0,i="";if(o!=null&&o.trimCharsBeforeMatching
22
22
  /**
23
23
  * @name codsen-utils
24
24
  * @fileoverview Various utility functions
25
- * @version 1.6.0
25
+ * @version 1.6.1
26
26
  * @author Roy Revelt, Codsen Ltd
27
27
  * @license MIT
28
28
  * {@link https://codsen.com/os/codsen-utils/}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "string-match-left-right",
3
- "version": "9.0.13",
3
+ "version": "9.0.14",
4
4
  "description": "Match substrings on the left or right of a given index, ignoring whitespace",
5
5
  "keywords": [
6
6
  "left",
@@ -37,7 +37,7 @@
37
37
  "cjs-on": "exit 0",
38
38
  "dev": "DEV=true node '../../ops/scripts/esbuild.js' && npm run dts",
39
39
  "devtest": "c8 npm run unit && npm run examples && npm run lint",
40
- "dts": "rollup -c && npm run prettier -- 'types/index.d.ts' --write --loglevel 'silent'",
40
+ "dts": "rollup -c && npm run prettier -- 'types/index.d.ts' --write --log-level 'silent'",
41
41
  "examples": "node '../../ops/scripts/run-examples.js'",
42
42
  "lect": "node '../../ops/lect/lect.js' && npm run prettier -- 'README.md' '.all-contributorsrc' 'rollup.config.js' --write",
43
43
  "letspublish": "npm publish || :",
@@ -45,7 +45,7 @@
45
45
  "perf": "node perf/check.js",
46
46
  "prep": "echo 'ready'",
47
47
  "prettier": "prettier",
48
- "prettier:format": "npm run prettier -- --write '**/*.{ts,tsx,md}' --no-error-on-unmatched-pattern --loglevel 'silent'",
48
+ "prettier:format": "npm run prettier -- --write '**/*.{ts,tsx,md}' --no-error-on-unmatched-pattern --log-level 'silent'",
49
49
  "pretest": "npm run lect && npm run build",
50
50
  "test": "npm run devtest",
51
51
  "unit": "uvu test"
@@ -68,8 +68,8 @@
68
68
  }
69
69
  },
70
70
  "dependencies": {
71
- "arrayiffy-if-string": "^5.0.5",
72
- "codsen-utils": "^1.6.0",
73
- "string-character-is-astral-surrogate": "^3.0.7"
71
+ "arrayiffy-if-string": "^5.0.6",
72
+ "codsen-utils": "^1.6.1",
73
+ "string-character-is-astral-surrogate": "^3.0.8"
74
74
  }
75
75
  }
package/types/index.d.ts CHANGED
@@ -6,7 +6,7 @@ interface Opts {
6
6
  | ((
7
7
  wholeCharacterOutside?: string | undefined,
8
8
  theRemainderOfTheString?: string,
9
- firstCharOutsideIndex?: number
9
+ firstCharOutsideIndex?: number,
10
10
  ) => string | boolean);
11
11
  i: boolean;
12
12
  trimBeforeMatching: boolean;
@@ -22,25 +22,25 @@ declare function matchLeftIncl(
22
22
  str: string,
23
23
  position: number,
24
24
  whatToMatch: (() => string) | string | string[],
25
- opts?: Partial<Opts>
25
+ opts?: Partial<Opts>,
26
26
  ): boolean | string;
27
27
  declare function matchLeft(
28
28
  str: string,
29
29
  position: number,
30
30
  whatToMatch: (() => string) | string | string[],
31
- opts?: Partial<Opts>
31
+ opts?: Partial<Opts>,
32
32
  ): boolean | string;
33
33
  declare function matchRightIncl(
34
34
  str: string,
35
35
  position: number,
36
36
  whatToMatch: (() => string) | string | string[],
37
- opts?: Partial<Opts>
37
+ opts?: Partial<Opts>,
38
38
  ): boolean | string;
39
39
  declare function matchRight(
40
40
  str: string,
41
41
  position: number,
42
42
  whatToMatch: (() => string) | string | string[],
43
- opts?: Partial<Opts>
43
+ opts?: Partial<Opts>,
44
44
  ): boolean | string;
45
45
 
46
46
  export {