json-variables 11.0.17 → 11.0.18

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,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.17
4
+ * @version 11.0.18
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.0.17";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 r=0,n=e.length;r<n;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,n=e.length;r<n;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)||g(r.headsNoWrap)&&r.headsNoWrap.length&&e.includes(r.headsNoWrap)||g(r.tailsNoWrap)&&r.tailsNoWrap.length&&e.includes(r.tailsNoWrap))}function X(e,r,n){let o,i;return typeof e=="string"&&e.length&&M(e,0,r,{trimBeforeMatching:!0,cb:(t,a,l)=>(o=l,!0)})&&U(e,e.length-1,n,{trimBeforeMatching:!0,cb:(t,a,l)=>(i=(l||0)+1,!0)})?e.slice(o,i):e}function H(e,r,n=!1,o,i,t){if(r.wrapHeadsWith||(r.wrapHeadsWith=""),r.wrapTailsWith||(r.wrapTailsWith=""),g(e)&&!n&&r.wrapGlobalFlipSwitch&&!r.dontWrapVars.some(a=>x(t,a))&&(!r.preventDoubleWrapping||r.preventDoubleWrapping&&g(e)&&!e.includes(r.wrapHeadsWith)&&!e.includes(r.wrapTailsWith)))return`${r.wrapHeadsWith}${e}${r.wrapTailsWith}`;if(n){if(!g(e))return e;let a=L(e,{heads:r.wrapHeadsWith,tails:r.wrapTailsWith});return g(a)?X(a,r.wrapHeadsWith,r.wrapTailsWith):a}return e}function Z(e,r,n,o){let i;if(n.indexOf(".")!==-1){let t=n,a=!0;if(o.lookForDataContainers&&typeof o.dataContainerIdentifierTails=="string"&&o.dataContainerIdentifierTails.length&&!t.endsWith(o.dataContainerIdentifierTails)){let l=h.get(e,t+o.dataContainerIdentifierTails);V(l)&&h.get(l,r)&&(i=h.get(l,r),a=!1)}for(;a&&t.indexOf(".")!==-1;){if(t=J(t),P(t)===r)throw new Error(`json-variables/findValues(): [THROW_ID_20] While trying to resolve: "${r}" at path "${n}", we encountered a closed loop. The parent key "${P(t)}" is called the same as the variable "${r}" we're looking for.`);if(o.lookForDataContainers&&typeof o.dataContainerIdentifierTails=="string"&&o.dataContainerIdentifierTails.length&&!t.endsWith(o.dataContainerIdentifierTails)){let l=h.get(e,t+o.dataContainerIdentifierTails);V(l)&&h.get(l,r)&&(i=h.get(l,r),a=!1)}if(i===void 0){let l=h.get(e,t);V(l)&&h.get(l,r)&&(i=h.get(l,r),a=!1)}}}if(i===void 0){let t=h.get(e,r);t!==void 0&&(i=t)}if(i===void 0)if(r.indexOf(".")===-1){let t=_(e,r);if(t.length){for(let a=0,l=t.length;a<l;a++)if(g(t[a].val)||O(t[a].val)||N(t[a].val)){i=t[a].val;break}else if(G(t[a].val)){i=String(t[a].val);break}else if(Array.isArray(t[a].val)){i=t[a].val.join("");break}}}else{let t=_(e,Y(r));if(t.length)for(let a=0,l=t.length;a<l;a++){let y=h.get(t[a].val,Q(r));y&&g(y)&&(i=y)}}return i}function R(e,r,n,o,i=[]){if(i.includes(n)){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.0.18";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,n=e.length;t<n;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,n=e.length;t<n;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,n){let o,i;return typeof e=="string"&&e.length&&M(e,0,t,{trimBeforeMatching:!0,cb:(r,a,l)=>(o=l,!0)})&&U(e,e.length-1,n,{trimBeforeMatching:!0,cb:(r,a,l)=>(i=(l||0)+1,!0)})?e.slice(o,i):e}function H(e,t,n=!1,o,i,r){if(t.wrapHeadsWith||(t.wrapHeadsWith=""),t.wrapTailsWith||(t.wrapTailsWith=""),g(e)&&!n&&t.wrapGlobalFlipSwitch&&!t.dontWrapVars.some(a=>x(r,a))&&(!t.preventDoubleWrapping||t.preventDoubleWrapping&&g(e)&&!e.includes(t.wrapHeadsWith)&&!e.includes(t.wrapTailsWith)))return`${t.wrapHeadsWith}${e}${t.wrapTailsWith}`;if(n){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,n,o){let i;if(n.indexOf(".")!==-1){let r=n,a=!0;if(o.lookForDataContainers&&typeof o.dataContainerIdentifierTails=="string"&&o.dataContainerIdentifierTails.length&&!r.endsWith(o.dataContainerIdentifierTails)){let l=h.get(e,r+o.dataContainerIdentifierTails);V(l)&&h.get(l,t)&&(i=h.get(l,t),a=!1)}for(;a&&r.indexOf(".")!==-1;){if(r=J(r),P(r)===t)throw new Error(`json-variables/findValues(): [THROW_ID_20] While trying to resolve: "${t}" at path "${n}", we encountered a closed loop. The parent key "${P(r)}" is called the same as the variable "${t}" we're looking for.`);if(o.lookForDataContainers&&typeof o.dataContainerIdentifierTails=="string"&&o.dataContainerIdentifierTails.length&&!r.endsWith(o.dataContainerIdentifierTails)){let l=h.get(e,r+o.dataContainerIdentifierTails);V(l)&&h.get(l,t)&&(i=h.get(l,t),a=!1)}if(i===void 0){let l=h.get(e,r);V(l)&&h.get(l,t)&&(i=h.get(l,t),a=!1)}}}if(i===void 0){let r=h.get(e,t);r!==void 0&&(i=r)}if(i===void 0)if(t.indexOf(".")===-1){let r=_(e,t);if(r.length){for(let a=0,l=r.length;a<l;a++)if(g(r[a].val)||O(r[a].val)||N(r[a].val)){i=r[a].val;break}else if(G(r[a].val)){i=String(r[a].val);break}else if(Array.isArray(r[a].val)){i=r[a].val.join("");break}}}else{let r=_(e,Y(t));if(r.length)for(let a=0,l=r.length;a<l;a++){let y=h.get(r[a].val,Q(t));y&&g(y)&&(i=y)}}return i}function R(e,t,n,o,i=[]){if(i.includes(n)){let c="";if(i.length>1){let w=` \u2192
11
11
  `;c=i.reduce((D,b,S)=>D+(S===0?"":w)+(b===n?"\u{1F4A5} ":" ")+b,` Here's the path we travelled up until we hit the recursion:
12
12
 
13
- `),c+=`${w}\u{1F4A5} ${n}`}throw new Error(`json-variables/resolveString(): [THROW_ID_19] While trying to resolve: "${r}" at path "${n}", we encountered a closed loop, the key is referencing itself."${c}`)}let t={},a=Array.from(i);a.push(n);let l=new B;function y(c,w,D){for(let b=0,S=c.length;b<S;b++){let f=c[b],p=r.slice(f.headsEndAt,f.tailsStartAt);if(p.length===0)l.push(f.headsStartAt,f.tailsEndAt);else if(q.call(t,p)&&g(t[p]))l.push(f.headsStartAt,f.tailsEndAt,t[p]);else{let s=Z(e,p.trim(),n,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 ${r.slice(f.headsEndAt,f.tailsStartAt)}. We're at path: "${n}".`);if(!D&&o.throwWhenNonStringInsertedInString&&!g(s))throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_23] While resolving the variable ${r.slice(f.headsEndAt,f.tailsStartAt)} at path ${n}, 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=n.includes(".")?`${J(n)}.${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{t[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(r,o.heads,o.tails,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(c){throw new Error(`json-variables/resolveString(): [THROW_ID_17] While trying to resolve string: "${r}" at path ${n}, something wrong with heads and tails was detected! Here's the internal error message:
14
- ${c}`)}let W=!1;d.length===1&&A(r,[[d[0].headsStartAt,d[0].tailsEndAt]]).trim()===""&&(W=!0);let $=y(d,!1,W);if(typeof $=="boolean"||$===null)return $;try{d=I(r,o.headsNoWrap,o.tailsNoWrap,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(c){throw new Error(`json-variables/resolveString(): [THROW_ID_22] While trying to resolve string: "${r}" at path ${n}, something wrong with no-wrap heads and no-wrap tails was detected! Here's the internal error message:
15
- ${c}`)}d.length===1&&A(r,[[d[0].headsStartAt,d[0].tailsEndAt]]).trim()===""&&(W=!0);let E=y(d,!0,W);return O(E)||N(E)?E:l?.current()?A(r,l.current()):r}function de(e,r){if(!arguments.length)throw new Error("json-variables/jVar(): [THROW_ID_01] Alas! Inputs are missing!");if(!V(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&&!V(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 n={...K,...r};n.dontWrapVars?Array.isArray(n.dontWrapVars)||(n.dontWrapVars=F(n.dontWrapVars)):n.dontWrapVars=[];let o,i;if(n.dontWrapVars.length&&!n.dontWrapVars.every((a,l)=>g(a)?!0:(o=a,i=l,!1)))throw new Error(`json-variables/jVar(): [THROW_ID_05] Alas! All variable names set in resolvedOpts.dontWrapVars should be of a string type. Computer detected a value "${o}" at index ${i}, which is not string but ${Array.isArray(o)?"array":typeof o}!`);if(n.heads==="")throw new Error("json-variables/jVar(): [THROW_ID_06] Alas! resolvedOpts.heads are empty!");if(n.tails==="")throw new Error("json-variables/jVar(): [THROW_ID_07] Alas! resolvedOpts.tails are empty!");if(n.lookForDataContainers&&n.dataContainerIdentifierTails==="")throw new Error("json-variables/jVar(): [THROW_ID_08] Alas! resolvedOpts.dataContainerIdentifierTails is empty!");if(n.heads===n.tails)throw new Error("json-variables/jVar(): [THROW_ID_09] Alas! resolvedOpts.heads and resolvedOpts.tails can't be equal!");if(n.heads===n.headsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_10] Alas! resolvedOpts.heads and resolvedOpts.headsNoWrap can't be equal!");if(n.tails===n.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_11] Alas! resolvedOpts.tails and resolvedOpts.tailsNoWrap can't be equal!");if(n.headsNoWrap==="")throw new Error("json-variables/jVar(): [THROW_ID_12] Alas! resolvedOpts.headsNoWrap is an empty string!");if(n.tailsNoWrap==="")throw new Error("json-variables/jVar(): [THROW_ID_13] Alas! resolvedOpts.tailsNoWrap is an empty string!");if(n.headsNoWrap===n.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_14] Alas! resolvedOpts.headsNoWrap and resolvedOpts.tailsNoWrap can't be equal!");let t;return C(e,(a,l,y)=>{if(z(l)&&T(a,n))throw new Error(`json-variables/jVar(): [THROW_ID_15] Alas! Object keys can't contain variables!
16
- Please check the following key: ${a}`);if(l!==void 0?t=l:t=a,t==="")return t;if(n.heads.length&&u(t)===u(n.heads)||n.tails.length&&u(t)===u(n.tails)||n.headsNoWrap.length&&u(t)===u(n.headsNoWrap)||n.tailsNoWrap.length&&u(t)===u(n.tailsNoWrap)){if(!n.noSingleMarkers)return t;throw new Error(`json-variables/jVar(): [THROW_ID_16] Alas! While processing the input, we stumbled upon ${u(t)} which is equal to ${u(t)===u(n.heads)?"heads":""}${u(t)===u(n.tails)?"tails":""}${g(n.headsNoWrap)&&u(t)===u(n.headsNoWrap)?"headsNoWrap":""}${g(n.tailsNoWrap)&&u(t)===u(n.tailsNoWrap)?"tailsNoWrap":""}. If you wouldn't have set resolvedOpts.noSingleMarkers to "true" this error would not happen and computer would have left the current element (${u(t)}) alone`)}return g(t)&&T(t,n)?R(e,t,y.path,n):t})}export{K as defaults,de as jVar,he as version};
13
+ `),c+=`${w}\u{1F4A5} ${n}`}throw new Error(`json-variables/resolveString(): [THROW_ID_19] While trying to resolve: "${t}" at path "${n}", we encountered a closed loop, the key is referencing itself."${c}`)}let r={},a=Array.from(i);a.push(n);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(r,p)&&g(r[p]))l.push(f.headsStartAt,f.tailsEndAt,r[p]);else{let s=Z(e,p.trim(),n,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: "${n}".`);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 ${n}, 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=n.includes(".")?`${J(n)}.${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{r[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 ${n}, something wrong with heads and tails was detected! Here's the internal error message:
14
+ ${c}`)}let W=!1;d.length===1&&A(t,[[d[0].headsStartAt,d[0].tailsEndAt]]).trim()===""&&(W=!0);let $=y(d,!1,W);if(typeof $=="boolean"||$===null)return $;try{d=I(t,o.headsNoWrap,o.tailsNoWrap,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(c){throw new Error(`json-variables/resolveString(): [THROW_ID_22] While trying to resolve string: "${t}" at path ${n}, something wrong with no-wrap heads and no-wrap tails was detected! Here's the internal error message:
15
+ ${c}`)}d.length===1&&A(t,[[d[0].headsStartAt,d[0].tailsEndAt]]).trim()===""&&(W=!0);let E=y(d,!0,W);return O(E)||N(E)?E:l?.current()?A(t,l.current()):t}function de(e,t){if(!arguments.length)throw new Error("json-variables/jVar(): [THROW_ID_01] Alas! Inputs are missing!");if(!V(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&&!V(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 n={...K,...t};n.dontWrapVars?Array.isArray(n.dontWrapVars)||(n.dontWrapVars=F(n.dontWrapVars)):n.dontWrapVars=[];let o,i;if(n.dontWrapVars.length&&!n.dontWrapVars.every((a,l)=>g(a)?!0:(o=a,i=l,!1)))throw new Error(`json-variables/jVar(): [THROW_ID_05] Alas! All variable names set in resolvedOpts.dontWrapVars should be of a string type. Computer detected a value "${o}" at index ${i}, which is not string but ${Array.isArray(o)?"array":typeof o}!`);if(n.heads==="")throw new Error("json-variables/jVar(): [THROW_ID_06] Alas! resolvedOpts.heads are empty!");if(n.tails==="")throw new Error("json-variables/jVar(): [THROW_ID_07] Alas! resolvedOpts.tails are empty!");if(n.lookForDataContainers&&n.dataContainerIdentifierTails==="")throw new Error("json-variables/jVar(): [THROW_ID_08] Alas! resolvedOpts.dataContainerIdentifierTails is empty!");if(n.heads===n.tails)throw new Error("json-variables/jVar(): [THROW_ID_09] Alas! resolvedOpts.heads and resolvedOpts.tails can't be equal!");if(n.heads===n.headsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_10] Alas! resolvedOpts.heads and resolvedOpts.headsNoWrap can't be equal!");if(n.tails===n.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_11] Alas! resolvedOpts.tails and resolvedOpts.tailsNoWrap can't be equal!");if(n.headsNoWrap==="")throw new Error("json-variables/jVar(): [THROW_ID_12] Alas! resolvedOpts.headsNoWrap is an empty string!");if(n.tailsNoWrap==="")throw new Error("json-variables/jVar(): [THROW_ID_13] Alas! resolvedOpts.tailsNoWrap is an empty string!");if(n.headsNoWrap===n.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_14] Alas! resolvedOpts.headsNoWrap and resolvedOpts.tailsNoWrap can't be equal!");let r;return C(e,(a,l,y)=>{if(z(l)&&T(a,n))throw new Error(`json-variables/jVar(): [THROW_ID_15] Alas! Object keys can't contain variables!
16
+ Please check the following key: ${a}`);if(l!==void 0?r=l:r=a,r==="")return r;if(n.heads.length&&u(r)===u(n.heads)||n.tails.length&&u(r)===u(n.tails)||n.headsNoWrap.length&&u(r)===u(n.headsNoWrap)||n.tailsNoWrap.length&&u(r)===u(n.tailsNoWrap)){if(!n.noSingleMarkers)return r;throw new Error(`json-variables/jVar(): [THROW_ID_16] Alas! While processing the input, we stumbled upon ${u(r)} which is equal to ${u(r)===u(n.heads)?"heads":""}${u(r)===u(n.tails)?"tails":""}${g(n.headsNoWrap)&&u(r)===u(n.headsNoWrap)?"headsNoWrap":""}${g(n.tailsNoWrap)&&u(r)===u(n.tailsNoWrap)?"tailsNoWrap":""}. If you wouldn't have set resolvedOpts.noSingleMarkers to "true" this error would not happen and computer would have left the current element (${u(r)}) alone`)}return g(r)&&T(r,n)?R(e,r,y.path,n):r})}export{K as defaults,de as jVar,he as version};
@@ -1,7 +1,7 @@
1
- /**
1
+ "use strict";/**
2
2
  * @name json-variables
3
3
  * @fileoverview Resolves custom-marked, cross-referenced paths in parsed JSON
4
- * @version 11.0.17
4
+ * @version 11.0.18
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/json-variables/}
@@ -37,7 +37,7 @@ ${JSON.stringify(t,null,4)} (type ${typeof t})`);else i=$({},Gt);let o=e.filter(
37
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 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 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=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,o;if(r.strictlyTwoElementsInRangeArrays&&!e.every((a,c)=>!Array.isArray(a)||a.length!==2?(i=c,o=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 ${o} elements!`);if(!e.every((a,c)=>!Array.isArray(a)||!Number.isInteger(a[0])||a[0]<0||!Number.isInteger(a[1])||a[1]<0?(i=c,!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((a,c)=>(r.progressFn&&(l+=1,r.progressFn(Math.floor(l*100/n))),a[0]===c[0]?a[1]<c[1]?-1:a[1]>c[1]?1:0:a[0]<c[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
38
  ${JSON.stringify(t,null,4)} (type ${typeof t})`);else i=$({},zt);let o=e.filter(s=>Array.isArray(s)).map(s=>[...s]).filter(s=>s[2]!==void 0||s[0]!==s[1]),n,l,a;i.progressFn?n=Fe(o,{progressFn:s=>{a=Math.floor(s/5),a!==l&&(l=a,i.progressFn(a))}}):n=Fe(o);let c=n.length-1;for(let s=c;s>0;s--)i.progressFn&&(a=Math.floor((1-s/c)*78)+21,a!==l&&a>l&&(l=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,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,a=0;n.filter(g=>g).forEach((g,h)=>{if(r&&(i=Math.floor(a/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 ${h}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 ${h}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[h][0]=+n[h][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 ${h}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[h][1]=+n[h][1]}a+=1});let c=Yt(n,{progressFn:g=>{r&&(i=10+Math.floor(g/10),i!==o&&(o=i,r(i)))}});Xt(c);let s=c.length;if(s>0){let g=e.slice(c[s-1][1]);e=c.reduce((h,T,m,u)=>{r&&(i=20+Math.floor(m/s*80),i!==o&&(o=i,r(i)));let y=m===0?0:u[m-1][1],d=u[m][0];return`${h}${e.slice(y,d)}${u[m][2]||""}`},""),e+=g}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(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,a=e.length;l<a;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 resolvedOpts.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 resolvedOpts.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,a=!1,c=new Z({limitToBeAddedWhitespace:!0}),s=new Z({limitToBeAddedWhitespace:!0}),g=!0,h=!0,T="";function m(y,d){let f;return S(y,0,d.heads,{trimBeforeMatching:!0,cb:(p,w,b)=>(f=b,!0)})&&S(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||!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 y=0,d=e.length;y<d;y++)if(e[y].trim()!==""){let f;if(S(e,y,n.heads,{trimBeforeMatching:!0,cb:(p,w,b)=>(f=b,!0)})&&f){h=!0,g&&(g=!0);let p;S(e,f,n.tails,{trimBeforeMatching:!0,cb:(w,b,v)=>(p=v,!0)})&&c.push(y,p),s.current()&&l&&T!=="tails"&&c.push(s.current()),l||s.current()&&(c.push(s.current()),s.wipe()),s.push(y,f),T="heads",y=f-1;continue}if(S(e,y,n.tails,{trimBeforeMatching:!0,cb:(p,w,b)=>(f=Number.isInteger(b)?b:e.length,!0)})&&f){h=!0,g?(T==="heads"&&s.wipe(),g=!1):s.push(y,f),T="tails",y=f-1;continue}g&&(g=!0),h&&!l?(l=!0,h=!1):h&&!a?(a=!0,g=!0,h=!1,T==="heads"&&s.wipe()):h&&a&&s.wipe()}return s.current()&&c.push(s.current()),c.current()?L(e,c.current()).trim():e.trim()}var er="11.0.17";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,o;return typeof e=="string"&&e.length&&S(e,0,t,{trimBeforeMatching:!0,cb:(n,l,a)=>(i=a,!0)})&&k(e,e.length-1,r,{trimBeforeMatching:!0,cb:(n,l,a)=>(o=(a||0)+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 a=W.default.get(e,n+i.dataContainerIdentifierTails);ee(a)&&W.default.get(a,t)&&(o=W.default.get(a,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 a=W.default.get(e,n+i.dataContainerIdentifierTails);ee(a)&&W.default.get(a,t)&&(o=W.default.get(a,t),l=!1)}if(o===void 0){let a=W.default.get(e,n);ee(a)&&W.default.get(a,t)&&(o=W.default.get(a,t),l=!1)}}}if(o===void 0){let n=W.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,a=n.length;l<a;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,a=n.length;l<a;l++){let c=W.default.get(n[l].val,wi(t));c&&A(c)&&(o=c)}}return o}function ar(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,a=e.length;l<a;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 resolvedOpts.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 resolvedOpts.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,a=!1,c=new Z({limitToBeAddedWhitespace:!0}),s=new Z({limitToBeAddedWhitespace:!0}),g=!0,h=!0,T="";function m(y,d){let f;return S(y,0,d.heads,{trimBeforeMatching:!0,cb:(p,w,b)=>(f=b,!0)})&&S(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||!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 y=0,d=e.length;y<d;y++)if(e[y].trim()!==""){let f;if(S(e,y,n.heads,{trimBeforeMatching:!0,cb:(p,w,b)=>(f=b,!0)})&&f){h=!0,g&&(g=!0);let p;S(e,f,n.tails,{trimBeforeMatching:!0,cb:(w,b,v)=>(p=v,!0)})&&c.push(y,p),s.current()&&l&&T!=="tails"&&c.push(s.current()),l||s.current()&&(c.push(s.current()),s.wipe()),s.push(y,f),T="heads",y=f-1;continue}if(S(e,y,n.tails,{trimBeforeMatching:!0,cb:(p,w,b)=>(f=Number.isInteger(b)?b:e.length,!0)})&&f){h=!0,g?(T==="heads"&&s.wipe(),g=!1):s.push(y,f),T="tails",y=f-1;continue}g&&(g=!0),h&&!l?(l=!0,h=!1):h&&!a?(a=!0,g=!0,h=!1,T==="heads"&&s.wipe()):h&&a&&s.wipe()}return s.current()&&c.push(s.current()),c.current()?L(e,c.current()).trim():e.trim()}var er="11.0.18";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,o;return typeof e=="string"&&e.length&&S(e,0,t,{trimBeforeMatching:!0,cb:(n,l,a)=>(i=a,!0)})&&k(e,e.length-1,r,{trimBeforeMatching:!0,cb:(n,l,a)=>(o=(a||0)+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 a=W.default.get(e,n+i.dataContainerIdentifierTails);ee(a)&&W.default.get(a,t)&&(o=W.default.get(a,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 a=W.default.get(e,n+i.dataContainerIdentifierTails);ee(a)&&W.default.get(a,t)&&(o=W.default.get(a,t),l=!1)}if(o===void 0){let a=W.default.get(e,n);ee(a)&&W.default.get(a,t)&&(o=W.default.get(a,t),l=!1)}}}if(o===void 0){let n=W.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,a=n.length;l<a;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,a=n.length;l<a;l++){let c=W.default.get(n[l].val,wi(t));c&&A(c)&&(o=c)}}return o}function ar(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 a=new Z;function c(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)a.push(p.headsStartAt,p.tailsEndAt);else if(pi.call(n,w)&&A(n[w]))a.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 a.wipe(),i.resolveToFalseIfAnyValuesContainBool?!1:b;b=""}else{if(de(b)&&y)return a.wipe(),b;Array.isArray(b)?b=String(b.join("")):de(b)?b="":b=String(b)}let v=r.includes(".")?`${ir(r)}.${w}`:w;if(qe(b,i)){let E=rr(ar(e,b,v,i,l),i,u,l,v,w.trim());typeof E=="string"&&a.push(p.headsStartAt,p.tailsEndAt,E)}else{n[w]=b;let E=rr(b,i,u,l,v,w.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(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:
@@ -47,7 +47,7 @@ Please check the following key: ${l}`);if(a!==void 0?n=a:n=l,n==="")return n;if(
47
47
  /**
48
48
  * @name arrayiffy-if-string
49
49
  * @fileoverview Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else.
50
- * @version 4.0.14
50
+ * @version 4.0.15
51
51
  * @author Roy Revelt, Codsen Ltd
52
52
  * @license MIT
53
53
  * {@link https://codsen.com/os/arrayiffy-if-string/}
@@ -55,7 +55,7 @@ Please check the following key: ${l}`);if(a!==void 0?n=a:n=l,n==="")return n;if(
55
55
  /**
56
56
  * @name ast-get-values-by-key
57
57
  * @fileoverview Extract values and paths from AST by keys OR set them by keys
58
- * @version 4.0.13
58
+ * @version 4.0.14
59
59
  * @author Roy Revelt, Codsen Ltd
60
60
  * @license MIT
61
61
  * {@link https://codsen.com/os/ast-get-values-by-key/}
@@ -63,7 +63,7 @@ Please check the following key: ${l}`);if(a!==void 0?n=a:n=l,n==="")return n;if(
63
63
  /**
64
64
  * @name ast-monkey-traverse
65
65
  * @fileoverview Utility library to traverse AST
66
- * @version 3.0.13
66
+ * @version 3.0.14
67
67
  * @author Roy Revelt, Codsen Ltd
68
68
  * @license MIT
69
69
  * {@link https://codsen.com/os/ast-monkey-traverse/}
@@ -71,7 +71,7 @@ Please check the following key: ${l}`);if(a!==void 0?n=a:n=l,n==="")return n;if(
71
71
  /**
72
72
  * @name ast-monkey-util
73
73
  * @fileoverview Utility library of AST helper functions
74
- * @version 2.0.13
74
+ * @version 2.0.14
75
75
  * @author Roy Revelt, Codsen Ltd
76
76
  * @license MIT
77
77
  * {@link https://codsen.com/os/ast-monkey-util/}
@@ -79,7 +79,7 @@ Please check the following key: ${l}`);if(a!==void 0?n=a: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.1.3
82
+ * @version 6.1.4
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(a!==void 0?n=a: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.1.3
90
+ * @version 8.1.4
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(a!==void 0?n=a:n=l,n==="")return n;if(
95
95
  /**
96
96
  * @name ranges-push
97
97
  * @fileoverview Gather string index ranges
98
- * @version 6.1.3
98
+ * @version 6.1.4
99
99
  * @author Roy Revelt, Codsen Ltd
100
100
  * @license MIT
101
101
  * {@link https://codsen.com/os/ranges-push/}
@@ -103,7 +103,7 @@ Please check the following key: ${l}`);if(a!==void 0?n=a:n=l,n==="")return n;if(
103
103
  /**
104
104
  * @name ranges-sort
105
105
  * @fileoverview Sort string index ranges
106
- * @version 5.0.13
106
+ * @version 5.0.14
107
107
  * @author Roy Revelt, Codsen Ltd
108
108
  * @license MIT
109
109
  * {@link https://codsen.com/os/ranges-sort/}
@@ -111,7 +111,7 @@ Please check the following key: ${l}`);if(a!==void 0?n=a:n=l,n==="")return n;if(
111
111
  /**
112
112
  * @name string-collapse-leading-whitespace
113
113
  * @fileoverview Collapse the leading and trailing whitespace of a string
114
- * @version 6.0.14
114
+ * @version 6.0.15
115
115
  * @author Roy Revelt, Codsen Ltd
116
116
  * @license MIT
117
117
  * {@link https://codsen.com/os/string-collapse-leading-whitespace/}
@@ -119,7 +119,7 @@ Please check the following key: ${l}`);if(a!==void 0?n=a: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.17
122
+ * @version 5.0.18
123
123
  * @author Roy Revelt, Codsen Ltd
124
124
  * @license MIT
125
125
  * {@link https://codsen.com/os/string-find-heads-tails/}
@@ -127,7 +127,7 @@ Please check the following key: ${l}`);if(a!==void 0?n=a:n=l,n==="")return n;if(
127
127
  /**
128
128
  * @name string-match-left-right
129
129
  * @fileoverview Match substrings on the left or right of a given index, ignoring whitespace
130
- * @version 8.1.3
130
+ * @version 8.1.4
131
131
  * @author Roy Revelt, Codsen Ltd
132
132
  * @license MIT
133
133
  * {@link https://codsen.com/os/string-match-left-right/}
@@ -135,7 +135,7 @@ Please check the following key: ${l}`);if(a!==void 0?n=a: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.17
138
+ * @version 6.0.18
139
139
  * @author Roy Revelt, Codsen Ltd
140
140
  * @license MIT
141
141
  * {@link https://codsen.com/os/string-remove-duplicate-heads-tails/}
@@ -143,7 +143,7 @@ Please check the following key: ${l}`);if(a!==void 0?n=a:n=l,n==="")return n;if(
143
143
  /**
144
144
  * @name string-trim-spaces-only
145
145
  * @fileoverview Like String.trim() but you can choose granularly what to trim
146
- * @version 4.0.13
146
+ * @version 4.0.14
147
147
  * @author Roy Revelt, Codsen Ltd
148
148
  * @license MIT
149
149
  * {@link https://codsen.com/os/string-trim-spaces-only/}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-variables",
3
- "version": "11.0.17",
3
+ "version": "11.0.18",
4
4
  "description": "Resolves custom-marked, cross-referenced paths in parsed JSON",
5
5
  "keywords": [
6
6
  "comb",
@@ -35,6 +35,7 @@
35
35
  },
36
36
  "type": "module",
37
37
  "exports": {
38
+ "types": "./types/index.d.ts",
38
39
  "script": "./dist/json-variables.umd.js",
39
40
  "default": "./dist/json-variables.esm.js"
40
41
  },
@@ -75,15 +76,15 @@
75
76
  "various": {}
76
77
  },
77
78
  "dependencies": {
78
- "arrayiffy-if-string": "^4.0.14",
79
- "ast-get-values-by-key": "^4.0.13",
80
- "ast-monkey-traverse": "^3.0.13",
79
+ "arrayiffy-if-string": "^4.0.15",
80
+ "ast-get-values-by-key": "^4.0.14",
81
+ "ast-monkey-traverse": "^3.0.14",
81
82
  "matcher": "^5.0.0",
82
83
  "object-path": "^0.11.8",
83
- "ranges-apply": "^6.1.3",
84
- "ranges-push": "^6.1.3",
85
- "string-find-heads-tails": "^5.0.17",
86
- "string-match-left-right": "^8.1.3",
87
- "string-remove-duplicate-heads-tails": "^6.0.17"
84
+ "ranges-apply": "^6.1.4",
85
+ "ranges-push": "^6.1.4",
86
+ "string-find-heads-tails": "^5.0.18",
87
+ "string-match-left-right": "^8.1.4",
88
+ "string-remove-duplicate-heads-tails": "^6.0.18"
88
89
  }
89
90
  }