string-match-left-right
Advanced tools
Comparing version 9.0.12 to 9.0.13
/** | ||
* @name string-match-left-right | ||
* @fileoverview Match substrings on the left or right of a given index, ignoring whitespace | ||
* @version 9.0.12 | ||
* @version 9.0.13 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -10,5 +10,5 @@ * @license MIT | ||
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.12";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: | ||
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: | ||
${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: | ||
${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: | ||
${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}; |
/** | ||
* @name string-match-left-right | ||
* @fileoverview Match substrings on the left or right of a given index, ignoring whitespace | ||
* @version 9.0.12 | ||
* @version 9.0.13 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -10,6 +10,6 @@ * @license MIT | ||
"use strict";var stringMatchLeftRight=(()=>{var V=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames,N=Object.getOwnPropertySymbols;var k=Object.prototype.hasOwnProperty,P=Object.prototype.propertyIsEnumerable;var L=(e,t,r)=>t in e?V(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,M=(e,t)=>{for(var r in t||(t={}))k.call(t,r)&&L(e,r,t[r]);if(N)for(var r of N(t))P.call(t,r)&&L(e,r,t[r]);return e};var j=(e,t)=>{for(var r in t)V(e,r,{get:t[r],enumerable:!0})},H=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of v(t))!k.call(e,a)&&a!==r&&V(e,a,{get:()=>t[a],enumerable:!(i=F(t,a))||i.enumerable});return e};var U=e=>H(V({},"__esModule",{value:!0}),e);var Z={};j(Z,{defaultGetNextIdx:()=>J,defaults:()=>A,matchLeft:()=>Y,matchLeftIncl:()=>Q,matchRight:()=>G,matchRightIncl:()=>K,version:()=>_});function B(e){return typeof e!="string"?e:e.length?[e]:[]}function O(e){if(e==null||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t!==null&&t!==Object.prototype&&Object.getPrototypeOf(t)!==null?!1:!(Symbol.iterator in e)&&!(Symbol.toStringTag in e)}function y(e){return typeof e=="string"}function x(e,t){return O(e)&&y(t)&&t in e}var I="9.0.12";var _=I,A={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},J=e=>e+1;function q(e,t,r,i,a=!1,s=J){let u=typeof r=="function"?r():r;if(+t<0&&a&&u==="EOL")return u;let o=M(M({},A),i);if(t>=e.length&&!a)return!1;let c=a?1:r.length,C=0,D=!1,E=!1,h=!1,l=o.maxMismatches,n=t,f=!1,$=!1,b=!1;function m(){return C===1&&l<o.maxMismatches-1}for(;e[n];){let p=s(n);if(o.trimBeforeMatching&&e[n].trim()===""){if(!e[p]&&a&&r==="EOL")return!0;n=s(n);continue}if(o&&!o.i&&o.trimCharsBeforeMatching&&o.trimCharsBeforeMatching.includes(e[n])||o!=null&&o.i&&o.trimCharsBeforeMatching&&o.trimCharsBeforeMatching.map(T=>T.toLowerCase()).includes(e[n].toLowerCase())){if(a&&r==="EOL"&&!e[p])return!0;n=s(n);continue}let R=p>n?r[r.length-c]:r[c-1];if(!o.i&&e[n]===R||o.i&&e[n].toLowerCase()===R.toLowerCase()){if(f||(f=!0),h||(h=!0),c===r.length){if($=!0,l!==o.maxMismatches)return!1}else c===1&&(b=!0);if(c-=1,C++,m())return!1;if(!c)return C!==r.length||l===o.maxMismatches||!D?n:!1}else if(!D&&!C&&(D=!0),o.maxMismatches&&l&&n){l-=1;for(let T=0;T<=l;T++){let d=p>n?r[r.length-c+1+T]:r[c-2-T],S=e[s(n)];if(d&&(!o.i&&e[n]===d||o.i&&e[n].toLowerCase()===d.toLowerCase())&&(!o.firstMustMatch||c!==r.length)){if(C++,m())return!1;c-=2,f=!0;break}else if(S&&d&&(!o.i&&S===d||o.i&&S.toLowerCase()===d.toLowerCase())&&(!o.firstMustMatch||c!==r.length)){if(!C&&!o.hungry)return!1;c-=1,f=!0;break}else if(d===void 0&&l>=0&&f&&(!o.firstMustMatch||$)&&(!o.lastMustMatch||b))return n}f||(E=n)}else return n===0&&c===1&&!o.lastMustMatch&&h?0:!1;if(E!==!1&&E!==n&&(E=!1),c<1)return n;n=s(n)}if(c>0)return a&&u==="EOL"?!0:o&&o.maxMismatches>=c&&h?E||0:!1}function w(e,t,r,i,a){var D,E;if(O(a)&&x(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 s=M(M({},A),a);if(typeof s.trimCharsBeforeMatching=="string"&&(s.trimCharsBeforeMatching=B(s.trimCharsBeforeMatching)),s.trimCharsBeforeMatching=s.trimCharsBeforeMatching.map(h=>y(h)?h:String(h)),!y(t)||!t.length)return!1;if(!Number.isInteger(r)||r<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 r}, equal to: | ||
${JSON.stringify(r,null,4)}`);let u,o;if(y(i))u=[i];else if(Array.isArray(i))u=i;else if(!i)u=i;else if(typeof i=="function")u=[],u.push(i);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 i}, equal to: | ||
${JSON.stringify(i,null,4)}`);if(a&&!O(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: | ||
${JSON.stringify(a,null,4)}`);let c=0,C="";if(s!=null&&s.trimCharsBeforeMatching&&s.trimCharsBeforeMatching.some((h,l)=>h.length>1?(c=l,C=h,!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 ${c} is longer than 1 character, ${C.length} (equals to ${C}). Please split it into separate characters and put into array as separate elements.`);if(!u||!Array.isArray(u)||Array.isArray(u)&&!u.length||Array.isArray(u)&&u.length===1&&y(u[0])&&!u[0].trim()){if(typeof s.cb=="function"){let l,n=r;if((e==="matchLeftIncl"||e==="matchRight")&&(n+=1),e[5]==="L")for(let m=n;m--;){let g=t[m];if((!s.trimBeforeMatching||s.trimBeforeMatching&&g!==void 0&&g.trim())&&(!((D=s.trimCharsBeforeMatching)!=null&&D.length)||g!==void 0&&!s.trimCharsBeforeMatching.includes(g))){l=m;break}}else if(e.startsWith("matchRight"))for(let m=n;m<t.length;m++){let g=t[m];if((!s.trimBeforeMatching||s.trimBeforeMatching&&g.trim())&&(!((E=s.trimCharsBeforeMatching)!=null&&E.length)||!s.trimCharsBeforeMatching.includes(g))){l=m;break}}if(l===void 0)return!1;let f=t[l],$=l+1,b="";return $&&$>0&&(b=t.slice(0,$)),e[5]==="L"||l&&l>0&&(b=t.slice(l)),s.cb(f,b,l)}let h="";throw a||(h=" 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!${h}`)}for(let h=0,l=u.length;h<l;h++){o=typeof u[h]=="function";let n=u[h],f,$,b="",m=r;e==="matchRight"?m+=1:e==="matchLeft"&&(m-=1);let g=q(t,m,n,s,o,p=>e[5]==="L"?p-1:p+1);if(g&&o&&typeof n=="function"&&n()==="EOL")return n()&&(!s.cb||s.cb(f,b,$))?n():!1;if(Number.isInteger(g)&&($=e.startsWith("matchLeft")?g-1:g+1,e[5]==="L"?b=t.slice(0,g):b=t.slice($)),$<0&&($=void 0),t[$]&&(f=t[$]),Number.isInteger(g)&&(!s.cb||s.cb(f,b,$)))return n}return!1}function Q(e,t,r,i){return w("matchLeftIncl",e,t,r,i)}function Y(e,t,r,i){return w("matchLeft",e,t,r,i)}function K(e,t,r,i){return w("matchRightIncl",e,t,r,i)}function G(e,t,r,i){return w("matchRight",e,t,r,i)}return U(Z);})(); | ||
"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: | ||
${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: | ||
${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: | ||
${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);})(); | ||
/** | ||
@@ -26,3 +26,3 @@ * @name arrayiffy-if-string | ||
* @fileoverview Various utility functions | ||
* @version 1.5.0 | ||
* @version 1.6.0 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -29,0 +29,0 @@ * @license MIT |
{ | ||
"name": "string-match-left-right", | ||
"version": "9.0.12", | ||
"version": "9.0.13", | ||
"description": "Match substrings on the left or right of a given index, ignoring whitespace", | ||
@@ -72,5 +72,5 @@ "keywords": [ | ||
"arrayiffy-if-string": "^5.0.5", | ||
"codsen-utils": "^1.5.0", | ||
"codsen-utils": "^1.6.0", | ||
"string-character-is-astral-surrogate": "^3.0.7" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36281
147
Updatedcodsen-utils@^1.6.0