json-variables 11.0.13 → 11.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.
package/README.md CHANGED
@@ -26,7 +26,7 @@
26
26
 
27
27
  ## Install
28
28
 
29
- The latest version is **ESM only**: Node 12+ is needed to use it and it must be `import`ed instead of `require`d. If your project is not on ESM yet and you want to use `require`, use an older version of this program, `10.1.0`.
29
+ This package is [pure ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c). If you're not ready yet, install an older version of this program, 10.1.0 (`npm i json-variables@10.1.0`).
30
30
 
31
31
  ```bash
32
32
  npm i json-variables
@@ -57,7 +57,7 @@ assert.deepEqual(
57
57
 
58
58
  ## Documentation
59
59
 
60
- Please [visit codsen.com](https://codsen.com/os/json-variables/) for a full description of the API and even a test <a href="https://codsen.com/os/json-variables/play">playground</a>.
60
+ Please [visit codsen.com](https://codsen.com/os/json-variables/) for a full description of the API.
61
61
 
62
62
  ## Contributing
63
63
 
@@ -1,16 +1,16 @@
1
1
  /**
2
2
  * @name json-variables
3
3
  * @fileoverview Resolves custom-marked, cross-referenced paths in parsed JSON
4
- * @version 11.0.13
4
+ * @version 11.0.14
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/json-variables/}
8
8
  */
9
9
 
10
- import{traverse as k}from"ast-monkey-traverse";import{isMatch as x}from"matcher";import d from"object-path";import{arrayiffy as F}from"arrayiffy-if-string";import{strFindHeadsTails as I}from"string-find-heads-tails";import{getByKey as _}from"ast-get-values-by-key";import{Ranges as B}from"ranges-push";import{rApply as S}from"ranges-apply";import{remDup as L}from"string-remove-duplicate-heads-tails";import{matchLeftIncl as U,matchRightIncl as M}from"string-match-left-right";var j="11.0.13";var de=j,q=Object.prototype.hasOwnProperty,K={heads:"%%_",tails:"_%%",headsNoWrap:"%%-",tailsNoWrap:"-%%",lookForDataContainers:!0,dataContainerIdentifierTails:"_data",wrapHeadsWith:"",wrapTailsWith:"",dontWrapVars:[],preventDoubleWrapping:!0,wrapGlobalFlipSwitch:!0,noSingleMarkers:!1,resolveToBoolIfAnyValuesContainBool:!0,resolveToFalseIfAnyValuesContainBool:!0,throwWhenNonStringInsertedInString:!1,allowUnresolved:!1};function u(e){return typeof e=="string"}function G(e){return typeof e=="number"}function A(e){return typeof e=="boolean"}function D(e){return e===null}function w(e){return e&&typeof e=="object"&&!Array.isArray(e)}function z(e){return e!=null}function g(e){return u(e)?e.trim():e}function Y(e){if(typeof e=="string"&&e.length>0&&e.indexOf(".")!==-1){for(let r=0,t=e.length;r<t;r++)if(e[r]===".")return e.slice(0,r)}return e}function Q(e){if(typeof e=="string"&&e.length>0&&e.indexOf(".")!==-1){for(let r=0,t=e.length;r<t;r++)if(e[r]===".")return e.slice(r+1)}return e}function J(e){if(typeof e=="string"&&e.length>0&&e.indexOf(".")!==-1){for(let r=e.length;r--;)if(e[r]===".")return e.slice(0,r)}return e}function P(e){if(typeof e=="string"&&e.length>0&&e.indexOf(".")!==-1){for(let r=e.length;r--;)if(e[r]===".")return e.slice(r+1)}return e}function T(e,r){return typeof e!="string"||!e.trim()?!1:!!(e.includes(r.heads)||e.includes(r.tails)||u(r.headsNoWrap)&&r.headsNoWrap.length>0&&e.includes(r.headsNoWrap)||u(r.tailsNoWrap)&&r.tailsNoWrap.length>0&&e.includes(r.tailsNoWrap))}function X(e,r,t){let l,i;return typeof e=="string"&&e.length>0&&M(e,0,r,{trimBeforeMatching:!0,cb:(n,a,o)=>(l=o,!0)})&&U(e,e.length-1,t,{trimBeforeMatching:!0,cb:(n,a,o)=>(i=+o+1,!0)})?e.slice(l,i):e}function H(e,r,t=!1,l,i,n){if(r.wrapHeadsWith||(r.wrapHeadsWith=""),r.wrapTailsWith||(r.wrapTailsWith=""),u(e)&&!t&&r.wrapGlobalFlipSwitch&&!r.dontWrapVars.some(a=>x(n,a))&&(!r.preventDoubleWrapping||r.preventDoubleWrapping&&u(e)&&!e.includes(r.wrapHeadsWith)&&!e.includes(r.wrapTailsWith)))return`${r.wrapHeadsWith}${e}${r.wrapTailsWith}`;if(t){if(!u(e))return e;let a=L(e,{heads:r.wrapHeadsWith,tails:r.wrapTailsWith});return u(a)?X(a,r.wrapHeadsWith,r.wrapTailsWith):a}return e}function Z(e,r,t,l){let i;if(t.indexOf(".")!==-1){let n=t,a=!0;if(l.lookForDataContainers&&typeof l.dataContainerIdentifierTails=="string"&&l.dataContainerIdentifierTails.length>0&&!n.endsWith(l.dataContainerIdentifierTails)){let o=d.get(e,n+l.dataContainerIdentifierTails);w(o)&&d.get(o,r)&&(i=d.get(o,r),a=!1)}for(;a&&n.indexOf(".")!==-1;){if(n=J(n),P(n)===r)throw new Error(`json-variables/findValues(): [THROW_ID_20] While trying to resolve: "${r}" at path "${t}", we encountered a closed loop. The parent key "${P(n)}" is called the same as the variable "${r}" we're looking for.`);if(l.lookForDataContainers&&typeof l.dataContainerIdentifierTails=="string"&&l.dataContainerIdentifierTails.length>0&&!n.endsWith(l.dataContainerIdentifierTails)){let o=d.get(e,n+l.dataContainerIdentifierTails);w(o)&&d.get(o,r)&&(i=d.get(o,r),a=!1)}if(i===void 0){let o=d.get(e,n);w(o)&&d.get(o,r)&&(i=d.get(o,r),a=!1)}}}if(i===void 0){let n=d.get(e,r);n!==void 0&&(i=n)}if(i===void 0)if(r.indexOf(".")===-1){let n=_(e,r);if(n.length>0){for(let a=0,o=n.length;a<o;a++)if(u(n[a].val)||A(n[a].val)||D(n[a].val)){i=n[a].val;break}else if(G(n[a].val)){i=String(n[a].val);break}else if(Array.isArray(n[a].val)){i=n[a].val.join("");break}}}else{let n=_(e,Y(r));if(n.length>0)for(let a=0,o=n.length;a<o;a++){let y=d.get(n[a].val,Q(r));y&&u(y)&&(i=y)}}return i}function R(e,r,t,l,i=[]){if(i.includes(t)){let c="";if(i.length>1){let m=` \u2192
10
+ import{traverse as k}from"ast-monkey-traverse";import{isMatch as x}from"matcher";import d from"object-path";import{arrayiffy as F}from"arrayiffy-if-string";import{strFindHeadsTails as I}from"string-find-heads-tails";import{getByKey as _}from"ast-get-values-by-key";import{Ranges as B}from"ranges-push";import{rApply as S}from"ranges-apply";import{remDup as L}from"string-remove-duplicate-heads-tails";import{matchLeftIncl as U,matchRightIncl as M}from"string-match-left-right";var j="11.0.14";var de=j,q=Object.prototype.hasOwnProperty,K={heads:"%%_",tails:"_%%",headsNoWrap:"%%-",tailsNoWrap:"-%%",lookForDataContainers:!0,dataContainerIdentifierTails:"_data",wrapHeadsWith:"",wrapTailsWith:"",dontWrapVars:[],preventDoubleWrapping:!0,wrapGlobalFlipSwitch:!0,noSingleMarkers:!1,resolveToBoolIfAnyValuesContainBool:!0,resolveToFalseIfAnyValuesContainBool:!0,throwWhenNonStringInsertedInString:!1,allowUnresolved:!1};function u(e){return typeof e=="string"}function G(e){return typeof e=="number"}function A(e){return typeof e=="boolean"}function D(e){return e===null}function w(e){return e&&typeof e=="object"&&!Array.isArray(e)}function z(e){return e!=null}function g(e){return u(e)?e.trim():e}function Y(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let r=0,t=e.length;r<t;r++)if(e[r]===".")return e.slice(0,r)}return e}function Q(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let r=0,t=e.length;r<t;r++)if(e[r]===".")return e.slice(r+1)}return e}function J(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let r=e.length;r--;)if(e[r]===".")return e.slice(0,r)}return e}function P(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let r=e.length;r--;)if(e[r]===".")return e.slice(r+1)}return e}function T(e,r){return typeof e!="string"||!e.trim()?!1:!!(e.includes(r.heads)||e.includes(r.tails)||u(r.headsNoWrap)&&r.headsNoWrap.length&&e.includes(r.headsNoWrap)||u(r.tailsNoWrap)&&r.tailsNoWrap.length&&e.includes(r.tailsNoWrap))}function X(e,r,t){let l,i;return typeof e=="string"&&e.length&&M(e,0,r,{trimBeforeMatching:!0,cb:(n,a,o)=>(l=o,!0)})&&U(e,e.length-1,t,{trimBeforeMatching:!0,cb:(n,a,o)=>(i=+o+1,!0)})?e.slice(l,i):e}function H(e,r,t=!1,l,i,n){if(r.wrapHeadsWith||(r.wrapHeadsWith=""),r.wrapTailsWith||(r.wrapTailsWith=""),u(e)&&!t&&r.wrapGlobalFlipSwitch&&!r.dontWrapVars.some(a=>x(n,a))&&(!r.preventDoubleWrapping||r.preventDoubleWrapping&&u(e)&&!e.includes(r.wrapHeadsWith)&&!e.includes(r.wrapTailsWith)))return`${r.wrapHeadsWith}${e}${r.wrapTailsWith}`;if(t){if(!u(e))return e;let a=L(e,{heads:r.wrapHeadsWith,tails:r.wrapTailsWith});return u(a)?X(a,r.wrapHeadsWith,r.wrapTailsWith):a}return e}function Z(e,r,t,l){let i;if(t.indexOf(".")!==-1){let n=t,a=!0;if(l.lookForDataContainers&&typeof l.dataContainerIdentifierTails=="string"&&l.dataContainerIdentifierTails.length&&!n.endsWith(l.dataContainerIdentifierTails)){let o=d.get(e,n+l.dataContainerIdentifierTails);w(o)&&d.get(o,r)&&(i=d.get(o,r),a=!1)}for(;a&&n.indexOf(".")!==-1;){if(n=J(n),P(n)===r)throw new Error(`json-variables/findValues(): [THROW_ID_20] While trying to resolve: "${r}" at path "${t}", we encountered a closed loop. The parent key "${P(n)}" is called the same as the variable "${r}" we're looking for.`);if(l.lookForDataContainers&&typeof l.dataContainerIdentifierTails=="string"&&l.dataContainerIdentifierTails.length&&!n.endsWith(l.dataContainerIdentifierTails)){let o=d.get(e,n+l.dataContainerIdentifierTails);w(o)&&d.get(o,r)&&(i=d.get(o,r),a=!1)}if(i===void 0){let o=d.get(e,n);w(o)&&d.get(o,r)&&(i=d.get(o,r),a=!1)}}}if(i===void 0){let n=d.get(e,r);n!==void 0&&(i=n)}if(i===void 0)if(r.indexOf(".")===-1){let n=_(e,r);if(n.length){for(let a=0,o=n.length;a<o;a++)if(u(n[a].val)||A(n[a].val)||D(n[a].val)){i=n[a].val;break}else if(G(n[a].val)){i=String(n[a].val);break}else if(Array.isArray(n[a].val)){i=n[a].val.join("");break}}}else{let n=_(e,Y(r));if(n.length)for(let a=0,o=n.length;a<o;a++){let y=d.get(n[a].val,Q(r));y&&u(y)&&(i=y)}}return i}function R(e,r,t,l,i=[]){if(i.includes(t)){let c="";if(i.length>1){let m=` \u2192
11
11
  `;c=i.reduce((E,b,O)=>E+(O===0?"":m)+(b===t?"\u{1F4A5} ":" ")+b,` Here's the path we travelled up until we hit the recursion:
12
12
 
13
13
  `),c+=`${m}\u{1F4A5} ${t}`}throw new Error(`json-variables/resolveString(): [THROW_ID_19] While trying to resolve: "${r}" at path "${t}", we encountered a closed loop, the key is referencing itself."${c}`)}let n={},a=Array.from(i);a.push(t);let o=new B;function y(c,m,E){for(let b=0,O=c.length;b<O;b++){let f=c[b],p=r.slice(f.headsEndAt,f.tailsStartAt);if(p.length===0)o.push(f.headsStartAt,f.tailsEndAt);else if(q.call(n,p)&&u(n[p]))o.push(f.headsStartAt,f.tailsEndAt,n[p]);else{let s=Z(e,p.trim(),t,l);if(s===void 0)if(l.allowUnresolved===!0)s="";else if(typeof l.allowUnresolved=="string")s=l.allowUnresolved;else throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_18] We couldn't find the value to resolve the variable ${r.slice(f.headsEndAt,f.tailsStartAt)}. We're at path: "${t}".`);if(!E&&l.throwWhenNonStringInsertedInString&&!u(s))throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_23] While resolving the variable ${r.slice(f.headsEndAt,f.tailsStartAt)} at path ${t}, it resolved into a non-string value, ${JSON.stringify(s,null,4)}. This is happening because options setting "throwWhenNonStringInsertedInString" is active (set to "true").`);if(A(s)){if(l.resolveToBoolIfAnyValuesContainBool)return o.wipe(),l.resolveToFalseIfAnyValuesContainBool?!1:s;s=""}else{if(D(s)&&E)return o.wipe(),s;Array.isArray(s)?s=String(s.join("")):D(s)?s="":s=String(s)}let N=t.includes(".")?`${J(t)}.${p}`:p;if(T(s,l)){let V=H(R(e,s,N,l,a),l,m,a,N,p.trim());typeof V=="string"&&o.push(f.headsStartAt,f.tailsEndAt,V)}else{n[p]=s;let V=H(s,l,m,a,N,p.trim());typeof V=="string"&&o.push(f.headsStartAt,f.tailsEndAt,V)}}}}let h;try{h=I(r,l.heads,l.tails,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(c){throw new Error(`json-variables/resolveString(): [THROW_ID_17] While trying to resolve string: "${r}" at path ${t}, something wrong with heads and tails was detected! Here's the internal error message:
14
14
  ${c}`)}let W=!1;h.length===1&&S(r,[[h[0].headsStartAt,h[0].tailsEndAt]]).trim()===""&&(W=!0);let $=y(h,!1,W);if(typeof $=="boolean"||$===null)return $;try{h=I(r,l.headsNoWrap,l.tailsNoWrap,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(c){throw new Error(`json-variables/resolveString(): [THROW_ID_22] While trying to resolve string: "${r}" at path ${t}, something wrong with no-wrap heads and no-wrap tails was detected! Here's the internal error message:
15
- ${c}`)}h.length===1&&S(r,[[h[0].headsStartAt,h[0].tailsEndAt]]).trim()===""&&(W=!0);let v=y(h,!0,W);return A(v)||D(v)?v:o?.current()?S(r,o.current()):r}function he(e,r){if(!arguments.length)throw new Error("json-variables/jVar(): [THROW_ID_01] Alas! Inputs are missing!");if(!w(e))throw new TypeError(`json-variables/jVar(): [THROW_ID_02] Alas! The input must be a plain object! Currently it's: ${Array.isArray(e)?"array":typeof e}`);if(r&&!w(r))throw new TypeError(`json-variables/jVar(): [THROW_ID_03] Alas! An Optional Options Object must be a plain object! Currently it's: ${Array.isArray(r)?"array":typeof r}`);let t={...K,...r};t.dontWrapVars?Array.isArray(t.dontWrapVars)||(t.dontWrapVars=F(t.dontWrapVars)):t.dontWrapVars=[];let l,i;if(t.dontWrapVars.length>0&&!t.dontWrapVars.every((a,o)=>u(a)?!0:(l=a,i=o,!1)))throw new Error(`json-variables/jVar(): [THROW_ID_05] Alas! All variable names set in opts.dontWrapVars should be of a string type. Computer detected a value "${l}" at index ${i}, which is not string but ${Array.isArray(l)?"array":typeof l}!`);if(t.heads==="")throw new Error("json-variables/jVar(): [THROW_ID_06] Alas! opts.heads are empty!");if(t.tails==="")throw new Error("json-variables/jVar(): [THROW_ID_07] Alas! opts.tails are empty!");if(t.lookForDataContainers&&t.dataContainerIdentifierTails==="")throw new Error("json-variables/jVar(): [THROW_ID_08] Alas! opts.dataContainerIdentifierTails is empty!");if(t.heads===t.tails)throw new Error("json-variables/jVar(): [THROW_ID_09] Alas! opts.heads and opts.tails can't be equal!");if(t.heads===t.headsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_10] Alas! opts.heads and opts.headsNoWrap can't be equal!");if(t.tails===t.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_11] Alas! opts.tails and opts.tailsNoWrap can't be equal!");if(t.headsNoWrap==="")throw new Error("json-variables/jVar(): [THROW_ID_12] Alas! opts.headsNoWrap is an empty string!");if(t.tailsNoWrap==="")throw new Error("json-variables/jVar(): [THROW_ID_13] Alas! opts.tailsNoWrap is an empty string!");if(t.headsNoWrap===t.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_14] Alas! opts.headsNoWrap and opts.tailsNoWrap can't be equal!");let n;return k(e,(a,o,y)=>{if(z(o)&&T(a,t))throw new Error(`json-variables/jVar(): [THROW_ID_15] Alas! Object keys can't contain variables!
15
+ ${c}`)}h.length===1&&S(r,[[h[0].headsStartAt,h[0].tailsEndAt]]).trim()===""&&(W=!0);let v=y(h,!0,W);return A(v)||D(v)?v:o?.current()?S(r,o.current()):r}function he(e,r){if(!arguments.length)throw new Error("json-variables/jVar(): [THROW_ID_01] Alas! Inputs are missing!");if(!w(e))throw new TypeError(`json-variables/jVar(): [THROW_ID_02] Alas! The input must be a plain object! Currently it's: ${Array.isArray(e)?"array":typeof e}`);if(r&&!w(r))throw new TypeError(`json-variables/jVar(): [THROW_ID_03] Alas! An Optional Options Object must be a plain object! Currently it's: ${Array.isArray(r)?"array":typeof r}`);let t={...K,...r};t.dontWrapVars?Array.isArray(t.dontWrapVars)||(t.dontWrapVars=F(t.dontWrapVars)):t.dontWrapVars=[];let l,i;if(t.dontWrapVars.length&&!t.dontWrapVars.every((a,o)=>u(a)?!0:(l=a,i=o,!1)))throw new Error(`json-variables/jVar(): [THROW_ID_05] Alas! All variable names set in opts.dontWrapVars should be of a string type. Computer detected a value "${l}" at index ${i}, which is not string but ${Array.isArray(l)?"array":typeof l}!`);if(t.heads==="")throw new Error("json-variables/jVar(): [THROW_ID_06] Alas! opts.heads are empty!");if(t.tails==="")throw new Error("json-variables/jVar(): [THROW_ID_07] Alas! opts.tails are empty!");if(t.lookForDataContainers&&t.dataContainerIdentifierTails==="")throw new Error("json-variables/jVar(): [THROW_ID_08] Alas! opts.dataContainerIdentifierTails is empty!");if(t.heads===t.tails)throw new Error("json-variables/jVar(): [THROW_ID_09] Alas! opts.heads and opts.tails can't be equal!");if(t.heads===t.headsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_10] Alas! opts.heads and opts.headsNoWrap can't be equal!");if(t.tails===t.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_11] Alas! opts.tails and opts.tailsNoWrap can't be equal!");if(t.headsNoWrap==="")throw new Error("json-variables/jVar(): [THROW_ID_12] Alas! opts.headsNoWrap is an empty string!");if(t.tailsNoWrap==="")throw new Error("json-variables/jVar(): [THROW_ID_13] Alas! opts.tailsNoWrap is an empty string!");if(t.headsNoWrap===t.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_14] Alas! opts.headsNoWrap and opts.tailsNoWrap can't be equal!");let n;return k(e,(a,o,y)=>{if(z(o)&&T(a,t))throw new Error(`json-variables/jVar(): [THROW_ID_15] Alas! Object keys can't contain variables!
16
16
  Please check the following key: ${a}`);if(o!==void 0?n=o:n=a,n==="")return n;if(t.heads.length!==0&&g(n)===g(t.heads)||t.tails.length!==0&&g(n)===g(t.tails)||t.headsNoWrap.length!==0&&g(n)===g(t.headsNoWrap)||t.tailsNoWrap.length!==0&&g(n)===g(t.tailsNoWrap)){if(!t.noSingleMarkers)return n;throw new Error(`json-variables/jVar(): [THROW_ID_16] Alas! While processing the input, we stumbled upon ${g(n)} which is equal to ${g(n)===g(t.heads)?"heads":""}${g(n)===g(t.tails)?"tails":""}${u(t.headsNoWrap)&&g(n)===g(t.headsNoWrap)?"headsNoWrap":""}${u(t.tailsNoWrap)&&g(n)===g(t.tailsNoWrap)?"tailsNoWrap":""}. If you wouldn't have set opts.noSingleMarkers to "true" this error would not happen and computer would have left the current element (${g(n)}) alone`)}return u(n)&&T(n,t)?R(e,n,y.path,t):n})}export{K as defaults,he as jVar,de as version};
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @name json-variables
3
3
  * @fileoverview Resolves custom-marked, cross-referenced paths in parsed JSON
4
- * @version 11.0.13
4
+ * @version 11.0.14
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/json-variables/}
@@ -11,12 +11,12 @@ var jsonVariables=(()=>{var ar=Object.create;var q=Object.defineProperty,or=Obje
11
11
  ${JSON.stringify(r,null,4)}`);let l,s;if(he(i))l=[i];else if(Array.isArray(i))l=i;else if(!i)l=i;else if(typeof i=="function")l=[],l.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:
12
12
  ${JSON.stringify(i,null,4)}`);if(o&&!kt(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
13
  ${JSON.stringify(o,null,4)}`);let h=0,a="";if((n==null?void 0:n.trimCharsBeforeMatching)&&n.trimCharsBeforeMatching.some((g,c)=>g.length>1?(h=c,a=g,!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 ${h} is longer than 1 character, ${a.length} (equals to ${a}). 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&&he(l[0])&&!l[0].trim()){if(typeof n.cb=="function"){let c,T=r;if((e==="matchLeftIncl"||e==="matchRight")&&(T+=1),e[5]==="L")for(let d=T;d--;){let f=t[d];if((!n.trimBeforeMatching||n.trimBeforeMatching&&f!==void 0&&f.trim())&&(!n.trimCharsBeforeMatching||!n.trimCharsBeforeMatching.length||f!==void 0&&!n.trimCharsBeforeMatching.includes(f))){c=d;break}}else if(e.startsWith("matchRight"))for(let d=T;d<t.length;d++){let f=t[d];if((!n.trimBeforeMatching||n.trimBeforeMatching&&f.trim())&&(!n.trimCharsBeforeMatching||!n.trimCharsBeforeMatching.length||!n.trimCharsBeforeMatching.includes(f))){c=d;break}}if(c===void 0)return!1;let m=t[c],u=c+1,y="";return u&&u>0&&(y=t.slice(0,u)),e[5]==="L"||c&&c>0&&(y=t.slice(c)),n.cb(m,y,c)}let g="";throw o||(g=" 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!${g}`)}for(let g=0,c=l.length;g<c;g++){s=typeof l[g]=="function";let T=l[g],m,u,y="",d=r;e==="matchRight"?d+=1:e==="matchLeft"&&(d-=1);let f=ni(t,d,T,n,s,p=>e[5]==="L"?p-1:p+1);if(f&&s&&typeof T=="function"&&T()==="EOL")return T()&&(n.cb?n.cb(m,y,u):!0)?T():!1;if(Number.isInteger(f)&&(u=e.startsWith("matchLeft")?f-1:f+1,e[5]==="L"?y=t.slice(0,f):y=t.slice(u)),u<0&&(u=void 0),t[u]&&(m=t[u]),Number.isInteger(f)&&(n.cb?n.cb(m,y,u):!0))return T}return!1}function k(e,t,r,i){return qt("matchLeftIncl",e,t,r,i)}function W(e,t,r,i){return qt("matchRightIncl",e,t,r,i)}function ii(e){return e&&typeof e=="object"&&!Array.isArray(e)}function S(e){return typeof e=="string"}var Kt={fromIndex:0,throwWhenSomethingWrongIsDetected:!0,allowWholeValueToBeOnlyHeadsOrTails:!0,source:"string-find-heads-tails",matchHeadsAndTailsStrictlyInPairsByTheirOrder:!1,relaxedAPI:!1};function Pe(e,t,r,i){if(i&&!ii(i))throw new TypeError(`string-find-heads-tails: [THROW_ID_01] the fourth input argument, an Optional Options Object, must be a plain object! Currently it's equal to: ${i} (type: ${typeof i})`);let o=$($({},Kt),i);if(typeof o.fromIndex=="string"&&/^\d*$/.test(o.fromIndex))o.fromIndex=Number(o.fromIndex);else if(!Number.isInteger(o.fromIndex)||o.fromIndex<0)throw new TypeError(`${o.source} [THROW_ID_18] the fourth input argument must be a natural number or zero! Currently it's: ${o.fromIndex}`);if(!S(e)||e.length===0){if(o.relaxedAPI)return[];throw new TypeError(`string-find-heads-tails: [THROW_ID_02] the first input argument, input string, must be a non-zero-length string! Currently it's: ${typeof e}, equal to: ${e}`)}let n,l;if(typeof t!="string"&&!Array.isArray(t)){if(o.relaxedAPI)return[];throw new TypeError(`string-find-heads-tails: [THROW_ID_03] the second input argument, heads, must be either a string or an array of strings! Currently it's: ${typeof t}, equal to:
14
- ${JSON.stringify(t,null,4)}`)}else if(typeof t=="string")if(t.length===0){if(o.relaxedAPI)return[];throw new TypeError("string-find-heads-tails: [THROW_ID_04] the second input argument, heads, must be a non-empty string! Currently it's empty.")}else t=I(t);else if(Array.isArray(t))if(t.length===0){if(o.relaxedAPI)return[];throw new TypeError("string-find-heads-tails: [THROW_ID_05] the second input argument, heads, must be a non-empty array and contain at least one string! Currently it's empty.")}else if(t.every((u,y)=>(n=u,l=y,S(u)))){if(!t.every((u,y)=>(l=y,S(u)&&u.length>0&&u.trim()!=="")))if(o.relaxedAPI){if(t=t.filter(u=>S(u)&&u.length>0),t.length===0)return[]}else throw new TypeError(`string-find-heads-tails: [THROW_ID_07] the second input argument, heads, should not contain empty strings! For example, there's one detected at index ${l} of heads array:
15
- ${JSON.stringify(t,null,4)}.`)}else if(o.relaxedAPI){if(t=t.filter(u=>S(u)&&u.length>0),t.length===0)return[]}else throw new TypeError(`string-find-heads-tails: [THROW_ID_06] the second input argument, heads, contains non-string elements! For example, element at ${l}th index is ${typeof n}, equal to:
14
+ ${JSON.stringify(t,null,4)}`)}else if(typeof t=="string")if(t.length===0){if(o.relaxedAPI)return[];throw new TypeError("string-find-heads-tails: [THROW_ID_04] the second input argument, heads, must be a non-empty string! Currently it's empty.")}else t=I(t);else if(Array.isArray(t))if(t.length===0){if(o.relaxedAPI)return[];throw new TypeError("string-find-heads-tails: [THROW_ID_05] the second input argument, heads, must be a non-empty array and contain at least one string! Currently it's empty.")}else if(t.every((u,y)=>(n=u,l=y,S(u)))){if(!t.every((u,y)=>(l=y,S(u)&&u.length&&u.trim()!=="")))if(o.relaxedAPI){if(t=t.filter(u=>S(u)&&u.length),t.length===0)return[]}else throw new TypeError(`string-find-heads-tails: [THROW_ID_07] the second input argument, heads, should not contain empty strings! For example, there's one detected at index ${l} of heads array:
15
+ ${JSON.stringify(t,null,4)}.`)}else if(o.relaxedAPI){if(t=t.filter(u=>S(u)&&u.length),t.length===0)return[]}else throw new TypeError(`string-find-heads-tails: [THROW_ID_06] the second input argument, heads, contains non-string elements! For example, element at ${l}th index is ${typeof n}, equal to:
16
16
  ${JSON.stringify(n,null,4)}. Whole heads array looks like:
17
17
  ${JSON.stringify(t,null,4)}`);if(!S(r)&&!Array.isArray(r)){if(o.relaxedAPI)return[];throw new TypeError(`string-find-heads-tails: [THROW_ID_08] the third input argument, tails, must be either a string or an array of strings! Currently it's: ${typeof r}, equal to:
18
- ${JSON.stringify(r,null,4)}`)}else if(S(r))if(r.length===0){if(o.relaxedAPI)return[];throw new TypeError("string-find-heads-tails: [THROW_ID_09] the third input argument, tails, must be a non-empty string! Currently it's empty.")}else r=I(r);else if(Array.isArray(r))if(r.length===0){if(o.relaxedAPI)return[];throw new TypeError("string-find-heads-tails: [THROW_ID_10] the third input argument, tails, must be a non-empty array and contain at least one string! Currently it's empty.")}else if(r.every((u,y)=>(n=u,l=y,S(u)))){if(!r.every((u,y)=>(l=y,S(u)&&u.length>0&&u.trim()!=="")))if(o.relaxedAPI){if(r=r.filter(u=>S(u)&&u.length>0),r.length===0)return[]}else throw new TypeError(`string-find-heads-tails: [THROW_ID_12] the third input argument, tails, should not contain empty strings! For example, there's one detected at index ${l}. Whole tails array is equal to:
19
- ${JSON.stringify(r,null,4)}`)}else if(o.relaxedAPI){if(r=r.filter(u=>S(u)&&u.length>0),r.length===0)return[]}else throw new TypeError(`string-find-heads-tails: [THROW_ID_11] the third input argument, tails, contains non-string elements! For example, element at ${l}th index is ${typeof n}, equal to:
18
+ ${JSON.stringify(r,null,4)}`)}else if(S(r))if(r.length===0){if(o.relaxedAPI)return[];throw new TypeError("string-find-heads-tails: [THROW_ID_09] the third input argument, tails, must be a non-empty string! Currently it's empty.")}else r=I(r);else if(Array.isArray(r))if(r.length===0){if(o.relaxedAPI)return[];throw new TypeError("string-find-heads-tails: [THROW_ID_10] the third input argument, tails, must be a non-empty array and contain at least one string! Currently it's empty.")}else if(r.every((u,y)=>(n=u,l=y,S(u)))){if(!r.every((u,y)=>(l=y,S(u)&&u.length&&u.trim()!=="")))if(o.relaxedAPI){if(r=r.filter(u=>S(u)&&u.length),r.length===0)return[]}else throw new TypeError(`string-find-heads-tails: [THROW_ID_12] the third input argument, tails, should not contain empty strings! For example, there's one detected at index ${l}. Whole tails array is equal to:
19
+ ${JSON.stringify(r,null,4)}`)}else if(o.relaxedAPI){if(r=r.filter(u=>S(u)&&u.length),r.length===0)return[]}else throw new TypeError(`string-find-heads-tails: [THROW_ID_11] the third input argument, tails, contains non-string elements! For example, element at ${l}th index is ${typeof n}, equal to:
20
20
  ${JSON.stringify(n,null,4)}. Whole tails array is equal to:
21
21
  ${JSON.stringify(r,null,4)}`);let s=o.source===Kt.source;if(o.throwWhenSomethingWrongIsDetected&&!o.allowWholeValueToBeOnlyHeadsOrTails){if(I(t).includes(e))throw new Error(`${o.source}${s?": [THROW_ID_16]":""} the whole input string can't be equal to ${S(t)?"":"one of "}heads (${e})!`);if(I(r).includes(e))throw new Error(`${o.source}${s?": [THROW_ID_17]":""} the whole input string can't be equal to ${S(r)?"":"one of "}tails (${e})!`)}let h=t.concat(r).map(u=>u.charAt(0)).reduce((u,y)=>y.charCodeAt(0)>u[1]?[u[0],y.charCodeAt(0)]:y.charCodeAt(0)<u[0]?[y.charCodeAt(0),u[1]]:u,[t[0].charCodeAt(0),t[0].charCodeAt(0)]),a=[],g=!1,c={},T="",m;for(let u=o.fromIndex,y=e.length;u<y;u++){let d=e[u].charCodeAt(0);if(d<=h[1]&&d>=h[0]){let f=W(e,u,t);if(f&&o.matchHeadsAndTailsStrictlyInPairsByTheirOrder){for(let w=t.length;w--;)if(t[w]===f){m=w;break}}if(typeof f=="string")if(g){if(o.throwWhenSomethingWrongIsDetected)throw new TypeError(`${o.source}${s?": [THROW_ID_19]":""} When processing "${e}", we found heads (${e.slice(u,u+f.length)}) starting at character with index number "${u}" and there was another set of heads before it! Generally speaking, there should be "heads-tails-heads-tails", not "heads-heads-tails"!
22
22
  We're talking about the area of the code:
@@ -34,15 +34,15 @@ To turn off this error being thrown, set opts.throwWhenSomethingWrongIsDetected
34
34
  `;if(!n)return n;let g=0,c=0,T="";for(let m=0,u=n.length;m<u;m++)(n[m]===h||n[m]===a&&n[m-1]!==h)&&c++,`\r
35
35
  `.includes(n[m])||n[m]===r?(g=0,n[m]===r?T+=n[m]:n[m]===h?c<=l&&(T+=n[m],n[m+1]===a&&(T+=n[m+1],m++)):n[m]===a&&(!n[m-1]||n[m-1]!==h)&&c<=l&&(T+=n[m])):(g++,!n[m+1]&&!c&&(T+=" "));return T}if(typeof e=="string"&&e.length){let n=1;typeof+t=="number"&&Number.isInteger(+t)&&+t>=0&&(n=+t);let l="",s="";if(!e.trim())l=e;else if(!e[0].trim()){for(let h=0,a=e.length;h<a;h++)if(e[h].trim()){l=e.slice(0,h);break}}if(e.trim()&&(e.slice(-1).trim()===""||e.slice(-1)===r)){for(let h=e.length;h--;)if(e[h].trim()){s=e.slice(h+1);break}}return`${o(l,n,!1)}${e.trim()}${i(o(i(s),n,!0))}`}return e}var si={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function Ut(e,t){if(!Array.isArray(e)||!e.length)return e;let r=$($({},si),t),i,o;if(r.strictlyTwoElementsInRangeArrays&&!e.every((s,h)=>!Array.isArray(s)||s.length!==2?(i=h,o=s.length,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_03] The first argument should be an array and must consist of arrays which are natural number indexes representing TWO string index ranges. However, ${i}th range (${JSON.stringify(e[i],null,4)}) has not two but ${o} elements!`);if(!e.every((s,h)=>!Array.isArray(s)||!Number.isInteger(s[0])||s[0]<0||!Number.isInteger(s[1])||s[1]<0?(i=h,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_04] The first argument should be an array and must consist of arrays which are natural number indexes representing string index ranges. However, ${i}th range (${JSON.stringify(e[i],null,4)}) does not consist of only natural numbers!`);let n=e.length**2,l=0;return Array.from(e).sort((s,h)=>(r.progressFn&&(l+=1,r.progressFn(Math.floor(l*100/n))),s[0]===h[0]?s[1]<h[1]?-1:s[1]>h[1]?1:0:s[0]<h[0]?-1:1))}var Gt={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function ai(e,t){function r(a){return a&&typeof a=="object"&&!Array.isArray(a)}if(!Array.isArray(e)||!e.length)return null;let i;if(t)if(r(t)){if(i=$($({},Gt),t),i.progressFn&&r(i.progressFn)&&!Object.keys(i.progressFn).length)i.progressFn=null;else if(i.progressFn&&typeof i.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof i.progressFn}", equal to ${JSON.stringify(i.progressFn,null,4)}`);if(![1,2,"1","2"].includes(i.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof i.mergeType}", equal to ${JSON.stringify(i.mergeType,null,4)}`);if(typeof i.joinRangesThatTouchEdges!="boolean")throw new Error(`ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof i.joinRangesThatTouchEdges}", equal to ${JSON.stringify(i.joinRangesThatTouchEdges,null,4)}`)}else throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as:
36
36
  ${JSON.stringify(t,null,4)} (type ${typeof t})`);else i=$({},Gt);let o=e.filter(a=>Array.isArray(a)).map(a=>[...a]).filter(a=>a[2]!==void 0||a[0]!==a[1]),n,l,s;i.progressFn?n=Ut(o,{progressFn:a=>{s=Math.floor(a/5),s!==l&&(l=s,i.progressFn(s))}}):n=Ut(o);let h=n.length-1;for(let a=h;a>0;a--)i.progressFn&&(s=Math.floor((1-a/h)*78)+21,s!==l&&s>l&&(l=s,i.progressFn(s))),(n[a][0]<=n[a-1][0]||!i.joinRangesThatTouchEdges&&n[a][0]<n[a-1][1]||i.joinRangesThatTouchEdges&&n[a][0]<=n[a-1][1])&&(n[a-1][0]=Math.min(n[a][0],n[a-1][0]),n[a-1][1]=Math.max(n[a][1],n[a-1][1]),n[a][2]!==void 0&&(n[a-1][0]>=n[a][0]||n[a-1][1]<=n[a][1])&&n[a-1][2]!==null&&(n[a][2]===null&&n[a-1][2]!==null?n[a-1][2]=null:n[a-1][2]!=null?+i.mergeType==2&&n[a-1][0]===n[a][0]?n[a-1][2]=n[a][2]:n[a-1][2]+=n[a][2]:n[a-1][2]=n[a][2]),n.splice(a,1),a=n.length);return n.length?n:null}function C(e){return e!=null}function V(e){return Number.isInteger(e)&&e>=0}function X(e){return typeof e=="string"}var oi={limitToBeAddedWhitespace:!1,limitLinebreaksCount:1,mergeType:1},Z=class{constructor(e){be(this,"ranges");be(this,"opts");let t=$($({},oi),e);if(t.mergeType&&t.mergeType!==1&&t.mergeType!==2)if(X(t.mergeType)&&t.mergeType.trim()==="1")t.mergeType=1;else if(X(t.mergeType)&&t.mergeType.trim()==="2")t.mergeType=2;else throw new Error(`ranges-push: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof t.mergeType}", equal to ${JSON.stringify(t.mergeType,null,4)}`);this.opts=t,this.ranges=[]}add(e,t,r){if(e==null&&t==null)return;if(C(e)&&!C(t)){if(Array.isArray(e)){if(e.length){if(e.some(n=>Array.isArray(n))){e.forEach(n=>{Array.isArray(n)&&this.add(...n)});return}e.length&&V(+e[0])&&V(+e[1])&&this.add(...e)}return}throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_12] the first input argument, "from" is set (${JSON.stringify(e,null,0)}) but second-one, "to" is not (${JSON.stringify(t,null,0)})`)}else if(!C(e)&&C(t))throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_13] the second input argument, "to" is set (${JSON.stringify(t,null,0)}) but first-one, "from" is not (${JSON.stringify(e,null,0)})`);let i=+e,o=+t;if(V(r)&&(r=String(r)),V(i)&&V(o)){if(C(r)&&!X(r)&&!V(r))throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_08] The third argument, the value to add, was given not as string but ${typeof r}, equal to:
37
- ${JSON.stringify(r,null,4)}`);if(C(this.ranges)&&Array.isArray(this.last())&&i===this.last()[1]){if(this.last()[1]=o,this.last()[2],this.last()[2]!==null&&C(r)){let n=this.last()[2]&&this.last()[2].length>0&&(!this.opts||!this.opts.mergeType||this.opts.mergeType===1)?`${this.last()[2]}${r}`:r;this.opts.limitToBeAddedWhitespace&&(n=pe(n,this.opts.limitLinebreaksCount)),X(n)&&!n.length||(this.last()[2]=n)}}else{this.ranges||(this.ranges=[]);let n=r!==void 0&&!(X(r)&&!r.length)?[i,o,r&&this.opts.limitToBeAddedWhitespace?pe(r,this.opts.limitLinebreaksCount):r]:[i,o];this.ranges.push(n)}}else throw V(i)&&i>=0?new TypeError(`ranges-push/Ranges/add(): [THROW_ID_10] "to" value, the second input argument, must be a natural number or zero! Currently it's of a type "${typeof o}" equal to: ${JSON.stringify(o,null,4)}`):new TypeError(`ranges-push/Ranges/add(): [THROW_ID_09] "from" value, the first input argument, must be a natural number or zero! Currently it's of a type "${typeof i}" equal to: ${JSON.stringify(i,null,4)}`)}push(e,t,r){this.add(e,t,r)}current(){return Array.isArray(this.ranges)&&this.ranges.length?(this.ranges=ai(this.ranges,{mergeType:this.opts.mergeType}),this.ranges&&this.opts.limitToBeAddedWhitespace?this.ranges.map(e=>C(e[2])?[e[0],e[1],pe(e[2],this.opts.limitLinebreaksCount)]:e):this.ranges):null}wipe(){this.ranges=[]}replace(e){if(Array.isArray(e)&&e.length)if(Array.isArray(e[0])&&V(e[0][0]))this.ranges=Array.from(e);else throw new Error(`ranges-push/Ranges/replace(): [THROW_ID_11] Single range was given but we expected array of arrays! The first element, ${JSON.stringify(e[0],null,4)} should be an array and its first element should be an integer, a string index.`);else this.ranges=[]}last(){return Array.isArray(this.ranges)&&this.ranges.length?this.ranges[this.ranges.length-1]:null}};var li={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function Fe(e,t){if(!Array.isArray(e)||!e.length)return e;let r=$($({},li),t),i,o;if(r.strictlyTwoElementsInRangeArrays&&!e.every((s,h)=>!Array.isArray(s)||s.length!==2?(i=h,o=s.length,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_03] The first argument should be an array and must consist of arrays which are natural number indexes representing TWO string index ranges. However, ${i}th range (${JSON.stringify(e[i],null,4)}) has not two but ${o} elements!`);if(!e.every((s,h)=>!Array.isArray(s)||!Number.isInteger(s[0])||s[0]<0||!Number.isInteger(s[1])||s[1]<0?(i=h,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_04] The first argument should be an array and must consist of arrays which are natural number indexes representing string index ranges. However, ${i}th range (${JSON.stringify(e[i],null,4)}) does not consist of only natural numbers!`);let n=e.length**2,l=0;return Array.from(e).sort((s,h)=>(r.progressFn&&(l+=1,r.progressFn(Math.floor(l*100/n))),s[0]===h[0]?s[1]<h[1]?-1:s[1]>h[1]?1:0:s[0]<h[0]?-1:1))}var zt={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function Yt(e,t){function r(a){return a&&typeof a=="object"&&!Array.isArray(a)}if(!Array.isArray(e)||!e.length)return null;let i;if(t)if(r(t)){if(i=$($({},zt),t),i.progressFn&&r(i.progressFn)&&!Object.keys(i.progressFn).length)i.progressFn=null;else if(i.progressFn&&typeof i.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof i.progressFn}", equal to ${JSON.stringify(i.progressFn,null,4)}`);if(![1,2,"1","2"].includes(i.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof i.mergeType}", equal to ${JSON.stringify(i.mergeType,null,4)}`);if(typeof i.joinRangesThatTouchEdges!="boolean")throw new Error(`ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof i.joinRangesThatTouchEdges}", equal to ${JSON.stringify(i.joinRangesThatTouchEdges,null,4)}`)}else throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as:
37
+ ${JSON.stringify(r,null,4)}`);if(C(this.ranges)&&Array.isArray(this.last())&&i===this.last()[1]){if(this.last()[1]=o,this.last()[2],this.last()[2]!==null&&C(r)){let n=this.last()[2]&&this.last()[2].length&&(!this.opts||!this.opts.mergeType||this.opts.mergeType===1)?`${this.last()[2]}${r}`:r;this.opts.limitToBeAddedWhitespace&&(n=pe(n,this.opts.limitLinebreaksCount)),X(n)&&!n.length||(this.last()[2]=n)}}else{this.ranges||(this.ranges=[]);let n=r!==void 0&&!(X(r)&&!r.length)?[i,o,r&&this.opts.limitToBeAddedWhitespace?pe(r,this.opts.limitLinebreaksCount):r]:[i,o];this.ranges.push(n)}}else throw V(i)&&i>=0?new TypeError(`ranges-push/Ranges/add(): [THROW_ID_10] "to" value, the second input argument, must be a natural number or zero! Currently it's of a type "${typeof o}" equal to: ${JSON.stringify(o,null,4)}`):new TypeError(`ranges-push/Ranges/add(): [THROW_ID_09] "from" value, the first input argument, must be a natural number or zero! Currently it's of a type "${typeof i}" equal to: ${JSON.stringify(i,null,4)}`)}push(e,t,r){this.add(e,t,r)}current(){return Array.isArray(this.ranges)&&this.ranges.length?(this.ranges=ai(this.ranges,{mergeType:this.opts.mergeType}),this.ranges&&this.opts.limitToBeAddedWhitespace?this.ranges.map(e=>C(e[2])?[e[0],e[1],pe(e[2],this.opts.limitLinebreaksCount)]:e):this.ranges):null}wipe(){this.ranges=[]}replace(e){if(Array.isArray(e)&&e.length)if(Array.isArray(e[0])&&V(e[0][0]))this.ranges=Array.from(e);else throw new Error(`ranges-push/Ranges/replace(): [THROW_ID_11] Single range was given but we expected array of arrays! The first element, ${JSON.stringify(e[0],null,4)} should be an array and its first element should be an integer, a string index.`);else this.ranges=[]}last(){return Array.isArray(this.ranges)&&this.ranges.length?this.ranges[this.ranges.length-1]:null}};var li={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function Fe(e,t){if(!Array.isArray(e)||!e.length)return e;let r=$($({},li),t),i,o;if(r.strictlyTwoElementsInRangeArrays&&!e.every((s,h)=>!Array.isArray(s)||s.length!==2?(i=h,o=s.length,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_03] The first argument should be an array and must consist of arrays which are natural number indexes representing TWO string index ranges. However, ${i}th range (${JSON.stringify(e[i],null,4)}) has not two but ${o} elements!`);if(!e.every((s,h)=>!Array.isArray(s)||!Number.isInteger(s[0])||s[0]<0||!Number.isInteger(s[1])||s[1]<0?(i=h,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_04] The first argument should be an array and must consist of arrays which are natural number indexes representing string index ranges. However, ${i}th range (${JSON.stringify(e[i],null,4)}) does not consist of only natural numbers!`);let n=e.length**2,l=0;return Array.from(e).sort((s,h)=>(r.progressFn&&(l+=1,r.progressFn(Math.floor(l*100/n))),s[0]===h[0]?s[1]<h[1]?-1:s[1]>h[1]?1:0:s[0]<h[0]?-1:1))}var zt={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function Yt(e,t){function r(a){return a&&typeof a=="object"&&!Array.isArray(a)}if(!Array.isArray(e)||!e.length)return null;let i;if(t)if(r(t)){if(i=$($({},zt),t),i.progressFn&&r(i.progressFn)&&!Object.keys(i.progressFn).length)i.progressFn=null;else if(i.progressFn&&typeof i.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof i.progressFn}", equal to ${JSON.stringify(i.progressFn,null,4)}`);if(![1,2,"1","2"].includes(i.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof i.mergeType}", equal to ${JSON.stringify(i.mergeType,null,4)}`);if(typeof i.joinRangesThatTouchEdges!="boolean")throw new Error(`ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof i.joinRangesThatTouchEdges}", equal to ${JSON.stringify(i.joinRangesThatTouchEdges,null,4)}`)}else throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as:
38
38
  ${JSON.stringify(t,null,4)} (type ${typeof t})`);else i=$({},zt);let o=e.filter(a=>Array.isArray(a)).map(a=>[...a]).filter(a=>a[2]!==void 0||a[0]!==a[1]),n,l,s;i.progressFn?n=Fe(o,{progressFn:a=>{s=Math.floor(a/5),s!==l&&(l=s,i.progressFn(s))}}):n=Fe(o);let h=n.length-1;for(let a=h;a>0;a--)i.progressFn&&(s=Math.floor((1-a/h)*78)+21,s!==l&&s>l&&(l=s,i.progressFn(s))),(n[a][0]<=n[a-1][0]||!i.joinRangesThatTouchEdges&&n[a][0]<n[a-1][1]||i.joinRangesThatTouchEdges&&n[a][0]<=n[a-1][1])&&(n[a-1][0]=Math.min(n[a][0],n[a-1][0]),n[a-1][1]=Math.max(n[a][1],n[a-1][1]),n[a][2]!==void 0&&(n[a-1][0]>=n[a][0]||n[a-1][1]<=n[a][1])&&n[a-1][2]!==null&&(n[a][2]===null&&n[a-1][2]!==null?n[a-1][2]=null:n[a-1][2]!=null?+i.mergeType==2&&n[a-1][0]===n[a][0]?n[a-1][2]=n[a][2]:n[a-1][2]+=n[a][2]:n[a-1][2]=n[a][2]),n.splice(a,1),a=n.length);return n.length?n:null}var fi=!0,ke="Invariant failed";function Xt(e,t){if(!e){if(fi)throw new Error(ke);var r=typeof t=="function"?t():t,i=r?ke+": "+r:ke;throw new Error(i)}}function L(e,t,r){let i=0,o=0;if(arguments.length===0)throw new Error("ranges-apply: [THROW_ID_01] inputs missing!");if(typeof e!="string")throw new TypeError(`ranges-apply: [THROW_ID_02] first input argument must be a string! Currently it's: ${typeof e}, equal to: ${JSON.stringify(e,null,4)}`);if(t&&!Array.isArray(t))throw new TypeError(`ranges-apply: [THROW_ID_03] second input argument must be an array (or null)! Currently it's: ${typeof t}, equal to: ${JSON.stringify(t,null,4)}`);if(r&&typeof r!="function")throw new TypeError(`ranges-apply: [THROW_ID_04] the third input argument must be a function (or falsey)! Currently it's: ${typeof r}, equal to: ${JSON.stringify(r,null,4)}`);if(!t||!t.filter(g=>g).length)return e;let n;Array.isArray(t)&&Number.isInteger(t[0])&&Number.isInteger(t[1])?n=[Array.from(t)]:n=Array.from(t);let l=n.length,s=0;n.filter(g=>g).forEach((g,c)=>{if(r&&(i=Math.floor(s/l*10),i!==o&&(o=i,r(i))),!Array.isArray(g))throw new TypeError(`ranges-apply: [THROW_ID_05] ranges array, second input arg., has ${c}th element not an array: ${JSON.stringify(g,null,4)}, which is ${typeof g}`);if(!Number.isInteger(g[0])){if(!Number.isInteger(+g[0])||+g[0]<0)throw new TypeError(`ranges-apply: [THROW_ID_06] ranges array, second input arg. has ${c}th element, array ${JSON.stringify(g,null,0)}. Its first element is not an integer, string index, but ${typeof g[0]}, equal to: ${JSON.stringify(g[0],null,4)}.`);n[c][0]=+n[c][0]}if(!Number.isInteger(g[1])){if(!Number.isInteger(+g[1])||+g[1]<0)throw new TypeError(`ranges-apply: [THROW_ID_07] ranges array, second input arg. has ${c}th element, array ${JSON.stringify(g,null,0)}. Its second element is not an integer, string index, but ${typeof g[1]}, equal to: ${JSON.stringify(g[1],null,4)}.`);n[c][1]=+n[c][1]}s+=1});let h=Yt(n,{progressFn:g=>{r&&(i=10+Math.floor(g/10),i!==o&&(o=i,r(i)))}});Xt(h);let a=h.length;if(a>0){let g=e.slice(h[a-1][1]);e=h.reduce((c,T,m,u)=>{r&&(i=20+Math.floor(m/a*80),i!==o&&(o=i,r(i)));let y=m===0?0:u[m-1][1],d=u[m][0];return`${c}${e.slice(y,d)}${u[m][2]||""}`},""),e+=g}return e}var Zt=U(Ve(),1);var ui={classicTrim:!1,cr:!1,lf:!1,tab:!1,space:!0,nbsp:!1};function Q(e,t){if(typeof e!="string")throw new Error(`string-trim-spaces-only: [THROW_ID_01] input must be string! It was given as ${typeof e}, equal to:
39
39
  ${JSON.stringify(e,null,4)}`);let r=$($({},ui),t);function i(l){return r.classicTrim&&!l.trim()||!r.classicTrim&&(r.space&&l===" "||r.cr&&l==="\r"||r.lf&&l===`
40
- `||r.tab&&l===" "||r.nbsp&&l==="\xA0")}let o,n;if(e.length){if(i(e[0]))for(let l=0,s=e.length;l<s;l++){if(!i(e[l])){o=l;break}if(l===e.length-1)return{res:"",ranges:[[0,e.length]]}}if(i(e[e.length-1])){for(let l=e.length;l--;)if(!i(e[l])){n=l+1;break}}return o?n?{res:e.slice(o,n),ranges:[[0,o],[n,e.length]]}:{res:e.slice(o),ranges:[[0,o]]}:n?{res:e.slice(0,n),ranges:[[n,e.length]]}:{res:e,ranges:[]}}return{res:"",ranges:[]}}var gi={heads:["{{"],tails:["}}"]};function Qt(e,t){let r=Object.prototype.hasOwnProperty;if(e===void 0)throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_01] The input is missing!");if(typeof e!="string")return e;if(t&&!(0,Zt.default)(t))throw new Error(`string-remove-duplicate-heads-tails: [THROW_ID_03] The given options are not a plain object but ${typeof t}!`);let i=$({},t);if(i&&r.call(i,"heads"))if(I(i.heads).every(y=>typeof y=="string"||Array.isArray(y)))typeof i.heads=="string"&&(i.heads=I(i.heads));else throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_04] The opts.heads contains elements which are not string-type!");if(i&&r.call(i,"tails"))if(I(i.tails).every(y=>typeof y=="string"||Array.isArray(y)))typeof i.tails=="string"&&(i.tails=I(i.tails));else throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_05] The opts.tails contains elements which are not string-type!");let o=Q(e).res;if(o.length===0)return e;e=o;let n=$($({},gi),i);n.heads=n.heads.map(y=>y.trim()),n.tails=n.tails.map(y=>y.trim());let l=!1,s=!1,h=new Z({limitToBeAddedWhitespace:!0}),a=new Z({limitToBeAddedWhitespace:!0}),g=!0,c=!0,T="";function m(y,d){let f;return W(y,0,d.heads,{trimBeforeMatching:!0,cb:(p,w,b)=>(f=b,!0)})&&W(y,f,d.tails,{trimBeforeMatching:!0,cb:(p,w,b)=>(f=b,!0)})?y.slice(f):y}for(;e!==m(e,n);)e=Q(m(e,n)).res;function u(y,d){let f;return!k(y,y.length-1,d.tails,{trimBeforeMatching:!0,cb:(p,w,b)=>(f=b,!0)})||!f?y:k(y,f,d.heads,{trimBeforeMatching:!0,cb:(p,w,b)=>(f=b,!0)})?y.slice(0,f+1):y}for(;e!==u(e,n);)e=Q(u(e,n)).res;if(!n.heads.length||!W(e,0,n.heads,{trimBeforeMatching:!0})||!n.tails.length||!k(e,e.length-1,n.tails,{trimBeforeMatching:!0}))return Q(e).res;for(let y=0,d=e.length;y<d;y++)if(e[y].trim()!==""){let f;if(W(e,y,n.heads,{trimBeforeMatching:!0,cb:(p,w,b)=>(f=b,!0)})&&f){c=!0,g&&(g=!0);let p;W(e,f,n.tails,{trimBeforeMatching:!0,cb:(w,b,O)=>(p=O,!0)})&&h.push(y,p),a.current()&&l&&T!=="tails"&&h.push(a.current()),l||a.current()&&(h.push(a.current()),a.wipe()),a.push(y,f),T="heads",y=f-1;continue}if(W(e,y,n.tails,{trimBeforeMatching:!0,cb:(p,w,b)=>(f=Number.isInteger(b)?b:e.length,!0)})&&f){c=!0,g?(T==="heads"&&a.wipe(),g=!1):a.push(y,f),T="tails",y=f-1;continue}g&&(g=!0),c&&!l?(l=!0,c=!1):c&&!s?(s=!0,g=!0,c=!1,T==="heads"&&a.wipe()):c&&s&&a.wipe()}return a.current()&&h.push(a.current()),h.current()?L(e,h.current()).trim():e.trim()}var er="11.0.13";var hi=er,pi=Object.prototype.hasOwnProperty,nr={heads:"%%_",tails:"_%%",headsNoWrap:"%%-",tailsNoWrap:"-%%",lookForDataContainers:!0,dataContainerIdentifierTails:"_data",wrapHeadsWith:"",wrapTailsWith:"",dontWrapVars:[],preventDoubleWrapping:!0,wrapGlobalFlipSwitch:!0,noSingleMarkers:!1,resolveToBoolIfAnyValuesContainBool:!0,resolveToFalseIfAnyValuesContainBool:!0,throwWhenNonStringInsertedInString:!1,allowUnresolved:!1};function A(e){return typeof e=="string"}function di(e){return typeof e=="number"}function Le(e){return typeof e=="boolean"}function de(e){return e===null}function ee(e){return e&&typeof e=="object"&&!Array.isArray(e)}function yi(e){return e!=null}function _(e){return A(e)?e.trim():e}function mi(e){if(typeof e=="string"&&e.length>0&&e.indexOf(".")!==-1){for(let t=0,r=e.length;t<r;t++)if(e[t]===".")return e.slice(0,t)}return e}function wi(e){if(typeof e=="string"&&e.length>0&&e.indexOf(".")!==-1){for(let t=0,r=e.length;t<r;t++)if(e[t]===".")return e.slice(t+1)}return e}function ir(e){if(typeof e=="string"&&e.length>0&&e.indexOf(".")!==-1){for(let t=e.length;t--;)if(e[t]===".")return e.slice(0,t)}return e}function tr(e){if(typeof e=="string"&&e.length>0&&e.indexOf(".")!==-1){for(let t=e.length;t--;)if(e[t]===".")return e.slice(t+1)}return e}function qe(e,t){return typeof e!="string"||!e.trim()?!1:!!(e.includes(t.heads)||e.includes(t.tails)||A(t.headsNoWrap)&&t.headsNoWrap.length>0&&e.includes(t.headsNoWrap)||A(t.tailsNoWrap)&&t.tailsNoWrap.length>0&&e.includes(t.tailsNoWrap))}function bi(e,t,r){let i,o;return typeof e=="string"&&e.length>0&&W(e,0,t,{trimBeforeMatching:!0,cb:(n,l,s)=>(i=s,!0)})&&k(e,e.length-1,r,{trimBeforeMatching:!0,cb:(n,l,s)=>(o=+s+1,!0)})?e.slice(i,o):e}function rr(e,t,r=!1,i,o,n){if(t.wrapHeadsWith||(t.wrapHeadsWith=""),t.wrapTailsWith||(t.wrapTailsWith=""),A(e)&&!r&&t.wrapGlobalFlipSwitch&&!t.dontWrapVars.some(l=>ge(n,l))&&(!t.preventDoubleWrapping||t.preventDoubleWrapping&&A(e)&&!e.includes(t.wrapHeadsWith)&&!e.includes(t.wrapTailsWith)))return`${t.wrapHeadsWith}${e}${t.wrapTailsWith}`;if(r){if(!A(e))return e;let l=Qt(e,{heads:t.wrapHeadsWith,tails:t.wrapTailsWith});return A(l)?bi(l,t.wrapHeadsWith,t.wrapTailsWith):l}return e}function Ti(e,t,r,i){let o;if(r.indexOf(".")!==-1){let n=r,l=!0;if(i.lookForDataContainers&&typeof i.dataContainerIdentifierTails=="string"&&i.dataContainerIdentifierTails.length>0&&!n.endsWith(i.dataContainerIdentifierTails)){let s=D.default.get(e,n+i.dataContainerIdentifierTails);ee(s)&&D.default.get(s,t)&&(o=D.default.get(s,t),l=!1)}for(;l&&n.indexOf(".")!==-1;){if(n=ir(n),tr(n)===t)throw new Error(`json-variables/findValues(): [THROW_ID_20] While trying to resolve: "${t}" at path "${r}", we encountered a closed loop. The parent key "${tr(n)}" is called the same as the variable "${t}" we're looking for.`);if(i.lookForDataContainers&&typeof i.dataContainerIdentifierTails=="string"&&i.dataContainerIdentifierTails.length>0&&!n.endsWith(i.dataContainerIdentifierTails)){let s=D.default.get(e,n+i.dataContainerIdentifierTails);ee(s)&&D.default.get(s,t)&&(o=D.default.get(s,t),l=!1)}if(o===void 0){let s=D.default.get(e,n);ee(s)&&D.default.get(s,t)&&(o=D.default.get(s,t),l=!1)}}}if(o===void 0){let n=D.default.get(e,t);n!==void 0&&(o=n)}if(o===void 0)if(t.indexOf(".")===-1){let n=Be(e,t);if(n.length>0){for(let l=0,s=n.length;l<s;l++)if(A(n[l].val)||Le(n[l].val)||de(n[l].val)){o=n[l].val;break}else if(di(n[l].val)){o=String(n[l].val);break}else if(Array.isArray(n[l].val)){o=n[l].val.join("");break}}}else{let n=Be(e,mi(t));if(n.length>0)for(let l=0,s=n.length;l<s;l++){let h=D.default.get(n[l].val,wi(t));h&&A(h)&&(o=h)}}return o}function sr(e,t,r,i,o=[]){if(o.includes(r)){let m="";if(o.length>1){let u=` \u2192
40
+ `||r.tab&&l===" "||r.nbsp&&l==="\xA0")}let o,n;if(e.length){if(i(e[0]))for(let l=0,s=e.length;l<s;l++){if(!i(e[l])){o=l;break}if(l===e.length-1)return{res:"",ranges:[[0,e.length]]}}if(i(e[e.length-1])){for(let l=e.length;l--;)if(!i(e[l])){n=l+1;break}}return o?n?{res:e.slice(o,n),ranges:[[0,o],[n,e.length]]}:{res:e.slice(o),ranges:[[0,o]]}:n?{res:e.slice(0,n),ranges:[[n,e.length]]}:{res:e,ranges:[]}}return{res:"",ranges:[]}}var gi={heads:["{{"],tails:["}}"]};function Qt(e,t){let r=Object.prototype.hasOwnProperty;if(e===void 0)throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_01] The input is missing!");if(typeof e!="string")return e;if(t&&!(0,Zt.default)(t))throw new Error(`string-remove-duplicate-heads-tails: [THROW_ID_03] The given options are not a plain object but ${typeof t}!`);let i=$({},t);if(i&&r.call(i,"heads"))if(I(i.heads).every(y=>typeof y=="string"||Array.isArray(y)))typeof i.heads=="string"&&(i.heads=I(i.heads));else throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_04] The opts.heads contains elements which are not string-type!");if(i&&r.call(i,"tails"))if(I(i.tails).every(y=>typeof y=="string"||Array.isArray(y)))typeof i.tails=="string"&&(i.tails=I(i.tails));else throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_05] The opts.tails contains elements which are not string-type!");let o=Q(e).res;if(o.length===0)return e;e=o;let n=$($({},gi),i);n.heads=n.heads.map(y=>y.trim()),n.tails=n.tails.map(y=>y.trim());let l=!1,s=!1,h=new Z({limitToBeAddedWhitespace:!0}),a=new Z({limitToBeAddedWhitespace:!0}),g=!0,c=!0,T="";function m(y,d){let f;return W(y,0,d.heads,{trimBeforeMatching:!0,cb:(p,w,b)=>(f=b,!0)})&&W(y,f,d.tails,{trimBeforeMatching:!0,cb:(p,w,b)=>(f=b,!0)})?y.slice(f):y}for(;e!==m(e,n);)e=Q(m(e,n)).res;function u(y,d){let f;return!k(y,y.length-1,d.tails,{trimBeforeMatching:!0,cb:(p,w,b)=>(f=b,!0)})||!f?y:k(y,f,d.heads,{trimBeforeMatching:!0,cb:(p,w,b)=>(f=b,!0)})?y.slice(0,f+1):y}for(;e!==u(e,n);)e=Q(u(e,n)).res;if(!n.heads.length||!W(e,0,n.heads,{trimBeforeMatching:!0})||!n.tails.length||!k(e,e.length-1,n.tails,{trimBeforeMatching:!0}))return Q(e).res;for(let y=0,d=e.length;y<d;y++)if(e[y].trim()!==""){let f;if(W(e,y,n.heads,{trimBeforeMatching:!0,cb:(p,w,b)=>(f=b,!0)})&&f){c=!0,g&&(g=!0);let p;W(e,f,n.tails,{trimBeforeMatching:!0,cb:(w,b,O)=>(p=O,!0)})&&h.push(y,p),a.current()&&l&&T!=="tails"&&h.push(a.current()),l||a.current()&&(h.push(a.current()),a.wipe()),a.push(y,f),T="heads",y=f-1;continue}if(W(e,y,n.tails,{trimBeforeMatching:!0,cb:(p,w,b)=>(f=Number.isInteger(b)?b:e.length,!0)})&&f){c=!0,g?(T==="heads"&&a.wipe(),g=!1):a.push(y,f),T="tails",y=f-1;continue}g&&(g=!0),c&&!l?(l=!0,c=!1):c&&!s?(s=!0,g=!0,c=!1,T==="heads"&&a.wipe()):c&&s&&a.wipe()}return a.current()&&h.push(a.current()),h.current()?L(e,h.current()).trim():e.trim()}var er="11.0.14";var hi=er,pi=Object.prototype.hasOwnProperty,nr={heads:"%%_",tails:"_%%",headsNoWrap:"%%-",tailsNoWrap:"-%%",lookForDataContainers:!0,dataContainerIdentifierTails:"_data",wrapHeadsWith:"",wrapTailsWith:"",dontWrapVars:[],preventDoubleWrapping:!0,wrapGlobalFlipSwitch:!0,noSingleMarkers:!1,resolveToBoolIfAnyValuesContainBool:!0,resolveToFalseIfAnyValuesContainBool:!0,throwWhenNonStringInsertedInString:!1,allowUnresolved:!1};function A(e){return typeof e=="string"}function di(e){return typeof e=="number"}function Le(e){return typeof e=="boolean"}function de(e){return e===null}function ee(e){return e&&typeof e=="object"&&!Array.isArray(e)}function yi(e){return e!=null}function _(e){return A(e)?e.trim():e}function mi(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let t=0,r=e.length;t<r;t++)if(e[t]===".")return e.slice(0,t)}return e}function wi(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let t=0,r=e.length;t<r;t++)if(e[t]===".")return e.slice(t+1)}return e}function ir(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let t=e.length;t--;)if(e[t]===".")return e.slice(0,t)}return e}function tr(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let t=e.length;t--;)if(e[t]===".")return e.slice(t+1)}return e}function qe(e,t){return typeof e!="string"||!e.trim()?!1:!!(e.includes(t.heads)||e.includes(t.tails)||A(t.headsNoWrap)&&t.headsNoWrap.length&&e.includes(t.headsNoWrap)||A(t.tailsNoWrap)&&t.tailsNoWrap.length&&e.includes(t.tailsNoWrap))}function bi(e,t,r){let i,o;return typeof e=="string"&&e.length&&W(e,0,t,{trimBeforeMatching:!0,cb:(n,l,s)=>(i=s,!0)})&&k(e,e.length-1,r,{trimBeforeMatching:!0,cb:(n,l,s)=>(o=+s+1,!0)})?e.slice(i,o):e}function rr(e,t,r=!1,i,o,n){if(t.wrapHeadsWith||(t.wrapHeadsWith=""),t.wrapTailsWith||(t.wrapTailsWith=""),A(e)&&!r&&t.wrapGlobalFlipSwitch&&!t.dontWrapVars.some(l=>ge(n,l))&&(!t.preventDoubleWrapping||t.preventDoubleWrapping&&A(e)&&!e.includes(t.wrapHeadsWith)&&!e.includes(t.wrapTailsWith)))return`${t.wrapHeadsWith}${e}${t.wrapTailsWith}`;if(r){if(!A(e))return e;let l=Qt(e,{heads:t.wrapHeadsWith,tails:t.wrapTailsWith});return A(l)?bi(l,t.wrapHeadsWith,t.wrapTailsWith):l}return e}function Ti(e,t,r,i){let o;if(r.indexOf(".")!==-1){let n=r,l=!0;if(i.lookForDataContainers&&typeof i.dataContainerIdentifierTails=="string"&&i.dataContainerIdentifierTails.length&&!n.endsWith(i.dataContainerIdentifierTails)){let s=D.default.get(e,n+i.dataContainerIdentifierTails);ee(s)&&D.default.get(s,t)&&(o=D.default.get(s,t),l=!1)}for(;l&&n.indexOf(".")!==-1;){if(n=ir(n),tr(n)===t)throw new Error(`json-variables/findValues(): [THROW_ID_20] While trying to resolve: "${t}" at path "${r}", we encountered a closed loop. The parent key "${tr(n)}" is called the same as the variable "${t}" we're looking for.`);if(i.lookForDataContainers&&typeof i.dataContainerIdentifierTails=="string"&&i.dataContainerIdentifierTails.length&&!n.endsWith(i.dataContainerIdentifierTails)){let s=D.default.get(e,n+i.dataContainerIdentifierTails);ee(s)&&D.default.get(s,t)&&(o=D.default.get(s,t),l=!1)}if(o===void 0){let s=D.default.get(e,n);ee(s)&&D.default.get(s,t)&&(o=D.default.get(s,t),l=!1)}}}if(o===void 0){let n=D.default.get(e,t);n!==void 0&&(o=n)}if(o===void 0)if(t.indexOf(".")===-1){let n=Be(e,t);if(n.length){for(let l=0,s=n.length;l<s;l++)if(A(n[l].val)||Le(n[l].val)||de(n[l].val)){o=n[l].val;break}else if(di(n[l].val)){o=String(n[l].val);break}else if(Array.isArray(n[l].val)){o=n[l].val.join("");break}}}else{let n=Be(e,mi(t));if(n.length)for(let l=0,s=n.length;l<s;l++){let h=D.default.get(n[l].val,wi(t));h&&A(h)&&(o=h)}}return o}function sr(e,t,r,i,o=[]){if(o.includes(r)){let m="";if(o.length>1){let u=` \u2192
41
41
  `;m=o.reduce((y,d,f)=>y+(f===0?"":u)+(d===r?"\u{1F4A5} ":" ")+d,` Here's the path we travelled up until we hit the recursion:
42
42
 
43
43
  `),m+=`${u}\u{1F4A5} ${r}`}throw new Error(`json-variables/resolveString(): [THROW_ID_19] While trying to resolve: "${t}" at path "${r}", we encountered a closed loop, the key is referencing itself."${m}`)}let n={},l=Array.from(o);l.push(r);let s=new Z;function h(m,u,y){for(let d=0,f=m.length;d<f;d++){let p=m[d],w=t.slice(p.headsEndAt,p.tailsStartAt);if(w.length===0)s.push(p.headsStartAt,p.tailsEndAt);else if(pi.call(n,w)&&A(n[w]))s.push(p.headsStartAt,p.tailsEndAt,n[w]);else{let b=Ti(e,w.trim(),r,i);if(b===void 0)if(i.allowUnresolved===!0)b="";else if(typeof i.allowUnresolved=="string")b=i.allowUnresolved;else throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_18] We couldn't find the value to resolve the variable ${t.slice(p.headsEndAt,p.tailsStartAt)}. We're at path: "${r}".`);if(!y&&i.throwWhenNonStringInsertedInString&&!A(b))throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_23] While resolving the variable ${t.slice(p.headsEndAt,p.tailsStartAt)} at path ${r}, it resolved into a non-string value, ${JSON.stringify(b,null,4)}. This is happening because options setting "throwWhenNonStringInsertedInString" is active (set to "true").`);if(Le(b)){if(i.resolveToBoolIfAnyValuesContainBool)return s.wipe(),i.resolveToFalseIfAnyValuesContainBool?!1:b;b=""}else{if(de(b)&&y)return s.wipe(),b;Array.isArray(b)?b=String(b.join("")):de(b)?b="":b=String(b)}let O=r.includes(".")?`${ir(r)}.${w}`:w;if(qe(b,i)){let E=rr(sr(e,b,O,i,l),i,u,l,O,w.trim());typeof E=="string"&&s.push(p.headsStartAt,p.tailsEndAt,E)}else{n[w]=b;let E=rr(b,i,u,l,O,w.trim());typeof E=="string"&&s.push(p.headsStartAt,p.tailsEndAt,E)}}}}let a;try{a=Pe(t,i.heads,i.tails,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(m){throw new Error(`json-variables/resolveString(): [THROW_ID_17] While trying to resolve string: "${t}" at path ${r}, something wrong with heads and tails was detected! Here's the internal error message:
44
44
  ${m}`)}let g=!1;a.length===1&&L(t,[[a[0].headsStartAt,a[0].tailsEndAt]]).trim()===""&&(g=!0);let c=h(a,!1,g);if(typeof c=="boolean"||c===null)return c;try{a=Pe(t,i.headsNoWrap,i.tailsNoWrap,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(m){throw new Error(`json-variables/resolveString(): [THROW_ID_22] While trying to resolve string: "${t}" at path ${r}, something wrong with no-wrap heads and no-wrap tails was detected! Here's the internal error message:
45
- ${m}`)}a.length===1&&L(t,[[a[0].headsStartAt,a[0].tailsEndAt]]).trim()===""&&(g=!0);let T=h(a,!0,g);return Le(T)||de(T)?T:s!=null&&s.current()?L(t,s.current()):t}function $i(e,t){if(!arguments.length)throw new Error("json-variables/jVar(): [THROW_ID_01] Alas! Inputs are missing!");if(!ee(e))throw new TypeError(`json-variables/jVar(): [THROW_ID_02] Alas! The input must be a plain object! Currently it's: ${Array.isArray(e)?"array":typeof e}`);if(t&&!ee(t))throw new TypeError(`json-variables/jVar(): [THROW_ID_03] Alas! An Optional Options Object must be a plain object! Currently it's: ${Array.isArray(t)?"array":typeof t}`);let r=$($({},nr),t);r.dontWrapVars?Array.isArray(r.dontWrapVars)||(r.dontWrapVars=I(r.dontWrapVars)):r.dontWrapVars=[];let i,o;if(r.dontWrapVars.length>0&&!r.dontWrapVars.every((l,s)=>A(l)?!0:(i=l,o=s,!1)))throw new Error(`json-variables/jVar(): [THROW_ID_05] Alas! All variable names set in opts.dontWrapVars should be of a string type. Computer detected a value "${i}" at index ${o}, which is not string but ${Array.isArray(i)?"array":typeof i}!`);if(r.heads==="")throw new Error("json-variables/jVar(): [THROW_ID_06] Alas! opts.heads are empty!");if(r.tails==="")throw new Error("json-variables/jVar(): [THROW_ID_07] Alas! opts.tails are empty!");if(r.lookForDataContainers&&r.dataContainerIdentifierTails==="")throw new Error("json-variables/jVar(): [THROW_ID_08] Alas! opts.dataContainerIdentifierTails is empty!");if(r.heads===r.tails)throw new Error("json-variables/jVar(): [THROW_ID_09] Alas! opts.heads and opts.tails can't be equal!");if(r.heads===r.headsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_10] Alas! opts.heads and opts.headsNoWrap can't be equal!");if(r.tails===r.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_11] Alas! opts.tails and opts.tailsNoWrap can't be equal!");if(r.headsNoWrap==="")throw new Error("json-variables/jVar(): [THROW_ID_12] Alas! opts.headsNoWrap is an empty string!");if(r.tailsNoWrap==="")throw new Error("json-variables/jVar(): [THROW_ID_13] Alas! opts.tailsNoWrap is an empty string!");if(r.headsNoWrap===r.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_14] Alas! opts.headsNoWrap and opts.tailsNoWrap can't be equal!");let n;return ue(e,(l,s,h)=>{if(yi(s)&&qe(l,r))throw new Error(`json-variables/jVar(): [THROW_ID_15] Alas! Object keys can't contain variables!
45
+ ${m}`)}a.length===1&&L(t,[[a[0].headsStartAt,a[0].tailsEndAt]]).trim()===""&&(g=!0);let T=h(a,!0,g);return Le(T)||de(T)?T:s!=null&&s.current()?L(t,s.current()):t}function $i(e,t){if(!arguments.length)throw new Error("json-variables/jVar(): [THROW_ID_01] Alas! Inputs are missing!");if(!ee(e))throw new TypeError(`json-variables/jVar(): [THROW_ID_02] Alas! The input must be a plain object! Currently it's: ${Array.isArray(e)?"array":typeof e}`);if(t&&!ee(t))throw new TypeError(`json-variables/jVar(): [THROW_ID_03] Alas! An Optional Options Object must be a plain object! Currently it's: ${Array.isArray(t)?"array":typeof t}`);let r=$($({},nr),t);r.dontWrapVars?Array.isArray(r.dontWrapVars)||(r.dontWrapVars=I(r.dontWrapVars)):r.dontWrapVars=[];let i,o;if(r.dontWrapVars.length&&!r.dontWrapVars.every((l,s)=>A(l)?!0:(i=l,o=s,!1)))throw new Error(`json-variables/jVar(): [THROW_ID_05] Alas! All variable names set in opts.dontWrapVars should be of a string type. Computer detected a value "${i}" at index ${o}, which is not string but ${Array.isArray(i)?"array":typeof i}!`);if(r.heads==="")throw new Error("json-variables/jVar(): [THROW_ID_06] Alas! opts.heads are empty!");if(r.tails==="")throw new Error("json-variables/jVar(): [THROW_ID_07] Alas! opts.tails are empty!");if(r.lookForDataContainers&&r.dataContainerIdentifierTails==="")throw new Error("json-variables/jVar(): [THROW_ID_08] Alas! opts.dataContainerIdentifierTails is empty!");if(r.heads===r.tails)throw new Error("json-variables/jVar(): [THROW_ID_09] Alas! opts.heads and opts.tails can't be equal!");if(r.heads===r.headsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_10] Alas! opts.heads and opts.headsNoWrap can't be equal!");if(r.tails===r.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_11] Alas! opts.tails and opts.tailsNoWrap can't be equal!");if(r.headsNoWrap==="")throw new Error("json-variables/jVar(): [THROW_ID_12] Alas! opts.headsNoWrap is an empty string!");if(r.tailsNoWrap==="")throw new Error("json-variables/jVar(): [THROW_ID_13] Alas! opts.tailsNoWrap is an empty string!");if(r.headsNoWrap===r.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_14] Alas! opts.headsNoWrap and opts.tailsNoWrap can't be equal!");let n;return ue(e,(l,s,h)=>{if(yi(s)&&qe(l,r))throw new Error(`json-variables/jVar(): [THROW_ID_15] Alas! Object keys can't contain variables!
46
46
  Please check the following key: ${l}`);if(s!==void 0?n=s:n=l,n==="")return n;if(r.heads.length!==0&&_(n)===_(r.heads)||r.tails.length!==0&&_(n)===_(r.tails)||r.headsNoWrap.length!==0&&_(n)===_(r.headsNoWrap)||r.tailsNoWrap.length!==0&&_(n)===_(r.tailsNoWrap)){if(!r.noSingleMarkers)return n;throw new Error(`json-variables/jVar(): [THROW_ID_16] Alas! While processing the input, we stumbled upon ${_(n)} which is equal to ${_(n)===_(r.heads)?"heads":""}${_(n)===_(r.tails)?"tails":""}${A(r.headsNoWrap)&&_(n)===_(r.headsNoWrap)?"headsNoWrap":""}${A(r.tailsNoWrap)&&_(n)===_(r.tailsNoWrap)?"tailsNoWrap":""}. If you wouldn't have set opts.noSingleMarkers to "true" this error would not happen and computer would have left the current element (${_(n)}) alone`)}return A(n)&&qe(n,r)?sr(e,n,h.path,r):n})}return pr(vi);})();
47
47
  /**
48
48
  * @name arrayiffy-if-string
@@ -79,7 +79,7 @@ Please check the following key: ${l}`);if(s!==void 0?n=s:n=l,n==="")return n;if(
79
79
  /**
80
80
  * @name ranges-apply
81
81
  * @fileoverview Take an array of string index ranges, delete/replace the string according to them
82
- * @version 6.0.12
82
+ * @version 6.1.0
83
83
  * @author Roy Revelt, Codsen Ltd
84
84
  * @license MIT
85
85
  * {@link https://codsen.com/os/ranges-apply/}
@@ -87,7 +87,7 @@ Please check the following key: ${l}`);if(s!==void 0?n=s:n=l,n==="")return n;if(
87
87
  /**
88
88
  * @name ranges-merge
89
89
  * @fileoverview Merge and sort string index ranges
90
- * @version 8.0.12
90
+ * @version 8.1.0
91
91
  * @author Roy Revelt, Codsen Ltd
92
92
  * @license MIT
93
93
  * {@link https://codsen.com/os/ranges-merge/}
@@ -95,7 +95,7 @@ Please check the following key: ${l}`);if(s!==void 0?n=s:n=l,n==="")return n;if(
95
95
  /**
96
96
  * @name ranges-push
97
97
  * @fileoverview Gather string index ranges
98
- * @version 6.0.12
98
+ * @version 6.1.0
99
99
  * @author Roy Revelt, Codsen Ltd
100
100
  * @license MIT
101
101
  * {@link https://codsen.com/os/ranges-push/}
@@ -119,7 +119,7 @@ Please check the following key: ${l}`);if(s!==void 0?n=s:n=l,n==="")return n;if(
119
119
  /**
120
120
  * @name string-find-heads-tails
121
121
  * @fileoverview Finds where are arbitrary templating marker heads and tails located
122
- * @version 5.0.13
122
+ * @version 5.0.14
123
123
  * @author Roy Revelt, Codsen Ltd
124
124
  * @license MIT
125
125
  * {@link https://codsen.com/os/string-find-heads-tails/}
@@ -135,7 +135,7 @@ Please check the following key: ${l}`);if(s!==void 0?n=s:n=l,n==="")return n;if(
135
135
  /**
136
136
  * @name string-remove-duplicate-heads-tails
137
137
  * @fileoverview Detect and (recursively) remove head and tail wrappings around the input string
138
- * @version 6.0.13
138
+ * @version 6.0.14
139
139
  * @author Roy Revelt, Codsen Ltd
140
140
  * @license MIT
141
141
  * {@link https://codsen.com/os/string-remove-duplicate-heads-tails/}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-variables",
3
- "version": "11.0.13",
3
+ "version": "11.0.14",
4
4
  "description": "Resolves custom-marked, cross-referenced paths in parsed JSON",
5
5
  "keywords": [
6
6
  "comb",
@@ -80,10 +80,10 @@
80
80
  "ast-monkey-traverse": "^3.0.12",
81
81
  "matcher": "^5.0.0",
82
82
  "object-path": "^0.11.8",
83
- "ranges-apply": "^6.0.12",
84
- "ranges-push": "^6.0.12",
85
- "string-find-heads-tails": "^5.0.13",
83
+ "ranges-apply": "^6.1.0",
84
+ "ranges-push": "^6.1.0",
85
+ "string-find-heads-tails": "^5.0.14",
86
86
  "string-match-left-right": "^8.1.0",
87
- "string-remove-duplicate-heads-tails": "^6.0.13"
87
+ "string-remove-duplicate-heads-tails": "^6.0.14"
88
88
  }
89
89
  }