string-match-left-right
Advanced tools
Comparing version 9.0.4 to 9.0.5
/** | ||
* @name string-match-left-right | ||
* @fileoverview Match substrings on the left or right of a given index, ignoring whitespace | ||
* @version 9.0.4 | ||
* @version 9.0.5 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -10,5 +10,5 @@ * @license MIT | ||
import{arrayiffy as N}from"arrayiffy-if-string";var O="9.0.4";var x=O;function w(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}function d(t){return typeof t=="string"}var R={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},k=t=>t+1;function A(t,s,n,a,u=!1,o=k){let l=typeof n=="function"?n():n;if(+s<0&&u&&l==="EOL")return l;let r={...R,...a};if(s>=t.length&&!u)return!1;let c=u?1:n.length,E=0,h=!1,i=!1,m=!1,b=r.maxMismatches,e=s,g=!1,f=!1,$=!1;function D(){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(p=>p.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(g||(g=!0),m||(m=!0),c===n.length){if(f=!0,b!==r.maxMismatches)return!1}else c===1&&($=!0);if(c-=1,E++,D())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 p=0;p<=b;p++){let C=T>e?n[n.length-c+1+p]:n[c-2-p],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++,D())return!1;c-=2,g=!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,g=!0;break}else if(C===void 0&&b>=0&&g&&(!r.firstMustMatch||f)&&(!r.lastMustMatch||$))return e}g||(i=e)}else return e===0&&c===1&&!r.lastMustMatch&&m?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&&m?i||0:!1}function V(t,s,n,a,u){if(w(u)&&Object.prototype.hasOwnProperty.call(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={...R,...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";var O="9.0.5";var x=O;function w(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}function d(t){return typeof t=="string"}var R={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},k=t=>t+1;function A(t,s,n,a,u=!1,o=k){let l=typeof n=="function"?n():n;if(+s<0&&u&&l==="EOL")return l;let r={...R,...a};if(s>=t.length&&!u)return!1;let c=u?1:n.length,E=0,h=!1,i=!1,m=!1,b=r.maxMismatches,e=s,g=!1,f=!1,$=!1;function D(){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(p=>p.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(g||(g=!0),m||(m=!0),c===n.length){if(f=!0,b!==r.maxMismatches)return!1}else c===1&&($=!0);if(c-=1,E++,D())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 p=0;p<=b;p++){let C=T>e?n[n.length-c+1+p]:n[c-2-p],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++,D())return!1;c-=2,g=!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,g=!0;break}else if(C===void 0&&b>=0&&g&&(!r.firstMustMatch||f)&&(!r.lastMustMatch||$))return e}g||(i=e)}else return e===0&&c===1&&!r.lastMustMatch&&m?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&&m?i||0:!1}function V(t,s,n,a,u){if(w(u)&&Object.prototype.hasOwnProperty.call(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={...R,...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&&!w(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,m=n;if((t==="matchLeftIncl"||t==="matchRight")&&(m+=1),t[5]==="L")for(let f=m;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=m;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,g="";return e&&e>0&&(g=s.slice(0,e)),t[5]==="L"||i&&i>0&&(g=s.slice(i)),o.cb(b,g,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 m=l[h],b,e,g="",f=n;t==="matchRight"?f+=1:t==="matchLeft"&&(f-=1);let $=A(s,f,m,o,r,D=>t[5]==="L"?D-1:D+1);if($&&r&&typeof m=="function"&&m()==="EOL")return m()&&(!o.cb||o.cb(b,g,e))?m():!1;if(Number.isInteger($)&&(e=t.startsWith("matchLeft")?$-1:$+1,t[5]==="L"?g=s.slice(0,$):g=s.slice(e)),e<0&&(e=void 0),s[e]&&(b=s[e]),Number.isInteger($)&&(!o.cb||o.cb(b,g,e)))return m}return!1}function J(t,s,n,a){return V("matchLeftIncl",t,s,n,a)}function F(t,s,n,a){return V("matchLeft",t,s,n,a)}function H(t,s,n,a){return V("matchRightIncl",t,s,n,a)}function j(t,s,n,a){return V("matchRight",t,s,n,a)}export{k as defaultGetNextIdx,R as defaults,F as matchLeft,J as matchLeftIncl,j as matchRight,H as matchRightIncl,x as version}; |
/** | ||
* @name string-match-left-right | ||
* @fileoverview Match substrings on the left or right of a given index, ignoring whitespace | ||
* @version 9.0.4 | ||
* @version 9.0.5 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -10,3 +10,3 @@ * @license MIT | ||
"use strict";var stringMatchLeftRight=(()=>{var M=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames,N=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var k=(t,n,e)=>n in t?M(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e,V=(t,n)=>{for(var e in n||(n={}))A.call(n,e)&&k(t,e,n[e]);if(N)for(var e of N(n))H.call(n,e)&&k(t,e,n[e]);return t};var j=(t,n)=>{for(var e in n)M(t,e,{get:n[e],enumerable:!0})},P=(t,n,e,l)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of F(n))!A.call(t,a)&&a!==e&&M(t,a,{get:()=>n[a],enumerable:!(l=J(n,a))||l.enumerable});return t};var U=t=>P(M({},"__esModule",{value:!0}),t);var X={};j(X,{defaultGetNextIdx:()=>I,defaults:()=>R,matchLeft:()=>Y,matchLeftIncl:()=>q,matchRight:()=>K,matchRightIncl:()=>G,version:()=>W});function L(t){return typeof t!="string"?t:t.length?[t]:[]}var x="9.0.4";var W=x;function B(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}function y(t){return typeof t=="string"}var R={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},I=t=>t+1;function _(t,n,e,l,a=!1,s=I){let c=typeof e=="function"?e():e;if(+n<0&&a&&c==="EOL")return c;let o=V(V({},R),l);if(n>=t.length&&!a)return!1;let u=a?1:e.length,E=0,T=!1,C=!1,h=!1,i=o.maxMismatches,r=n,f=!1,$=!1,b=!1;function g(){return E===1&&i<o.maxMismatches-1}for(;t[r];){let D=s(r);if(o.trimBeforeMatching&&t[r].trim()===""){if(!t[D]&&a&&e==="EOL")return!0;r=s(r);continue}if(o&&!o.i&&o.trimCharsBeforeMatching&&o.trimCharsBeforeMatching.includes(t[r])||o!=null&&o.i&&o.trimCharsBeforeMatching&&o.trimCharsBeforeMatching.map(d=>d.toLowerCase()).includes(t[r].toLowerCase())){if(a&&e==="EOL"&&!t[D])return!0;r=s(r);continue}let S=D>r?e[e.length-u]:e[u-1];if(!o.i&&t[r]===S||o.i&&t[r].toLowerCase()===S.toLowerCase()){if(f||(f=!0),h||(h=!0),u===e.length){if($=!0,i!==o.maxMismatches)return!1}else u===1&&(b=!0);if(u-=1,E++,g())return!1;if(!u)return E!==e.length||i===o.maxMismatches||!T?r:!1}else if(!T&&!E&&(T=!0),o.maxMismatches&&i&&r){i-=1;for(let d=0;d<=i;d++){let p=D>r?e[e.length-u+1+d]:e[u-2-d],w=t[s(r)];if(p&&(!o.i&&t[r]===p||o.i&&t[r].toLowerCase()===p.toLowerCase())&&(!o.firstMustMatch||u!==e.length)){if(E++,g())return!1;u-=2,f=!0;break}else if(w&&p&&(!o.i&&w===p||o.i&&w.toLowerCase()===p.toLowerCase())&&(!o.firstMustMatch||u!==e.length)){if(!E&&!o.hungry)return!1;u-=1,f=!0;break}else if(p===void 0&&i>=0&&f&&(!o.firstMustMatch||$)&&(!o.lastMustMatch||b))return r}f||(C=r)}else return r===0&&u===1&&!o.lastMustMatch&&h?0:!1;if(C!==!1&&C!==r&&(C=!1),u<1)return r;r=s(r)}if(u>0)return a&&c==="EOL"?!0:o&&o.maxMismatches>=u&&h?C||0:!1}function O(t,n,e,l,a){var T,C;if(B(a)&&Object.prototype.hasOwnProperty.call(a,"trimBeforeMatching")&&a&&typeof a.trimBeforeMatching!="boolean")throw new Error(`string-match-left-right/${t}(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!${Array.isArray(a.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""}`);let s=V(V({},R),a);if(typeof s.trimCharsBeforeMatching=="string"&&(s.trimCharsBeforeMatching=L(s.trimCharsBeforeMatching)),s.trimCharsBeforeMatching=s.trimCharsBeforeMatching.map(h=>y(h)?h:String(h)),!y(n)||!n.length)return!1;if(!Number.isInteger(e)||e<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 e}, equal to: | ||
"use strict";var stringMatchLeftRight=(()=>{var M=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames,N=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var k=(t,n,e)=>n in t?M(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e,V=(t,n)=>{for(var e in n||(n={}))A.call(n,e)&&k(t,e,n[e]);if(N)for(var e of N(n))H.call(n,e)&&k(t,e,n[e]);return t};var j=(t,n)=>{for(var e in n)M(t,e,{get:n[e],enumerable:!0})},P=(t,n,e,l)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of F(n))!A.call(t,a)&&a!==e&&M(t,a,{get:()=>n[a],enumerable:!(l=J(n,a))||l.enumerable});return t};var U=t=>P(M({},"__esModule",{value:!0}),t);var X={};j(X,{defaultGetNextIdx:()=>I,defaults:()=>R,matchLeft:()=>Y,matchLeftIncl:()=>q,matchRight:()=>K,matchRightIncl:()=>G,version:()=>W});function L(t){return typeof t!="string"?t:t.length?[t]:[]}var x="9.0.5";var W=x;function B(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}function y(t){return typeof t=="string"}var R={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},I=t=>t+1;function _(t,n,e,l,a=!1,s=I){let c=typeof e=="function"?e():e;if(+n<0&&a&&c==="EOL")return c;let o=V(V({},R),l);if(n>=t.length&&!a)return!1;let u=a?1:e.length,E=0,T=!1,C=!1,h=!1,i=o.maxMismatches,r=n,f=!1,$=!1,b=!1;function g(){return E===1&&i<o.maxMismatches-1}for(;t[r];){let D=s(r);if(o.trimBeforeMatching&&t[r].trim()===""){if(!t[D]&&a&&e==="EOL")return!0;r=s(r);continue}if(o&&!o.i&&o.trimCharsBeforeMatching&&o.trimCharsBeforeMatching.includes(t[r])||o!=null&&o.i&&o.trimCharsBeforeMatching&&o.trimCharsBeforeMatching.map(d=>d.toLowerCase()).includes(t[r].toLowerCase())){if(a&&e==="EOL"&&!t[D])return!0;r=s(r);continue}let S=D>r?e[e.length-u]:e[u-1];if(!o.i&&t[r]===S||o.i&&t[r].toLowerCase()===S.toLowerCase()){if(f||(f=!0),h||(h=!0),u===e.length){if($=!0,i!==o.maxMismatches)return!1}else u===1&&(b=!0);if(u-=1,E++,g())return!1;if(!u)return E!==e.length||i===o.maxMismatches||!T?r:!1}else if(!T&&!E&&(T=!0),o.maxMismatches&&i&&r){i-=1;for(let d=0;d<=i;d++){let p=D>r?e[e.length-u+1+d]:e[u-2-d],w=t[s(r)];if(p&&(!o.i&&t[r]===p||o.i&&t[r].toLowerCase()===p.toLowerCase())&&(!o.firstMustMatch||u!==e.length)){if(E++,g())return!1;u-=2,f=!0;break}else if(w&&p&&(!o.i&&w===p||o.i&&w.toLowerCase()===p.toLowerCase())&&(!o.firstMustMatch||u!==e.length)){if(!E&&!o.hungry)return!1;u-=1,f=!0;break}else if(p===void 0&&i>=0&&f&&(!o.firstMustMatch||$)&&(!o.lastMustMatch||b))return r}f||(C=r)}else return r===0&&u===1&&!o.lastMustMatch&&h?0:!1;if(C!==!1&&C!==r&&(C=!1),u<1)return r;r=s(r)}if(u>0)return a&&c==="EOL"?!0:o&&o.maxMismatches>=u&&h?C||0:!1}function O(t,n,e,l,a){var T,C;if(B(a)&&Object.prototype.hasOwnProperty.call(a,"trimBeforeMatching")&&a&&typeof a.trimBeforeMatching!="boolean")throw new Error(`string-match-left-right/${t}(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!${Array.isArray(a.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""}`);let s=V(V({},R),a);if(typeof s.trimCharsBeforeMatching=="string"&&(s.trimCharsBeforeMatching=L(s.trimCharsBeforeMatching)),s.trimCharsBeforeMatching=s.trimCharsBeforeMatching.map(h=>y(h)?h:String(h)),!y(n)||!n.length)return!1;if(!Number.isInteger(e)||e<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 e}, equal to: | ||
${JSON.stringify(e,null,4)}`);let c,o;if(y(l))c=[l];else if(Array.isArray(l))c=l;else if(!l)c=l;else if(typeof l=="function")c=[],c.push(l);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 l}, equal to: | ||
@@ -13,0 +13,0 @@ ${JSON.stringify(l,null,4)}`);if(a&&!B(a))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 a}", and equal to: |
{ | ||
"name": "string-match-left-right", | ||
"version": "9.0.4", | ||
"version": "9.0.5", | ||
"description": "Match substrings on the left or right of a given index, ignoring whitespace", | ||
@@ -72,5 +72,5 @@ "keywords": [ | ||
"arrayiffy-if-string": "^5.0.3", | ||
"codsen-utils": "^1.1.0", | ||
"codsen-utils": "^1.1.1", | ||
"string-character-is-astral-surrogate": "^3.0.3" | ||
} | ||
} |
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
Updatedcodsen-utils@^1.1.1