json-variables 12.0.16 → 12.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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2010-2023 Roy Revelt and other contributors
3
+ Copyright (c) 2010-2024 Roy Revelt and other contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
package/README.md CHANGED
@@ -64,6 +64,6 @@ To report bugs or request features or assistance, [raise an issue](https://githu
64
64
 
65
65
  MIT License.
66
66
 
67
- Copyright © 2010-2023 Roy Revelt and other contributors.
67
+ Copyright © 2010-2024 Roy Revelt and other contributors.
68
68
 
69
69
  <p align="center"><img src="https://codsen.com/images/png-codsen-ok.png" width="98" alt="ok" align="center"> <img src="https://codsen.com/images/png-codsen-1.png" width="148" alt="codsen" align="center"> <img src="https://codsen.com/images/png-codsen-star-small.png" width="32" alt="star" align="center"></p>
@@ -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 12.0.16
4
+ * @version 12.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{matchLeftIncl as k,matchRightIncl as x}from"string-match-left-right";import{remDup as F}from"string-remove-duplicate-heads-tails";import{strFindHeadsTails as I}from"string-find-heads-tails";import{getByKey as _}from"ast-get-values-by-key";import{arrayiffy as B}from"arrayiffy-if-string";import{traverse as L}from"ast-monkey-traverse";import{rApply as O}from"ranges-apply";import h from"object-path";import{Ranges as U}from"ranges-push";import{isMatch as M}from"matcher";import{isPlainObject as w,existy as q,isBool as A,isNull as N,isStr as o,isNum as K}from"codsen-utils";var j="12.0.16";var ce=j,G=Object.prototype.hasOwnProperty,z={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(r){return o(r)?r.trim():r}function Y(r){if(o(r)&&r.length&&r.indexOf(".")!==-1){for(let e=0,t=r.length;e<t;e++)if(r[e]===".")return r.slice(0,e)}return r}function Q(r){if(o(r)&&r.length&&r.indexOf(".")!==-1){for(let e=0,t=r.length;e<t;e++)if(r[e]===".")return r.slice(e+1)}return r}function J(r){if(o(r)&&r.length&&r.indexOf(".")!==-1){for(let e=r.length;e--;)if(r[e]===".")return r.slice(0,e)}return r}function P(r){if(o(r)&&r.length&&r.indexOf(".")!==-1){for(let e=r.length;e--;)if(r[e]===".")return r.slice(e+1)}return r}function T(r,e){return!o(r)||!r.trim()?!1:!!(r.includes(e.heads)||r.includes(e.tails)||o(e.headsNoWrap)&&e.headsNoWrap.length&&r.includes(e.headsNoWrap)||o(e.tailsNoWrap)&&e.tailsNoWrap.length&&r.includes(e.tailsNoWrap))}function X(r,e,t){let l,s;return o(r)&&r.length&&x(r,0,e,{trimBeforeMatching:!0,cb:(n,a,i)=>(l=i,!0)})&&k(r,r.length-1,t,{trimBeforeMatching:!0,cb:(n,a,i)=>(s=(i||0)+1,!0)})?r.slice(l,s):r}function H(r,e,t=!1,l,s,n){if(e.wrapHeadsWith||(e.wrapHeadsWith=""),e.wrapTailsWith||(e.wrapTailsWith=""),o(r)&&!t&&e.wrapGlobalFlipSwitch&&!e.dontWrapVars.some(a=>M(n,a))&&(!e.preventDoubleWrapping||e.preventDoubleWrapping&&o(r)&&!r.includes(e.wrapHeadsWith)&&!r.includes(e.wrapTailsWith)))return`${e.wrapHeadsWith}${r}${e.wrapTailsWith}`;if(t){if(!o(r))return r;let a=F(r,{heads:e.wrapHeadsWith,tails:e.wrapTailsWith});return o(a)?X(a,e.wrapHeadsWith,e.wrapTailsWith):a}return r}function Z(r,e,t,l){let s;if(t.indexOf(".")!==-1){let n=t,a=!0;if(l.lookForDataContainers&&o(l.dataContainerIdentifierTails)&&l.dataContainerIdentifierTails.length&&!n.endsWith(l.dataContainerIdentifierTails)){let i=h.get(r,n+l.dataContainerIdentifierTails);w(i)&&h.get(i,e)&&(s=h.get(i,e),a=!1)}for(;a&&n.indexOf(".")!==-1;){if(n=J(n),P(n)===e)throw new Error(`json-variables/findValues(): [THROW_ID_20] While trying to resolve: "${e}" at path "${t}", we encountered a closed loop. The parent key "${P(n)}" is called the same as the variable "${e}" we're looking for.`);if(l.lookForDataContainers&&o(l.dataContainerIdentifierTails)&&l.dataContainerIdentifierTails.length&&!n.endsWith(l.dataContainerIdentifierTails)){let i=h.get(r,n+l.dataContainerIdentifierTails);w(i)&&h.get(i,e)&&(s=h.get(i,e),a=!1)}if(s===void 0){let i=h.get(r,n);w(i)&&h.get(i,e)&&(s=h.get(i,e),a=!1)}}}if(s===void 0){let n=h.get(r,e);n!==void 0&&(s=n)}if(s===void 0)if(e.indexOf(".")===-1){let n=_(r,e);if(n.length){for(let a=0,i=n.length;a<i;a++)if(o(n[a].val)||A(n[a].val)||N(n[a].val)){s=n[a].val;break}else if(K(n[a].val)){s=String(n[a].val);break}else if(Array.isArray(n[a].val)){s=n[a].val.join("");break}}}else{let n=_(r,Y(e));if(n.length)for(let a=0,i=n.length;a<i;a++){let m=h.get(n[a].val,Q(e));m&&o(m)&&(s=m)}}return s}function R(r,e,t,l,s=[]){if(s.includes(t)){let c="";if(s.length>1){let y=` \u2192
10
+ import{matchLeftIncl as k,matchRightIncl as x}from"string-match-left-right";import{remDup as F}from"string-remove-duplicate-heads-tails";import{strFindHeadsTails as I}from"string-find-heads-tails";import{getByKey as _}from"ast-get-values-by-key";import{arrayiffy as B}from"arrayiffy-if-string";import{traverse as L}from"ast-monkey-traverse";import{rApply as O}from"ranges-apply";import h from"object-path";import{Ranges as U}from"ranges-push";import{isMatch as M}from"matcher";import{isPlainObject as w,existy as q,isBool as A,isNull as N,isStr as o,isNum as K}from"codsen-utils";var j="12.0.18";var ce=j,G=Object.prototype.hasOwnProperty,z={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(r){return o(r)?r.trim():r}function Y(r){if(o(r)&&r.length&&r.indexOf(".")!==-1){for(let e=0,t=r.length;e<t;e++)if(r[e]===".")return r.slice(0,e)}return r}function Q(r){if(o(r)&&r.length&&r.indexOf(".")!==-1){for(let e=0,t=r.length;e<t;e++)if(r[e]===".")return r.slice(e+1)}return r}function J(r){if(o(r)&&r.length&&r.indexOf(".")!==-1){for(let e=r.length;e--;)if(r[e]===".")return r.slice(0,e)}return r}function P(r){if(o(r)&&r.length&&r.indexOf(".")!==-1){for(let e=r.length;e--;)if(r[e]===".")return r.slice(e+1)}return r}function T(r,e){return!o(r)||!r.trim()?!1:!!(r.includes(e.heads)||r.includes(e.tails)||o(e.headsNoWrap)&&e.headsNoWrap.length&&r.includes(e.headsNoWrap)||o(e.tailsNoWrap)&&e.tailsNoWrap.length&&r.includes(e.tailsNoWrap))}function X(r,e,t){let l,s;return o(r)&&r.length&&x(r,0,e,{trimBeforeMatching:!0,cb:(n,a,i)=>(l=i,!0)})&&k(r,r.length-1,t,{trimBeforeMatching:!0,cb:(n,a,i)=>(s=(i||0)+1,!0)})?r.slice(l,s):r}function H(r,e,t=!1,l,s,n){if(e.wrapHeadsWith||(e.wrapHeadsWith=""),e.wrapTailsWith||(e.wrapTailsWith=""),o(r)&&!t&&e.wrapGlobalFlipSwitch&&!e.dontWrapVars.some(a=>M(n,a))&&(!e.preventDoubleWrapping||e.preventDoubleWrapping&&o(r)&&!r.includes(e.wrapHeadsWith)&&!r.includes(e.wrapTailsWith)))return`${e.wrapHeadsWith}${r}${e.wrapTailsWith}`;if(t){if(!o(r))return r;let a=F(r,{heads:e.wrapHeadsWith,tails:e.wrapTailsWith});return o(a)?X(a,e.wrapHeadsWith,e.wrapTailsWith):a}return r}function Z(r,e,t,l){let s;if(t.indexOf(".")!==-1){let n=t,a=!0;if(l.lookForDataContainers&&o(l.dataContainerIdentifierTails)&&l.dataContainerIdentifierTails.length&&!n.endsWith(l.dataContainerIdentifierTails)){let i=h.get(r,n+l.dataContainerIdentifierTails);w(i)&&h.get(i,e)&&(s=h.get(i,e),a=!1)}for(;a&&n.indexOf(".")!==-1;){if(n=J(n),P(n)===e)throw new Error(`json-variables/findValues(): [THROW_ID_20] While trying to resolve: "${e}" at path "${t}", we encountered a closed loop. The parent key "${P(n)}" is called the same as the variable "${e}" we're looking for.`);if(l.lookForDataContainers&&o(l.dataContainerIdentifierTails)&&l.dataContainerIdentifierTails.length&&!n.endsWith(l.dataContainerIdentifierTails)){let i=h.get(r,n+l.dataContainerIdentifierTails);w(i)&&h.get(i,e)&&(s=h.get(i,e),a=!1)}if(s===void 0){let i=h.get(r,n);w(i)&&h.get(i,e)&&(s=h.get(i,e),a=!1)}}}if(s===void 0){let n=h.get(r,e);n!==void 0&&(s=n)}if(s===void 0)if(e.indexOf(".")===-1){let n=_(r,e);if(n.length){for(let a=0,i=n.length;a<i;a++)if(o(n[a].val)||A(n[a].val)||N(n[a].val)){s=n[a].val;break}else if(K(n[a].val)){s=String(n[a].val);break}else if(Array.isArray(n[a].val)){s=n[a].val.join("");break}}}else{let n=_(r,Y(e));if(n.length)for(let a=0,i=n.length;a<i;a++){let m=h.get(n[a].val,Q(e));m&&o(m)&&(s=m)}}return s}function R(r,e,t,l,s=[]){if(s.includes(t)){let c="";if(s.length>1){let y=` \u2192
11
11
  `;c=s.reduce((D,b,S)=>D+(S===0?"":y)+(b===t?"\u{1F4A5} ":" ")+b,` Here's the path we travelled up until we hit the recursion:
12
12
 
13
13
  `),c+=`${y}\u{1F4A5} ${t}`}throw new Error(`json-variables/resolveString(): [THROW_ID_19] While trying to resolve: "${e}" at path "${t}", we encountered a closed loop, the key is referencing itself."${c}`)}let n={},a=Array.from(s);a.push(t);let i=new U;function m(c,y,D){for(let b=0,S=c.length;b<S;b++){let f=c[b],p=e.slice(f.headsEndAt,f.tailsStartAt);if(p.length===0)i.push(f.headsStartAt,f.tailsEndAt);else if(G.call(n,p)&&o(n[p]))i.push(f.headsStartAt,f.tailsEndAt,n[p]);else{let u=Z(r,p.trim(),t,l);if(u===void 0)if(l.allowUnresolved===!0)u="";else if(o(l.allowUnresolved))u=l.allowUnresolved;else throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_18] We couldn't find the value to resolve the variable ${e.slice(f.headsEndAt,f.tailsStartAt)}. We're at path: "${t}".`);if(!D&&l.throwWhenNonStringInsertedInString&&!o(u))throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_23] While resolving the variable ${e.slice(f.headsEndAt,f.tailsStartAt)} at path ${t}, it resolved into a non-string value, ${JSON.stringify(u,null,4)}. This is happening because options setting "throwWhenNonStringInsertedInString" is active (set to "true").`);if(A(u)){if(l.resolveToBoolIfAnyValuesContainBool)return i.wipe(),l.resolveToFalseIfAnyValuesContainBool?!1:u;u=""}else{if(N(u)&&D)return i.wipe(),u;Array.isArray(u)?u=String(u.join("")):N(u)?u="":u=String(u)}let v=t.includes(".")?`${J(t)}.${p}`:p;if(T(u,l)){let V=H(R(r,u,v,l,a),l,y,a,v,p.trim());o(V)&&i.push(f.headsStartAt,f.tailsEndAt,V)}else{n[p]=u;let V=H(u,l,y,a,v,p.trim());o(V)&&i.push(f.headsStartAt,f.tailsEndAt,V)}}}}let d;try{d=I(e,l.heads,l.tails,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(c){throw new Error(`json-variables/resolveString(): [THROW_ID_17] While trying to resolve string: "${e}" at path ${t}, 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 12.0.16
4
+ * @version 12.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 @@ ${e.slice(h+f.length,Math.min(w,h+200))}
37
37
  --------------------------------------ends
38
38
 
39
39
 
40
- To turn off this error being thrown, set resolvedOpts.throwWhenSomethingWrongIsDetected to Boolean false.`)}else{c={},c.headsStartAt=h,c.headsEndAt=h+f.length,g=!0,h+=f.length-1,b&&(b="");continue}let p=D(e,h,n);if(g&&p&&l.matchHeadsAndTailsStrictlyInPairsByTheirOrder&&y!==void 0&&n[y]!==void 0&&n[y]!==p){let m;for(let $=n.length;$--;)if(n[$]===p){m=$;break}throw new TypeError(`${l.source}${s?": [THROW_ID_20]":""} When processing "${e}", we had "resolvedOpts.matchHeadsAndTailsStrictlyInPairsByTheirOrder" on. We found heads (${r[y]}) but the tails the followed it were not of the same index, ${y} (${n[y]}) but ${m} (${p}).`)}if(A(p))if(g){c.tailsStartAt=h,c.tailsEndAt=h+p.length,i.push(c),c={},g=!1,h+=p.length-1;continue}else l.throwWhenSomethingWrongIsDetected&&(b=`${l.source}${s?": [THROW_ID_21]":""} When processing "${e}", we found tails (${e.slice(h,h+p.length)}) starting at character with index number "${h}" but there were no heads preceding it. That's very naughty!`)}if(l.throwWhenSomethingWrongIsDetected&&h===w-1){if(Object.keys(c).length!==0)throw new TypeError(`${l.source}${s?": [THROW_ID_22]":""} When processing "${e}", we reached the end of the string and yet didn't find any tails (${JSON.stringify(n,null,4)}) to match the last detected heads (${e.slice(c.headsStartAt,c.headsEndAt)})!`);if(b)throw new Error(b)}}return i}var Ae=J(F(),1);function Ye(e){if(e.includes(".")){let r=e.lastIndexOf(".");if(!e.slice(0,r).includes("."))return e.slice(0,r);for(let n=r-1;n--;)if(e[n]===".")return e.slice(n+1,r)}return null}var X=Ye;var ee=(0,Ae.default)();function q(e,r){let n={now:!1};function a(l,t,o,s){let u=ee(l),i,g=T({depth:-1,path:""},o);if(g.depth+=1,Array.isArray(u))for(let c=0,b=u.length;c<b&&!s.now;c++){let y=g.path?`${g.path}.${c}`:`${c}`;u[c]!==void 0?(g.parent=ee(u),g.parentType="array",g.parentKey=X(y),i=a(t(u[c],void 0,H(T({},g),{path:y}),s),t,H(T({},g),{path:y}),s),Number.isNaN(i)&&c<u.length?(u.splice(c,1),c-=1):u[c]=i):u.splice(c,1)}else if(E(u))for(let c in u){if(s.now&&c!=null)break;let b=g.path?`${g.path}.${c}`:c;g.depth===0&&c!=null&&(g.topmostKey=c),g.parent=ee(u),g.parentType="object",g.parentKey=X(b),i=a(t(c,u[c],H(T({},g),{path:b}),s),t,H(T({},g),{path:b}),s),Number.isNaN(i)?delete u[c]:u[c]=i}return u}return a(e,r,{},n)}function re(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}var te=new Map,Te=(e,r)=>{if(!Array.isArray(e))switch(typeof e){case"string":e=[e];break;case"undefined":e=[];break;default:throw new TypeError(`Expected '${r}' to be a string or an array, but got a type of '${typeof e}'`)}return e.filter(n=>{if(typeof n!="string"){if(typeof n>"u")return!1;throw new TypeError(`Expected '${r}' to be an array of strings, but found a type of '${typeof n}' in the array`)}return!0})},Xe=(e,r)=>{r=T({caseSensitive:!1},r);let n=e+JSON.stringify(r);if(te.has(n))return te.get(n);let a=e[0]==="!";a&&(e=e.slice(1)),e=re(e).replace(/\\\*/g,"[\\s\\S]*");let l=new RegExp(`^${e}$`,r.caseSensitive?"":"i");return l.negated=a,te.set(n,l),l},er=(e,r,n,a)=>{if(e=Te(e,"inputs"),r=Te(r,"patterns"),r.length===0)return[];r=r.map(o=>Xe(o,n));let{allPatterns:l}=n||{},t=[];for(let o of e){let s,u=[...r].fill(!1);for(let[i,g]of r.entries())if(g.test(o)&&(u[i]=!0,s=!g.negated,!s))break;if(!(s===!1||s===void 0&&r.some(i=>!i.negated)||l&&u.some((i,g)=>!i&&!r[g].negated))&&(t.push(o),a))break}return t};function U(e,r,n){return er(e,r,n,!0).length>0}var Oe=J(F(),1);var ve=(0,Oe.default)();function ne(e,r,n){let a;n!==void 0&&(a=Array.isArray(n)?ve(n):[ve(n)]);let l=[],t=q(e,(o,s,u)=>{let i=s!==void 0?s:o;if(s!==void 0&&U(o,r,{caseSensitive:!0})){if(a===void 0)l.push({val:s,path:u.path});else if(a.length)return a.shift()}return i});return a===void 0?l:t}var N=J(Ie(),1);var Se="12.0.16";var tr=Se,nr=Object.prototype.hasOwnProperty,Ne={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 O(e){return A(e)?e.trim():e}function ir(e){if(A(e)&&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 sr(e){if(A(e)&&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 _e(e){if(A(e)&&e.length&&e.indexOf(".")!==-1){for(let r=e.length;r--;)if(e[r]===".")return e.slice(0,r)}return e}function We(e){if(A(e)&&e.length&&e.indexOf(".")!==-1){for(let r=e.length;r--;)if(e[r]===".")return e.slice(r+1)}return e}function ie(e,r){return!A(e)||!e.trim()?!1:!!(e.includes(r.heads)||e.includes(r.tails)||A(r.headsNoWrap)&&r.headsNoWrap.length&&e.includes(r.headsNoWrap)||A(r.tailsNoWrap)&&r.tailsNoWrap.length&&e.includes(r.tailsNoWrap))}function ar(e,r,n){let a,l;return A(e)&&e.length&&D(e,0,r,{trimBeforeMatching:!0,cb:(t,o,s)=>(a=s,!0)})&&R(e,e.length-1,n,{trimBeforeMatching:!0,cb:(t,o,s)=>(l=(s||0)+1,!0)})?e.slice(a,l):e}function De(e,r,n=!1,a,l,t){if(r.wrapHeadsWith||(r.wrapHeadsWith=""),r.wrapTailsWith||(r.wrapTailsWith=""),A(e)&&!n&&r.wrapGlobalFlipSwitch&&!r.dontWrapVars.some(o=>U(t,o))&&(!r.preventDoubleWrapping||r.preventDoubleWrapping&&A(e)&&!e.includes(r.wrapHeadsWith)&&!e.includes(r.wrapTailsWith)))return`${r.wrapHeadsWith}${e}${r.wrapTailsWith}`;if(n){if(!A(e))return e;let o=be(e,{heads:r.wrapHeadsWith,tails:r.wrapTailsWith});return A(o)?ar(o,r.wrapHeadsWith,r.wrapTailsWith):o}return e}function or(e,r,n,a){let l;if(n.indexOf(".")!==-1){let t=n,o=!0;if(a.lookForDataContainers&&A(a.dataContainerIdentifierTails)&&a.dataContainerIdentifierTails.length&&!t.endsWith(a.dataContainerIdentifierTails)){let s=N.default.get(e,t+a.dataContainerIdentifierTails);E(s)&&N.default.get(s,r)&&(l=N.default.get(s,r),o=!1)}for(;o&&t.indexOf(".")!==-1;){if(t=_e(t),We(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 "${We(t)}" is called the same as the variable "${r}" we're looking for.`);if(a.lookForDataContainers&&A(a.dataContainerIdentifierTails)&&a.dataContainerIdentifierTails.length&&!t.endsWith(a.dataContainerIdentifierTails)){let s=N.default.get(e,t+a.dataContainerIdentifierTails);E(s)&&N.default.get(s,r)&&(l=N.default.get(s,r),o=!1)}if(l===void 0){let s=N.default.get(e,t);E(s)&&N.default.get(s,r)&&(l=N.default.get(s,r),o=!1)}}}if(l===void 0){let t=N.default.get(e,r);t!==void 0&&(l=t)}if(l===void 0)if(r.indexOf(".")===-1){let t=ne(e,r);if(t.length){for(let o=0,s=t.length;o<s;o++)if(A(t[o].val)||L(t[o].val)||j(t[o].val)){l=t[o].val;break}else if(ge(t[o].val)){l=String(t[o].val);break}else if(Array.isArray(t[o].val)){l=t[o].val.join("");break}}}else{let t=ne(e,ir(r));if(t.length)for(let o=0,s=t.length;o<s;o++){let u=N.default.get(t[o].val,sr(r));u&&A(u)&&(l=u)}}return l}function xe(e,r,n,a,l=[]){if(l.includes(n)){let y="";if(l.length>1){let h=` \u2192
40
+ To turn off this error being thrown, set resolvedOpts.throwWhenSomethingWrongIsDetected to Boolean false.`)}else{c={},c.headsStartAt=h,c.headsEndAt=h+f.length,g=!0,h+=f.length-1,b&&(b="");continue}let p=D(e,h,n);if(g&&p&&l.matchHeadsAndTailsStrictlyInPairsByTheirOrder&&y!==void 0&&n[y]!==void 0&&n[y]!==p){let m;for(let $=n.length;$--;)if(n[$]===p){m=$;break}throw new TypeError(`${l.source}${s?": [THROW_ID_20]":""} When processing "${e}", we had "resolvedOpts.matchHeadsAndTailsStrictlyInPairsByTheirOrder" on. We found heads (${r[y]}) but the tails the followed it were not of the same index, ${y} (${n[y]}) but ${m} (${p}).`)}if(A(p))if(g){c.tailsStartAt=h,c.tailsEndAt=h+p.length,i.push(c),c={},g=!1,h+=p.length-1;continue}else l.throwWhenSomethingWrongIsDetected&&(b=`${l.source}${s?": [THROW_ID_21]":""} When processing "${e}", we found tails (${e.slice(h,h+p.length)}) starting at character with index number "${h}" but there were no heads preceding it. That's very naughty!`)}if(l.throwWhenSomethingWrongIsDetected&&h===w-1){if(Object.keys(c).length!==0)throw new TypeError(`${l.source}${s?": [THROW_ID_22]":""} When processing "${e}", we reached the end of the string and yet didn't find any tails (${JSON.stringify(n,null,4)}) to match the last detected heads (${e.slice(c.headsStartAt,c.headsEndAt)})!`);if(b)throw new Error(b)}}return i}var Ae=J(F(),1);function Ye(e){if(e.includes(".")){let r=e.lastIndexOf(".");if(!e.slice(0,r).includes("."))return e.slice(0,r);for(let n=r-1;n--;)if(e[n]===".")return e.slice(n+1,r)}return null}var X=Ye;var ee=(0,Ae.default)();function q(e,r){let n={now:!1};function a(l,t,o,s){let u=ee(l),i,g=T({depth:-1,path:""},o);if(g.depth+=1,Array.isArray(u))for(let c=0,b=u.length;c<b&&!s.now;c++){let y=g.path?`${g.path}.${c}`:`${c}`;u[c]!==void 0?(g.parent=ee(u),g.parentType="array",g.parentKey=X(y),i=a(t(u[c],void 0,H(T({},g),{path:y}),s),t,H(T({},g),{path:y}),s),Number.isNaN(i)&&c<u.length?(u.splice(c,1),c-=1):u[c]=i):u.splice(c,1)}else if(E(u))for(let c in u){if(s.now&&c!=null)break;let b=g.path?`${g.path}.${c}`:c;g.depth===0&&c!=null&&(g.topmostKey=c),g.parent=ee(u),g.parentType="object",g.parentKey=X(b),i=a(t(c,u[c],H(T({},g),{path:b}),s),t,H(T({},g),{path:b}),s),Number.isNaN(i)?delete u[c]:u[c]=i}return u}return a(e,r,{},n)}function re(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}var te=new Map,Te=(e,r)=>{if(!Array.isArray(e))switch(typeof e){case"string":e=[e];break;case"undefined":e=[];break;default:throw new TypeError(`Expected '${r}' to be a string or an array, but got a type of '${typeof e}'`)}return e.filter(n=>{if(typeof n!="string"){if(typeof n>"u")return!1;throw new TypeError(`Expected '${r}' to be an array of strings, but found a type of '${typeof n}' in the array`)}return!0})},Xe=(e,r)=>{r=T({caseSensitive:!1},r);let n=e+JSON.stringify(r);if(te.has(n))return te.get(n);let a=e[0]==="!";a&&(e=e.slice(1)),e=re(e).replace(/\\\*/g,"[\\s\\S]*");let l=new RegExp(`^${e}$`,r.caseSensitive?"":"i");return l.negated=a,te.set(n,l),l},er=(e,r,n,a)=>{if(e=Te(e,"inputs"),r=Te(r,"patterns"),r.length===0)return[];r=r.map(o=>Xe(o,n));let{allPatterns:l}=n||{},t=[];for(let o of e){let s,u=[...r].fill(!1);for(let[i,g]of r.entries())if(g.test(o)&&(u[i]=!0,s=!g.negated,!s))break;if(!(s===!1||s===void 0&&r.some(i=>!i.negated)||l&&u.some((i,g)=>!i&&!r[g].negated))&&(t.push(o),a))break}return t};function U(e,r,n){return er(e,r,n,!0).length>0}var Oe=J(F(),1);var ve=(0,Oe.default)();function ne(e,r,n){let a;n!==void 0&&(a=Array.isArray(n)?ve(n):[ve(n)]);let l=[],t=q(e,(o,s,u)=>{let i=s!==void 0?s:o;if(s!==void 0&&U(o,r,{caseSensitive:!0})){if(a===void 0)l.push({val:s,path:u.path});else if(a.length)return a.shift()}return i});return a===void 0?l:t}var N=J(Ie(),1);var Se="12.0.18";var tr=Se,nr=Object.prototype.hasOwnProperty,Ne={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 O(e){return A(e)?e.trim():e}function ir(e){if(A(e)&&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 sr(e){if(A(e)&&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 _e(e){if(A(e)&&e.length&&e.indexOf(".")!==-1){for(let r=e.length;r--;)if(e[r]===".")return e.slice(0,r)}return e}function We(e){if(A(e)&&e.length&&e.indexOf(".")!==-1){for(let r=e.length;r--;)if(e[r]===".")return e.slice(r+1)}return e}function ie(e,r){return!A(e)||!e.trim()?!1:!!(e.includes(r.heads)||e.includes(r.tails)||A(r.headsNoWrap)&&r.headsNoWrap.length&&e.includes(r.headsNoWrap)||A(r.tailsNoWrap)&&r.tailsNoWrap.length&&e.includes(r.tailsNoWrap))}function ar(e,r,n){let a,l;return A(e)&&e.length&&D(e,0,r,{trimBeforeMatching:!0,cb:(t,o,s)=>(a=s,!0)})&&R(e,e.length-1,n,{trimBeforeMatching:!0,cb:(t,o,s)=>(l=(s||0)+1,!0)})?e.slice(a,l):e}function De(e,r,n=!1,a,l,t){if(r.wrapHeadsWith||(r.wrapHeadsWith=""),r.wrapTailsWith||(r.wrapTailsWith=""),A(e)&&!n&&r.wrapGlobalFlipSwitch&&!r.dontWrapVars.some(o=>U(t,o))&&(!r.preventDoubleWrapping||r.preventDoubleWrapping&&A(e)&&!e.includes(r.wrapHeadsWith)&&!e.includes(r.wrapTailsWith)))return`${r.wrapHeadsWith}${e}${r.wrapTailsWith}`;if(n){if(!A(e))return e;let o=be(e,{heads:r.wrapHeadsWith,tails:r.wrapTailsWith});return A(o)?ar(o,r.wrapHeadsWith,r.wrapTailsWith):o}return e}function or(e,r,n,a){let l;if(n.indexOf(".")!==-1){let t=n,o=!0;if(a.lookForDataContainers&&A(a.dataContainerIdentifierTails)&&a.dataContainerIdentifierTails.length&&!t.endsWith(a.dataContainerIdentifierTails)){let s=N.default.get(e,t+a.dataContainerIdentifierTails);E(s)&&N.default.get(s,r)&&(l=N.default.get(s,r),o=!1)}for(;o&&t.indexOf(".")!==-1;){if(t=_e(t),We(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 "${We(t)}" is called the same as the variable "${r}" we're looking for.`);if(a.lookForDataContainers&&A(a.dataContainerIdentifierTails)&&a.dataContainerIdentifierTails.length&&!t.endsWith(a.dataContainerIdentifierTails)){let s=N.default.get(e,t+a.dataContainerIdentifierTails);E(s)&&N.default.get(s,r)&&(l=N.default.get(s,r),o=!1)}if(l===void 0){let s=N.default.get(e,t);E(s)&&N.default.get(s,r)&&(l=N.default.get(s,r),o=!1)}}}if(l===void 0){let t=N.default.get(e,r);t!==void 0&&(l=t)}if(l===void 0)if(r.indexOf(".")===-1){let t=ne(e,r);if(t.length){for(let o=0,s=t.length;o<s;o++)if(A(t[o].val)||L(t[o].val)||j(t[o].val)){l=t[o].val;break}else if(ge(t[o].val)){l=String(t[o].val);break}else if(Array.isArray(t[o].val)){l=t[o].val.join("");break}}}else{let t=ne(e,ir(r));if(t.length)for(let o=0,s=t.length;o<s;o++){let u=N.default.get(t[o].val,sr(r));u&&A(u)&&(l=u)}}return l}function xe(e,r,n,a,l=[]){if(l.includes(n)){let y="";if(l.length>1){let h=` \u2192
41
41
  `;y=l.reduce((w,d,f)=>w+(f===0?"":h)+(d===n?"\u{1F4A5} ":" ")+d,` Here's the path we travelled up until we hit the recursion:
42
42
 
43
43
  `),y+=`${h}\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."${y}`)}let t={},o=Array.from(l);o.push(n);let s=new B;function u(y,h,w){for(let d=0,f=y.length;d<f;d++){let p=y[d],m=r.slice(p.headsEndAt,p.tailsStartAt);if(m.length===0)s.push(p.headsStartAt,p.tailsEndAt);else if(nr.call(t,m)&&A(t[m]))s.push(p.headsStartAt,p.tailsEndAt,t[m]);else{let $=or(e,m.trim(),n,a);if($===void 0)if(a.allowUnresolved===!0)$="";else if(A(a.allowUnresolved))$=a.allowUnresolved;else throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_18] We couldn't find the value to resolve the variable ${r.slice(p.headsEndAt,p.tailsStartAt)}. We're at path: "${n}".`);if(!w&&a.throwWhenNonStringInsertedInString&&!A($))throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_23] While resolving the variable ${r.slice(p.headsEndAt,p.tailsStartAt)} at path ${n}, it resolved into a non-string value, ${JSON.stringify($,null,4)}. This is happening because options setting "throwWhenNonStringInsertedInString" is active (set to "true").`);if(L($)){if(a.resolveToBoolIfAnyValuesContainBool)return s.wipe(),a.resolveToFalseIfAnyValuesContainBool?!1:$;$=""}else{if(j($)&&w)return s.wipe(),$;Array.isArray($)?$=String($.join("")):j($)?$="":$=String($)}let v=n.includes(".")?`${_e(n)}.${m}`:m;if(ie($,a)){let S=De(xe(e,$,v,a,o),a,h,o,v,m.trim());A(S)&&s.push(p.headsStartAt,p.tailsEndAt,S)}else{t[m]=$;let S=De($,a,h,o,v,m.trim());A(S)&&s.push(p.headsStartAt,p.tailsEndAt,S)}}}}let i;try{i=Y(r,a.heads,a.tails,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(y){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:
@@ -47,7 +47,7 @@ Please check the following key: ${o}`);if(s!==void 0?t=s:t=o,t==="")return t;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 5.0.7
50
+ * @version 5.0.8
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: ${o}`);if(s!==void 0?t=s:t=o,t==="")return t;if(
55
55
  /**
56
56
  * @name codsen-utils
57
57
  * @fileoverview Various utility functions
58
- * @version 1.6.2
58
+ * @version 1.6.4
59
59
  * @author Roy Revelt, Codsen Ltd
60
60
  * @license MIT
61
61
  * {@link https://codsen.com/os/codsen-utils/}
@@ -63,7 +63,7 @@ Please check the following key: ${o}`);if(s!==void 0?t=s:t=o,t==="")return t;if(
63
63
  /**
64
64
  * @name string-match-left-right
65
65
  * @fileoverview Match substrings on the left or right of a given index, ignoring whitespace
66
- * @version 9.0.16
66
+ * @version 9.0.18
67
67
  * @author Roy Revelt, Codsen Ltd
68
68
  * @license MIT
69
69
  * {@link https://codsen.com/os/string-match-left-right/}
@@ -71,7 +71,7 @@ Please check the following key: ${o}`);if(s!==void 0?t=s:t=o,t==="")return t;if(
71
71
  /**
72
72
  * @name string-collapse-leading-whitespace
73
73
  * @fileoverview Collapse the leading and trailing whitespace of a string
74
- * @version 7.0.6
74
+ * @version 7.0.7
75
75
  * @author Roy Revelt, Codsen Ltd
76
76
  * @license MIT
77
77
  * {@link https://codsen.com/os/string-collapse-leading-whitespace/}
@@ -79,7 +79,7 @@ Please check the following key: ${o}`);if(s!==void 0?t=s:t=o,t==="")return t;if(
79
79
  /**
80
80
  * @name ranges-sort
81
81
  * @fileoverview Sort string index ranges
82
- * @version 6.0.10
82
+ * @version 6.0.11
83
83
  * @author Roy Revelt, Codsen Ltd
84
84
  * @license MIT
85
85
  * {@link https://codsen.com/os/ranges-sort/}
@@ -87,7 +87,7 @@ Please check the following key: ${o}`);if(s!==void 0?t=s:t=o,t==="")return t;if(
87
87
  /**
88
88
  * @name ranges-push
89
89
  * @fileoverview Gather string index ranges
90
- * @version 7.0.13
90
+ * @version 7.0.15
91
91
  * @author Roy Revelt, Codsen Ltd
92
92
  * @license MIT
93
93
  * {@link https://codsen.com/os/ranges-push/}
@@ -95,7 +95,7 @@ Please check the following key: ${o}`);if(s!==void 0?t=s:t=o,t==="")return t;if(
95
95
  /**
96
96
  * @name ranges-merge
97
97
  * @fileoverview Merge and sort string index ranges
98
- * @version 9.0.13
98
+ * @version 9.0.15
99
99
  * @author Roy Revelt, Codsen Ltd
100
100
  * @license MIT
101
101
  * {@link https://codsen.com/os/ranges-merge/}
@@ -103,7 +103,7 @@ Please check the following key: ${o}`);if(s!==void 0?t=s:t=o,t==="")return t;if(
103
103
  /**
104
104
  * @name ranges-apply
105
105
  * @fileoverview Take an array of string index ranges, delete/replace the string according to them
106
- * @version 7.0.13
106
+ * @version 7.0.15
107
107
  * @author Roy Revelt, Codsen Ltd
108
108
  * @license MIT
109
109
  * {@link https://codsen.com/os/ranges-apply/}
@@ -111,7 +111,7 @@ Please check the following key: ${o}`);if(s!==void 0?t=s:t=o,t==="")return t;if(
111
111
  /**
112
112
  * @name string-trim-spaces-only
113
113
  * @fileoverview Like String.trim() but you can choose granularly what to trim
114
- * @version 5.0.9
114
+ * @version 5.0.10
115
115
  * @author Roy Revelt, Codsen Ltd
116
116
  * @license MIT
117
117
  * {@link https://codsen.com/os/string-trim-spaces-only/}
@@ -119,7 +119,7 @@ Please check the following key: ${o}`);if(s!==void 0?t=s:t=o,t==="")return t;if(
119
119
  /**
120
120
  * @name string-remove-duplicate-heads-tails
121
121
  * @fileoverview Detect and (recursively) remove head and tail wrappings around the input string
122
- * @version 7.0.16
122
+ * @version 7.0.18
123
123
  * @author Roy Revelt, Codsen Ltd
124
124
  * @license MIT
125
125
  * {@link https://codsen.com/os/string-remove-duplicate-heads-tails/}
@@ -127,7 +127,7 @@ Please check the following key: ${o}`);if(s!==void 0?t=s:t=o,t==="")return t;if(
127
127
  /**
128
128
  * @name string-find-heads-tails
129
129
  * @fileoverview Finds where are arbitrary templating marker heads and tails located
130
- * @version 6.0.16
130
+ * @version 6.0.18
131
131
  * @author Roy Revelt, Codsen Ltd
132
132
  * @license MIT
133
133
  * {@link https://codsen.com/os/string-find-heads-tails/}
@@ -135,7 +135,7 @@ Please check the following key: ${o}`);if(s!==void 0?t=s:t=o,t==="")return t;if(
135
135
  /**
136
136
  * @name ast-monkey-util
137
137
  * @fileoverview Utility library of AST helper functions
138
- * @version 3.0.7
138
+ * @version 3.0.8
139
139
  * @author Roy Revelt, Codsen Ltd
140
140
  * @license MIT
141
141
  * {@link https://codsen.com/os/ast-monkey-util/}
@@ -143,7 +143,7 @@ Please check the following key: ${o}`);if(s!==void 0?t=s:t=o,t==="")return t;if(
143
143
  /**
144
144
  * @name ast-monkey-traverse
145
145
  * @fileoverview Utility library to traverse AST
146
- * @version 4.0.14
146
+ * @version 4.0.16
147
147
  * @author Roy Revelt, Codsen Ltd
148
148
  * @license MIT
149
149
  * {@link https://codsen.com/os/ast-monkey-traverse/}
@@ -151,7 +151,7 @@ Please check the following key: ${o}`);if(s!==void 0?t=s:t=o,t==="")return t;if(
151
151
  /**
152
152
  * @name ast-get-values-by-key
153
153
  * @fileoverview Extract values and paths from AST by keys OR set them by keys
154
- * @version 5.0.16
154
+ * @version 5.0.18
155
155
  * @author Roy Revelt, Codsen Ltd
156
156
  * @license MIT
157
157
  * {@link https://codsen.com/os/ast-get-values-by-key/}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-variables",
3
- "version": "12.0.16",
3
+ "version": "12.0.18",
4
4
  "description": "Resolves custom-marked, cross-referenced paths in parsed JSON",
5
5
  "keywords": [
6
6
  "comb",
@@ -78,16 +78,16 @@
78
78
  "various": {}
79
79
  },
80
80
  "dependencies": {
81
- "arrayiffy-if-string": "^5.0.7",
82
- "ast-get-values-by-key": "^5.0.16",
83
- "ast-monkey-traverse": "^4.0.14",
84
- "codsen-utils": "^1.6.2",
81
+ "arrayiffy-if-string": "^5.0.8",
82
+ "ast-get-values-by-key": "^5.0.18",
83
+ "ast-monkey-traverse": "^4.0.16",
84
+ "codsen-utils": "^1.6.4",
85
85
  "matcher": "^5.0.0",
86
86
  "object-path": "^0.11.8",
87
- "ranges-apply": "^7.0.13",
88
- "ranges-push": "^7.0.13",
89
- "string-find-heads-tails": "^6.0.16",
90
- "string-match-left-right": "^9.0.16",
91
- "string-remove-duplicate-heads-tails": "^7.0.16"
87
+ "ranges-apply": "^7.0.15",
88
+ "ranges-push": "^7.0.15",
89
+ "string-find-heads-tails": "^6.0.18",
90
+ "string-match-left-right": "^9.0.18",
91
+ "string-remove-duplicate-heads-tails": "^7.0.18"
92
92
  }
93
93
  }