json-variables 11.1.2 → 11.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * @name json-variables
3
3
  * @fileoverview Resolves custom-marked, cross-referenced paths in parsed JSON
4
- * @version 11.1.2
4
+ * @version 11.1.3
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 C}from"ast-monkey-traverse";import{isMatch as x}from"matcher";import h 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 A}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.1.2";var he=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 g(e){return typeof e=="string"}function G(e){return typeof e=="number"}function O(e){return typeof e=="boolean"}function N(e){return e===null}function V(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function z(e){return e!=null}function u(e){return g(e)?e.trim():e}function Y(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 Q(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 J(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 P(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 T(e,t){return typeof e!="string"||!e.trim()?!1:!!(e.includes(t.heads)||e.includes(t.tails)||g(t.headsNoWrap)&&t.headsNoWrap.length&&e.includes(t.headsNoWrap)||g(t.tailsNoWrap)&&t.tailsNoWrap.length&&e.includes(t.tailsNoWrap))}function X(e,t,r){let o,i;return typeof e=="string"&&e.length&&M(e,0,t,{trimBeforeMatching:!0,cb:(n,a,l)=>(o=l,!0)})&&U(e,e.length-1,r,{trimBeforeMatching:!0,cb:(n,a,l)=>(i=(l||0)+1,!0)})?e.slice(o,i):e}function H(e,t,r=!1,o,i,n){if(t.wrapHeadsWith||(t.wrapHeadsWith=""),t.wrapTailsWith||(t.wrapTailsWith=""),g(e)&&!r&&t.wrapGlobalFlipSwitch&&!t.dontWrapVars.some(a=>x(n,a))&&(!t.preventDoubleWrapping||t.preventDoubleWrapping&&g(e)&&!e.includes(t.wrapHeadsWith)&&!e.includes(t.wrapTailsWith)))return`${t.wrapHeadsWith}${e}${t.wrapTailsWith}`;if(r){if(!g(e))return e;let a=L(e,{heads:t.wrapHeadsWith,tails:t.wrapTailsWith});return g(a)?X(a,t.wrapHeadsWith,t.wrapTailsWith):a}return e}function Z(e,t,r,o){let i;if(r.indexOf(".")!==-1){let n=r,a=!0;if(o.lookForDataContainers&&typeof o.dataContainerIdentifierTails=="string"&&o.dataContainerIdentifierTails.length&&!n.endsWith(o.dataContainerIdentifierTails)){let l=h.get(e,n+o.dataContainerIdentifierTails);V(l)&&h.get(l,t)&&(i=h.get(l,t),a=!1)}for(;a&&n.indexOf(".")!==-1;){if(n=J(n),P(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 "${P(n)}" is called the same as the variable "${t}" we're looking for.`);if(o.lookForDataContainers&&typeof o.dataContainerIdentifierTails=="string"&&o.dataContainerIdentifierTails.length&&!n.endsWith(o.dataContainerIdentifierTails)){let l=h.get(e,n+o.dataContainerIdentifierTails);V(l)&&h.get(l,t)&&(i=h.get(l,t),a=!1)}if(i===void 0){let l=h.get(e,n);V(l)&&h.get(l,t)&&(i=h.get(l,t),a=!1)}}}if(i===void 0){let n=h.get(e,t);n!==void 0&&(i=n)}if(i===void 0)if(t.indexOf(".")===-1){let n=_(e,t);if(n.length){for(let a=0,l=n.length;a<l;a++)if(g(n[a].val)||O(n[a].val)||N(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(t));if(n.length)for(let a=0,l=n.length;a<l;a++){let y=h.get(n[a].val,Q(t));y&&g(y)&&(i=y)}}return i}function R(e,t,r,o,i=[]){if(i.includes(r)){let c="";if(i.length>1){let w=` \u2192
10
+ import{traverse as C}from"ast-monkey-traverse";import{isMatch as x}from"matcher";import h 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 A}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.1.3";var he=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 g(e){return typeof e=="string"}function G(e){return typeof e=="number"}function O(e){return typeof e=="boolean"}function N(e){return e===null}function V(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function z(e){return e!=null}function u(e){return g(e)?e.trim():e}function Y(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 Q(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 J(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 P(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 T(e,t){return typeof e!="string"||!e.trim()?!1:!!(e.includes(t.heads)||e.includes(t.tails)||g(t.headsNoWrap)&&t.headsNoWrap.length&&e.includes(t.headsNoWrap)||g(t.tailsNoWrap)&&t.tailsNoWrap.length&&e.includes(t.tailsNoWrap))}function X(e,t,r){let o,i;return typeof e=="string"&&e.length&&M(e,0,t,{trimBeforeMatching:!0,cb:(n,a,l)=>(o=l,!0)})&&U(e,e.length-1,r,{trimBeforeMatching:!0,cb:(n,a,l)=>(i=(l||0)+1,!0)})?e.slice(o,i):e}function H(e,t,r=!1,o,i,n){if(t.wrapHeadsWith||(t.wrapHeadsWith=""),t.wrapTailsWith||(t.wrapTailsWith=""),g(e)&&!r&&t.wrapGlobalFlipSwitch&&!t.dontWrapVars.some(a=>x(n,a))&&(!t.preventDoubleWrapping||t.preventDoubleWrapping&&g(e)&&!e.includes(t.wrapHeadsWith)&&!e.includes(t.wrapTailsWith)))return`${t.wrapHeadsWith}${e}${t.wrapTailsWith}`;if(r){if(!g(e))return e;let a=L(e,{heads:t.wrapHeadsWith,tails:t.wrapTailsWith});return g(a)?X(a,t.wrapHeadsWith,t.wrapTailsWith):a}return e}function Z(e,t,r,o){let i;if(r.indexOf(".")!==-1){let n=r,a=!0;if(o.lookForDataContainers&&typeof o.dataContainerIdentifierTails=="string"&&o.dataContainerIdentifierTails.length&&!n.endsWith(o.dataContainerIdentifierTails)){let l=h.get(e,n+o.dataContainerIdentifierTails);V(l)&&h.get(l,t)&&(i=h.get(l,t),a=!1)}for(;a&&n.indexOf(".")!==-1;){if(n=J(n),P(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 "${P(n)}" is called the same as the variable "${t}" we're looking for.`);if(o.lookForDataContainers&&typeof o.dataContainerIdentifierTails=="string"&&o.dataContainerIdentifierTails.length&&!n.endsWith(o.dataContainerIdentifierTails)){let l=h.get(e,n+o.dataContainerIdentifierTails);V(l)&&h.get(l,t)&&(i=h.get(l,t),a=!1)}if(i===void 0){let l=h.get(e,n);V(l)&&h.get(l,t)&&(i=h.get(l,t),a=!1)}}}if(i===void 0){let n=h.get(e,t);n!==void 0&&(i=n)}if(i===void 0)if(t.indexOf(".")===-1){let n=_(e,t);if(n.length){for(let a=0,l=n.length;a<l;a++)if(g(n[a].val)||O(n[a].val)||N(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(t));if(n.length)for(let a=0,l=n.length;a<l;a++){let y=h.get(n[a].val,Q(t));y&&g(y)&&(i=y)}}return i}function R(e,t,r,o,i=[]){if(i.includes(r)){let c="";if(i.length>1){let w=` \u2192
11
11
  `;c=i.reduce((D,b,S)=>D+(S===0?"":w)+(b===r?"\u{1F4A5} ":" ")+b,` Here's the path we travelled up until we hit the recursion:
12
12
 
13
13
  `),c+=`${w}\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."${c}`)}let n={},a=Array.from(i);a.push(r);let l=new B;function y(c,w,D){for(let b=0,S=c.length;b<S;b++){let f=c[b],p=t.slice(f.headsEndAt,f.tailsStartAt);if(p.length===0)l.push(f.headsStartAt,f.tailsEndAt);else if(q.call(n,p)&&g(n[p]))l.push(f.headsStartAt,f.tailsEndAt,n[p]);else{let s=Z(e,p.trim(),r,o);if(s===void 0)if(o.allowUnresolved===!0)s="";else if(typeof o.allowUnresolved=="string")s=o.allowUnresolved;else throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_18] We couldn't find the value to resolve the variable ${t.slice(f.headsEndAt,f.tailsStartAt)}. We're at path: "${r}".`);if(!D&&o.throwWhenNonStringInsertedInString&&!g(s))throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_23] While resolving the variable ${t.slice(f.headsEndAt,f.tailsStartAt)} at path ${r}, 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(O(s)){if(o.resolveToBoolIfAnyValuesContainBool)return l.wipe(),o.resolveToFalseIfAnyValuesContainBool?!1:s;s=""}else{if(N(s)&&D)return l.wipe(),s;Array.isArray(s)?s=String(s.join("")):N(s)?s="":s=String(s)}let v=r.includes(".")?`${J(r)}.${p}`:p;if(T(s,o)){let m=H(R(e,s,v,o,a),o,w,a,v,p.trim());typeof m=="string"&&l.push(f.headsStartAt,f.tailsEndAt,m)}else{n[p]=s;let m=H(s,o,w,a,v,p.trim());typeof m=="string"&&l.push(f.headsStartAt,f.tailsEndAt,m)}}}}let d;try{d=I(t,o.heads,o.tails,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(c){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:
@@ -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.1.2
4
+ * @version 11.1.3
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/json-variables/}
@@ -35,9 +35,9 @@ To turn off this error being thrown, set resolvedOpts.throwWhenSomethingWrongIsD
35
35
  `.includes(n[y])||n[y]===r?(h=0,n[y]===r?T+=n[y]:n[y]===g?c<=o&&(T+=n[y],n[y+1]===s&&(T+=n[y+1],y++)):n[y]===s&&(n==null?void 0:n[y-1])!==g&&c<=o&&(T+=n[y])):(h++,!n[y+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 o="",a="";if(!e.trim())o=e;else if(!e[0].trim()){for(let g=0,s=e.length;g<s;g++)if(e[g].trim()){o=e.slice(0,g);break}}if(e.trim()&&(e.slice(-1).trim()===""||e.slice(-1)===r)){for(let g=e.length;g--;)if(e[g].trim()){a=e.slice(g+1);break}}return`${l(o,n,!1)}${e.trim()}${i(l(i(a),n,!0))}`}return e}var ai={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function Ut(e,t){if(!Array.isArray(e)||!e.length)return e;let r=$($({},ai),t),i,l;if(r.strictlyTwoElementsInRangeArrays&&!e.every((a,g)=>!Array.isArray(a)||a.length!==2?(i=g,l=a.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 ${l} elements!`);if(!e.every((a,g)=>!Array.isArray(a)||!Number.isInteger(a[0])||a[0]<0||!Number.isInteger(a[1])||a[1]<0?(i=g,!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,o=0;return Array.from(e).sort((a,g)=>(r.progressFn&&(o+=1,r.progressFn(Math.floor(o*100/n))),a[0]===g[0]?a[1]<g[1]?-1:a[1]>g[1]?1:0:a[0]<g[0]?-1:1))}var Gt={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function si(e,t){function r(s){return!!s&&typeof s=="object"&&!Array.isArray(s)}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] resolvedOpts.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] resolvedOpts.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] resolvedOpts.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 l=e.filter(s=>Array.isArray(s)).map(s=>[...s]).filter(s=>s[2]!==void 0||s[0]!==s[1]),n,o,a;i.progressFn?n=Ut(l,{progressFn:s=>{a=Math.floor(s/5),a!==o&&(o=a,i.progressFn(a))}}):n=Ut(l);let g=n.length-1;for(let s=g;s>0;s--)i.progressFn&&(a=Math.floor((1-s/g)*78)+21,a!==o&&a>o&&(o=a,i.progressFn(a))),(n[s][0]<=n[s-1][0]||!i.joinRangesThatTouchEdges&&n[s][0]<n[s-1][1]||i.joinRangesThatTouchEdges&&n[s][0]<=n[s-1][1])&&(n[s-1][0]=Math.min(n[s][0],n[s-1][0]),n[s-1][1]=Math.max(n[s][1],n[s-1][1]),n[s][2]!==void 0&&(n[s-1][0]>=n[s][0]||n[s-1][1]<=n[s][1])&&n[s-1][2]!==null&&(n[s][2]===null&&n[s-1][2]!==null?n[s-1][2]=null:n[s-1][2]!=null?+i.mergeType==2&&n[s-1][0]===n[s][0]?n[s-1][2]=n[s][2]:n[s-1][2]+=n[s][2]:n[s-1][2]=n[s][2]),n.splice(s,1),s=n.length);return n.length?n:null}function C(e){return e!=null}function j(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){var n;if(e==null&&t==null)return;if(C(e)&&!C(t)){if(Array.isArray(e)){if(e.length){if(e.some(o=>Array.isArray(o))){e.forEach(o=>{Array.isArray(o)&&this.add(...o)});return}e.length&&j(+e[0])&&j(+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,l=+t;if(j(r)&&(r=String(r)),j(i)&&j(l)){if(C(r)&&!X(r)&&!j(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
37
  ${JSON.stringify(r,null,4)}`);if(C(this.ranges)&&Array.isArray(this.last())&&i===this.last()[1]){if(this.last()[1]=l,this.last()[2],this.last()[2]!==null&&C(r)){let o=this.last()[2]&&this.last()[2].length&&(!((n=this.opts)!=null&&n.mergeType)||this.opts.mergeType===1)?`${this.last()[2]}${r}`:r;this.opts.limitToBeAddedWhitespace&&(o=pe(o,this.opts.limitLinebreaksCount)),X(o)&&!o.length||(this.last()[2]=o)}}else{this.ranges||(this.ranges=[]);let o=r!==void 0&&!(X(r)&&!r.length)?[i,l,r&&this.opts.limitToBeAddedWhitespace?pe(r,this.opts.limitLinebreaksCount):r]:[i,l];this.ranges.push(o)}}else throw j(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 l}" equal to: ${JSON.stringify(l,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=si(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])&&j(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,l;if(r.strictlyTwoElementsInRangeArrays&&!e.every((a,g)=>!Array.isArray(a)||a.length!==2?(i=g,l=a.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 ${l} elements!`);if(!e.every((a,g)=>!Array.isArray(a)||!Number.isInteger(a[0])||a[0]<0||!Number.isInteger(a[1])||a[1]<0?(i=g,!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,o=0;return Array.from(e).sort((a,g)=>(r.progressFn&&(o+=1,r.progressFn(Math.floor(o*100/n))),a[0]===g[0]?a[1]<g[1]?-1:a[1]>g[1]?1:0:a[0]<g[0]?-1:1))}var zt={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function Yt(e,t){function r(s){return!!s&&typeof s=="object"&&!Array.isArray(s)}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
- ${JSON.stringify(t,null,4)} (type ${typeof t})`);else i=$({},zt);let l=e.filter(s=>Array.isArray(s)).map(s=>[...s]).filter(s=>s[2]!==void 0||s[0]!==s[1]),n,o,a;i.progressFn?n=Fe(l,{progressFn:s=>{a=Math.floor(s/5),a!==o&&(o=a,i.progressFn(a))}}):n=Fe(l);let g=n.length-1;for(let s=g;s>0;s--)i.progressFn&&(a=Math.floor((1-s/g)*78)+21,a!==o&&a>o&&(o=a,i.progressFn(a))),(n[s][0]<=n[s-1][0]||!i.joinRangesThatTouchEdges&&n[s][0]<n[s-1][1]||i.joinRangesThatTouchEdges&&n[s][0]<=n[s-1][1])&&(n[s-1][0]=Math.min(n[s][0],n[s-1][0]),n[s-1][1]=Math.max(n[s][1],n[s-1][1]),n[s][2]!==void 0&&(n[s-1][0]>=n[s][0]||n[s-1][1]<=n[s][1])&&n[s-1][2]!==null&&(n[s][2]===null&&n[s-1][2]!==null?n[s-1][2]=null:n[s-1][2]!=null?+i.mergeType==2&&n[s-1][0]===n[s][0]?n[s-1][2]=n[s][2]:n[s-1][2]+=n[s][2]:n[s-1][2]=n[s][2]),n.splice(s,1),s=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,l=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(h=>h).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 o=n.length,a=0;n.filter(h=>h).forEach((h,c)=>{if(r&&(i=Math.floor(a/o*10),i!==l&&(l=i,r(i))),!Array.isArray(h))throw new TypeError(`ranges-apply: [THROW_ID_05] ranges array, second input arg., has ${c}th element not an array: ${JSON.stringify(h,null,4)}, which is ${typeof h}`);if(!Number.isInteger(h[0])){if(!Number.isInteger(+h[0])||+h[0]<0)throw new TypeError(`ranges-apply: [THROW_ID_06] ranges array, second input arg. has ${c}th element, array ${JSON.stringify(h,null,0)}. Its first element is not an integer, string index, but ${typeof h[0]}, equal to: ${JSON.stringify(h[0],null,4)}.`);n[c][0]=+n[c][0]}if(!Number.isInteger(h[1])){if(!Number.isInteger(+h[1])||+h[1]<0)throw new TypeError(`ranges-apply: [THROW_ID_07] ranges array, second input arg. has ${c}th element, array ${JSON.stringify(h,null,0)}. Its second element is not an integer, string index, but ${typeof h[1]}, equal to: ${JSON.stringify(h[1],null,4)}.`);n[c][1]=+n[c][1]}a+=1});let g=Yt(n,{progressFn:h=>{r&&(i=10+Math.floor(h/10),i!==l&&(l=i,r(i)))}});Xt(g);let s=g.length;if(s>0){let h=e.slice(g[s-1][1]);e=g.reduce((c,T,y,u)=>{r&&(i=20+Math.floor(y/s*80),i!==l&&(l=i,r(i)));let w=y===0?0:u[y-1][1],d=u[y][0];return`${c}${e.slice(w,d)}${u[y][2]||""}`},""),e+=h}return e}var Zt=U(je(),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:
38
+ ${JSON.stringify(t,null,4)} (type ${typeof t})`);else i=$({},zt);let l=e.filter(s=>Array.isArray(s)).map(s=>[...s]).filter(s=>s[2]!==void 0||s[0]!==s[1]),n,o,a;i.progressFn?n=Fe(l,{progressFn:s=>{a=Math.floor(s/5),a!==o&&(o=a,i.progressFn(a))}}):n=Fe(l);let g=n.length-1;for(let s=g;s>0;s--)i.progressFn&&(a=Math.floor((1-s/g)*78)+21,a!==o&&a>o&&(o=a,i.progressFn(a))),(n[s][0]<=n[s-1][0]||!i.joinRangesThatTouchEdges&&n[s][0]<n[s-1][1]||i.joinRangesThatTouchEdges&&n[s][0]<=n[s-1][1])&&(n[s-1][0]=Math.min(n[s][0],n[s-1][0]),n[s-1][1]=Math.max(n[s][1],n[s-1][1]),n[s][2]!==void 0&&(n[s-1][0]>=n[s][0]||n[s-1][1]<=n[s][1])&&n[s-1][2]!==null&&(n[s][2]===null&&n[s-1][2]!==null?n[s-1][2]=null:n[s-1][2]!=null?+i.mergeType==2&&n[s-1][0]===n[s][0]?n[s-1][2]=n[s][2]:n[s-1][2]+=n[s][2]:n[s-1][2]=n[s][2]),n.splice(s,1),s=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?"".concat(ke,": ").concat(r):ke;throw new Error(i)}}function L(e,t,r){let i=0,l=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(h=>h).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 o=n.length,a=0;n.filter(h=>h).forEach((h,c)=>{if(r&&(i=Math.floor(a/o*10),i!==l&&(l=i,r(i))),!Array.isArray(h))throw new TypeError(`ranges-apply: [THROW_ID_05] ranges array, second input arg., has ${c}th element not an array: ${JSON.stringify(h,null,4)}, which is ${typeof h}`);if(!Number.isInteger(h[0])){if(!Number.isInteger(+h[0])||+h[0]<0)throw new TypeError(`ranges-apply: [THROW_ID_06] ranges array, second input arg. has ${c}th element, array ${JSON.stringify(h,null,0)}. Its first element is not an integer, string index, but ${typeof h[0]}, equal to: ${JSON.stringify(h[0],null,4)}.`);n[c][0]=+n[c][0]}if(!Number.isInteger(h[1])){if(!Number.isInteger(+h[1])||+h[1]<0)throw new TypeError(`ranges-apply: [THROW_ID_07] ranges array, second input arg. has ${c}th element, array ${JSON.stringify(h,null,0)}. Its second element is not an integer, string index, but ${typeof h[1]}, equal to: ${JSON.stringify(h[1],null,4)}.`);n[c][1]=+n[c][1]}a+=1});let g=Yt(n,{progressFn:h=>{r&&(i=10+Math.floor(h/10),i!==l&&(l=i,r(i)))}});Xt(g);let s=g.length;if(s>0){let h=e.slice(g[s-1][1]);e=g.reduce((c,T,y,u)=>{r&&(i=20+Math.floor(y/s*80),i!==l&&(l=i,r(i)));let w=y===0?0:u[y-1][1],d=u[y][0];return`${c}${e.slice(w,d)}${u[y][2]||""}`},""),e+=h}return e}var Zt=U(je(),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(o){return r.classicTrim&&!o.trim()||!r.classicTrim&&(r.space&&o===" "||r.cr&&o==="\r"||r.lf&&o===`
40
- `||r.tab&&o===" "||r.nbsp&&o==="\xA0")}let l,n;if(e.length){if(i(e[0]))for(let o=0,a=e.length;o<a;o++){if(!i(e[o])){l=o;break}if(o===e.length-1)return{res:"",ranges:[[0,e.length]]}}if(i(e[e.length-1])){for(let o=e.length;o--;)if(!i(e[o])){n=o+1;break}}return l?n?{res:e.slice(l,n),ranges:[[0,l],[n,e.length]]}:{res:e.slice(l),ranges:[[0,l]]}: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(w=>typeof w=="string"||Array.isArray(w)))typeof i.heads=="string"&&(i.heads=I(i.heads));else throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_04] The resolvedOpts.heads contains elements which are not string-type!");if(i&&r.call(i,"tails"))if(I(i.tails).every(w=>typeof w=="string"||Array.isArray(w)))typeof i.tails=="string"&&(i.tails=I(i.tails));else throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_05] The resolvedOpts.tails contains elements which are not string-type!");let l=Q(e).res;if(l.length===0)return e;e=l;let n=$($({},gi),i);n.heads=n.heads.map(w=>w.trim()),n.tails=n.tails.map(w=>w.trim());let o=!1,a=!1,g=new Z({limitToBeAddedWhitespace:!0}),s=new Z({limitToBeAddedWhitespace:!0}),h=!0,c=!0,T="";function y(w,d){let f;return S(w,0,d.heads,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=b,!0)})&&S(w,f,d.tails,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=b,!0)})?w.slice(f):w}for(;e!==y(e,n);)e=Q(y(e,n)).res;function u(w,d){let f;return!k(w,w.length-1,d.tails,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=b,!0)})||!f?w:k(w,f,d.heads,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=b,!0)})?w.slice(0,f+1):w}for(;e!==u(e,n);)e=Q(u(e,n)).res;if(!n.heads.length||!S(e,0,n.heads,{trimBeforeMatching:!0})||!n.tails.length||!k(e,e.length-1,n.tails,{trimBeforeMatching:!0}))return Q(e).res;for(let w=0,d=e.length;w<d;w++)if(e[w].trim()!==""){let f;if(S(e,w,n.heads,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=b,!0)})&&f){c=!0,h&&(h=!0);let p;S(e,f,n.tails,{trimBeforeMatching:!0,cb:(m,b,v)=>(p=v,!0)})&&g.push(w,p),s.current()&&o&&T!=="tails"&&g.push(s.current()),o||s.current()&&(g.push(s.current()),s.wipe()),s.push(w,f),T="heads",w=f-1;continue}if(S(e,w,n.tails,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=Number.isInteger(b)?b:e.length,!0)})&&f){c=!0,h?(T==="heads"&&s.wipe(),h=!1):s.push(w,f),T="tails",w=f-1;continue}h&&(h=!0),c&&!o?(o=!0,c=!1):c&&!a?(a=!0,h=!0,c=!1,T==="heads"&&s.wipe()):c&&a&&s.wipe()}return s.current()&&g.push(s.current()),g.current()?L(e,g.current()).trim():e.trim()}var er="11.1.2";var ci=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,l;return typeof e=="string"&&e.length&&S(e,0,t,{trimBeforeMatching:!0,cb:(n,o,a)=>(i=a,!0)})&&k(e,e.length-1,r,{trimBeforeMatching:!0,cb:(n,o,a)=>(l=(a||0)+1,!0)})?e.slice(i,l):e}function rr(e,t,r=!1,i,l,n){if(t.wrapHeadsWith||(t.wrapHeadsWith=""),t.wrapTailsWith||(t.wrapTailsWith=""),A(e)&&!r&&t.wrapGlobalFlipSwitch&&!t.dontWrapVars.some(o=>ge(n,o))&&(!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 o=Qt(e,{heads:t.wrapHeadsWith,tails:t.wrapTailsWith});return A(o)?bi(o,t.wrapHeadsWith,t.wrapTailsWith):o}return e}function Ti(e,t,r,i){let l;if(r.indexOf(".")!==-1){let n=r,o=!0;if(i.lookForDataContainers&&typeof i.dataContainerIdentifierTails=="string"&&i.dataContainerIdentifierTails.length&&!n.endsWith(i.dataContainerIdentifierTails)){let a=W.default.get(e,n+i.dataContainerIdentifierTails);ee(a)&&W.default.get(a,t)&&(l=W.default.get(a,t),o=!1)}for(;o&&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 a=W.default.get(e,n+i.dataContainerIdentifierTails);ee(a)&&W.default.get(a,t)&&(l=W.default.get(a,t),o=!1)}if(l===void 0){let a=W.default.get(e,n);ee(a)&&W.default.get(a,t)&&(l=W.default.get(a,t),o=!1)}}}if(l===void 0){let n=W.default.get(e,t);n!==void 0&&(l=n)}if(l===void 0)if(t.indexOf(".")===-1){let n=Be(e,t);if(n.length){for(let o=0,a=n.length;o<a;o++)if(A(n[o].val)||Le(n[o].val)||de(n[o].val)){l=n[o].val;break}else if(di(n[o].val)){l=String(n[o].val);break}else if(Array.isArray(n[o].val)){l=n[o].val.join("");break}}}else{let n=Be(e,mi(t));if(n.length)for(let o=0,a=n.length;o<a;o++){let g=W.default.get(n[o].val,wi(t));g&&A(g)&&(l=g)}}return l}function ar(e,t,r,i,l=[]){if(l.includes(r)){let y="";if(l.length>1){let u=` \u2192
40
+ `||r.tab&&o===" "||r.nbsp&&o==="\xA0")}let l,n;if(e.length){if(i(e[0]))for(let o=0,a=e.length;o<a;o++){if(!i(e[o])){l=o;break}if(o===e.length-1)return{res:"",ranges:[[0,e.length]]}}if(i(e[e.length-1])){for(let o=e.length;o--;)if(!i(e[o])){n=o+1;break}}return l?n?{res:e.slice(l,n),ranges:[[0,l],[n,e.length]]}:{res:e.slice(l),ranges:[[0,l]]}: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(w=>typeof w=="string"||Array.isArray(w)))typeof i.heads=="string"&&(i.heads=I(i.heads));else throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_04] The resolvedOpts.heads contains elements which are not string-type!");if(i&&r.call(i,"tails"))if(I(i.tails).every(w=>typeof w=="string"||Array.isArray(w)))typeof i.tails=="string"&&(i.tails=I(i.tails));else throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_05] The resolvedOpts.tails contains elements which are not string-type!");let l=Q(e).res;if(l.length===0)return e;e=l;let n=$($({},gi),i);n.heads=n.heads.map(w=>w.trim()),n.tails=n.tails.map(w=>w.trim());let o=!1,a=!1,g=new Z({limitToBeAddedWhitespace:!0}),s=new Z({limitToBeAddedWhitespace:!0}),h=!0,c=!0,T="";function y(w,d){let f;return S(w,0,d.heads,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=b,!0)})&&S(w,f,d.tails,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=b,!0)})?w.slice(f):w}for(;e!==y(e,n);)e=Q(y(e,n)).res;function u(w,d){let f;return!k(w,w.length-1,d.tails,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=b,!0)})||!f?w:k(w,f,d.heads,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=b,!0)})?w.slice(0,f+1):w}for(;e!==u(e,n);)e=Q(u(e,n)).res;if(!n.heads.length||!S(e,0,n.heads,{trimBeforeMatching:!0})||!n.tails.length||!k(e,e.length-1,n.tails,{trimBeforeMatching:!0}))return Q(e).res;for(let w=0,d=e.length;w<d;w++)if(e[w].trim()!==""){let f;if(S(e,w,n.heads,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=b,!0)})&&f){c=!0,h&&(h=!0);let p;S(e,f,n.tails,{trimBeforeMatching:!0,cb:(m,b,v)=>(p=v,!0)})&&g.push(w,p),s.current()&&o&&T!=="tails"&&g.push(s.current()),o||s.current()&&(g.push(s.current()),s.wipe()),s.push(w,f),T="heads",w=f-1;continue}if(S(e,w,n.tails,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=Number.isInteger(b)?b:e.length,!0)})&&f){c=!0,h?(T==="heads"&&s.wipe(),h=!1):s.push(w,f),T="tails",w=f-1;continue}h&&(h=!0),c&&!o?(o=!0,c=!1):c&&!a?(a=!0,h=!0,c=!1,T==="heads"&&s.wipe()):c&&a&&s.wipe()}return s.current()&&g.push(s.current()),g.current()?L(e,g.current()).trim():e.trim()}var er="11.1.3";var ci=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,l;return typeof e=="string"&&e.length&&S(e,0,t,{trimBeforeMatching:!0,cb:(n,o,a)=>(i=a,!0)})&&k(e,e.length-1,r,{trimBeforeMatching:!0,cb:(n,o,a)=>(l=(a||0)+1,!0)})?e.slice(i,l):e}function rr(e,t,r=!1,i,l,n){if(t.wrapHeadsWith||(t.wrapHeadsWith=""),t.wrapTailsWith||(t.wrapTailsWith=""),A(e)&&!r&&t.wrapGlobalFlipSwitch&&!t.dontWrapVars.some(o=>ge(n,o))&&(!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 o=Qt(e,{heads:t.wrapHeadsWith,tails:t.wrapTailsWith});return A(o)?bi(o,t.wrapHeadsWith,t.wrapTailsWith):o}return e}function Ti(e,t,r,i){let l;if(r.indexOf(".")!==-1){let n=r,o=!0;if(i.lookForDataContainers&&typeof i.dataContainerIdentifierTails=="string"&&i.dataContainerIdentifierTails.length&&!n.endsWith(i.dataContainerIdentifierTails)){let a=W.default.get(e,n+i.dataContainerIdentifierTails);ee(a)&&W.default.get(a,t)&&(l=W.default.get(a,t),o=!1)}for(;o&&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 a=W.default.get(e,n+i.dataContainerIdentifierTails);ee(a)&&W.default.get(a,t)&&(l=W.default.get(a,t),o=!1)}if(l===void 0){let a=W.default.get(e,n);ee(a)&&W.default.get(a,t)&&(l=W.default.get(a,t),o=!1)}}}if(l===void 0){let n=W.default.get(e,t);n!==void 0&&(l=n)}if(l===void 0)if(t.indexOf(".")===-1){let n=Be(e,t);if(n.length){for(let o=0,a=n.length;o<a;o++)if(A(n[o].val)||Le(n[o].val)||de(n[o].val)){l=n[o].val;break}else if(di(n[o].val)){l=String(n[o].val);break}else if(Array.isArray(n[o].val)){l=n[o].val.join("");break}}}else{let n=Be(e,mi(t));if(n.length)for(let o=0,a=n.length;o<a;o++){let g=W.default.get(n[o].val,wi(t));g&&A(g)&&(l=g)}}return l}function ar(e,t,r,i,l=[]){if(l.includes(r)){let y="";if(l.length>1){let u=` \u2192
41
41
  `;y=l.reduce((w,d,f)=>w+(f===0?"":u)+(d===r?"\u{1F4A5} ":" ")+d,` Here's the path we travelled up until we hit the recursion:
42
42
 
43
43
  `),y+=`${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."${y}`)}let n={},o=Array.from(l);o.push(r);let a=new Z;function g(y,u,w){for(let d=0,f=y.length;d<f;d++){let p=y[d],m=t.slice(p.headsEndAt,p.tailsStartAt);if(m.length===0)a.push(p.headsStartAt,p.tailsEndAt);else if(pi.call(n,m)&&A(n[m]))a.push(p.headsStartAt,p.tailsEndAt,n[m]);else{let b=Ti(e,m.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(!w&&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 a.wipe(),i.resolveToFalseIfAnyValuesContainBool?!1:b;b=""}else{if(de(b)&&w)return a.wipe(),b;Array.isArray(b)?b=String(b.join("")):de(b)?b="":b=String(b)}let v=r.includes(".")?`${ir(r)}.${m}`:m;if(qe(b,i)){let E=rr(ar(e,b,v,i,o),i,u,o,v,m.trim());typeof E=="string"&&a.push(p.headsStartAt,p.tailsEndAt,E)}else{n[m]=b;let E=rr(b,i,u,o,v,m.trim());typeof E=="string"&&a.push(p.headsStartAt,p.tailsEndAt,E)}}}}let s;try{s=Pe(t,i.heads,i.tails,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(y){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:
@@ -79,7 +79,7 @@ Please check the following key: ${o}`);if(a!==void 0?n=a:n=o,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.2.2
82
+ * @version 6.2.3
83
83
  * @author Roy Revelt, Codsen Ltd
84
84
  * @license MIT
85
85
  * {@link https://codsen.com/os/ranges-apply/}
@@ -135,7 +135,7 @@ Please check the following key: ${o}`);if(a!==void 0?n=a:n=o,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.1.2
138
+ * @version 6.1.3
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.1.2",
3
+ "version": "11.1.3",
4
4
  "description": "Resolves custom-marked, cross-referenced paths in parsed JSON",
5
5
  "keywords": [
6
6
  "comb",
@@ -81,10 +81,10 @@
81
81
  "ast-monkey-traverse": "^3.1.1",
82
82
  "matcher": "^5.0.0",
83
83
  "object-path": "^0.11.8",
84
- "ranges-apply": "^6.2.2",
84
+ "ranges-apply": "^6.2.3",
85
85
  "ranges-push": "^6.2.2",
86
86
  "string-find-heads-tails": "^5.1.2",
87
87
  "string-match-left-right": "^8.2.2",
88
- "string-remove-duplicate-heads-tails": "^6.1.2"
88
+ "string-remove-duplicate-heads-tails": "^6.1.3"
89
89
  }
90
90
  }