json-variables 11.0.3 → 11.0.4

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,7 +1,7 @@
1
1
  /**
2
2
  * @name json-variables
3
3
  * @fileoverview Resolves custom-marked, cross-referenced paths in parsed JSON
4
- * @version 11.0.3
4
+ * @version 11.0.4
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/json-variables/}
@@ -18,7 +18,7 @@ import { rApply } from 'ranges-apply';
18
18
  import { remDup } from 'string-remove-duplicate-heads-tails';
19
19
  import { matchRightIncl, matchLeftIncl } from 'string-match-left-right';
20
20
 
21
- var version$1 = "11.0.3";
21
+ var version$1 = "11.0.4";
22
22
 
23
23
  const version = version$1;
24
24
  const has = Object.prototype.hasOwnProperty;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @name json-variables
3
3
  * @fileoverview Resolves custom-marked, cross-referenced paths in parsed JSON
4
- * @version 11.0.3
4
+ * @version 11.0.4
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/json-variables/}
@@ -11,7 +11,7 @@
11
11
  /**
12
12
  * @name ast-monkey-util
13
13
  * @fileoverview Utility library of AST helper functions
14
- * @version 2.0.3
14
+ * @version 2.0.4
15
15
  * @author Roy Revelt, Codsen Ltd
16
16
  * @license MIT
17
17
  * {@link https://codsen.com/os/ast-monkey-util/}
@@ -19,7 +19,7 @@
19
19
  /**
20
20
  * @name ast-monkey-traverse
21
21
  * @fileoverview Utility library to traverse AST
22
- * @version 3.0.3
22
+ * @version 3.0.4
23
23
  * @author Roy Revelt, Codsen Ltd
24
24
  * @license MIT
25
25
  * {@link https://codsen.com/os/ast-monkey-traverse/}
@@ -27,7 +27,7 @@
27
27
  /**
28
28
  * @name arrayiffy-if-string
29
29
  * @fileoverview Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else.
30
- * @version 4.0.3
30
+ * @version 4.0.4
31
31
  * @author Roy Revelt, Codsen Ltd
32
32
  * @license MIT
33
33
  * {@link https://codsen.com/os/arrayiffy-if-string/}
@@ -35,7 +35,7 @@
35
35
  /**
36
36
  * @name string-match-left-right
37
37
  * @fileoverview Match substrings on the left or right of a given index, ignoring whitespace
38
- * @version 8.0.3
38
+ * @version 8.0.4
39
39
  * @author Roy Revelt, Codsen Ltd
40
40
  * @license MIT
41
41
  * {@link https://codsen.com/os/string-match-left-right/}
@@ -43,7 +43,7 @@
43
43
  /**
44
44
  * @name string-find-heads-tails
45
45
  * @fileoverview Finds where are arbitrary templating marker heads and tails located
46
- * @version 5.0.3
46
+ * @version 5.0.4
47
47
  * @author Roy Revelt, Codsen Ltd
48
48
  * @license MIT
49
49
  * {@link https://codsen.com/os/string-find-heads-tails/}
@@ -51,7 +51,7 @@
51
51
  /**
52
52
  * @name ast-get-values-by-key
53
53
  * @fileoverview Extract values and paths from AST by keys OR set them by keys
54
- * @version 4.0.3
54
+ * @version 4.0.4
55
55
  * @author Roy Revelt, Codsen Ltd
56
56
  * @license MIT
57
57
  * {@link https://codsen.com/os/ast-get-values-by-key/}
@@ -59,7 +59,7 @@
59
59
  /**
60
60
  * @name string-collapse-leading-whitespace
61
61
  * @fileoverview Collapse the leading and trailing whitespace of a string
62
- * @version 6.0.3
62
+ * @version 6.0.4
63
63
  * @author Roy Revelt, Codsen Ltd
64
64
  * @license MIT
65
65
  * {@link https://codsen.com/os/string-collapse-leading-whitespace/}
@@ -67,7 +67,7 @@
67
67
  /**
68
68
  * @name ranges-push
69
69
  * @fileoverview Gather string index ranges
70
- * @version 6.0.3
70
+ * @version 6.0.4
71
71
  * @author Roy Revelt, Codsen Ltd
72
72
  * @license MIT
73
73
  * {@link https://codsen.com/os/ranges-push/}
@@ -75,7 +75,7 @@
75
75
  /**
76
76
  * @name ranges-sort
77
77
  * @fileoverview Sort string index ranges
78
- * @version 5.0.3
78
+ * @version 5.0.4
79
79
  * @author Roy Revelt, Codsen Ltd
80
80
  * @license MIT
81
81
  * {@link https://codsen.com/os/ranges-sort/}
@@ -83,7 +83,7 @@
83
83
  /**
84
84
  * @name ranges-merge
85
85
  * @fileoverview Merge and sort string index ranges
86
- * @version 8.0.3
86
+ * @version 8.0.4
87
87
  * @author Roy Revelt, Codsen Ltd
88
88
  * @license MIT
89
89
  * {@link https://codsen.com/os/ranges-merge/}
@@ -91,7 +91,7 @@
91
91
  /**
92
92
  * @name ranges-apply
93
93
  * @fileoverview Take an array of string index ranges, delete/replace the string according to them
94
- * @version 6.0.3
94
+ * @version 6.0.4
95
95
  * @author Roy Revelt, Codsen Ltd
96
96
  * @license MIT
97
97
  * {@link https://codsen.com/os/ranges-apply/}
@@ -99,7 +99,7 @@
99
99
  /**
100
100
  * @name string-trim-spaces-only
101
101
  * @fileoverview Like String.trim() but you can choose granularly what to trim
102
- * @version 4.0.3
102
+ * @version 4.0.4
103
103
  * @author Roy Revelt, Codsen Ltd
104
104
  * @license MIT
105
105
  * {@link https://codsen.com/os/string-trim-spaces-only/}
@@ -107,8 +107,8 @@
107
107
  /**
108
108
  * @name string-remove-duplicate-heads-tails
109
109
  * @fileoverview Detect and (recursively) remove head and tail wrappings around the input string
110
- * @version 6.0.3
110
+ * @version 6.0.4
111
111
  * @author Roy Revelt, Codsen Ltd
112
112
  * @license MIT
113
113
  * {@link https://codsen.com/os/string-remove-duplicate-heads-tails/}
114
- */const Q=Object.prototype.hasOwnProperty,X={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 Y(e){return"string"==typeof e}function Z(e){return"boolean"==typeof e}function ee(e){return null===e}function te(e){return e&&"object"==typeof e&&!Array.isArray(e)}function re(e){return null!=e}function ne(e){return Y(e)?e.trim():e}function ie(e){if("string"==typeof e&&e.length>0&&-1!==e.indexOf("."))for(let t=0,r=e.length;t<r;t++)if("."===e[t])return e.slice(t+1);return e}function se(e){if("string"==typeof e&&e.length>0&&-1!==e.indexOf("."))for(let t=e.length;t--;)if("."===e[t])return e.slice(0,t);return e}function oe(e){if("string"==typeof e&&e.length>0&&-1!==e.indexOf("."))for(let t=e.length;t--;)if("."===e[t])return e.slice(t+1);return e}function ae(e,t){return!("string"!=typeof e||!e.trim())&&!!(e.includes(t.heads)||e.includes(t.tails)||Y(t.headsNoWrap)&&t.headsNoWrap.length>0&&e.includes(t.headsNoWrap)||Y(t.tailsNoWrap)&&t.tailsNoWrap.length>0&&e.includes(t.tailsNoWrap))}function le(e,t,r=!1,n,i,s){if(t.wrapHeadsWith||(t.wrapHeadsWith=""),t.wrapTailsWith||(t.wrapTailsWith=""),Y(e)&&!r&&t.wrapGlobalFlipSwitch&&!t.dontWrapVars.some((e=>w(s,e)))&&(!t.preventDoubleWrapping||t.preventDoubleWrapping&&Y(e)&&!e.includes(t.wrapHeadsWith)&&!e.includes(t.wrapTailsWith)))return t.wrapHeadsWith+e+t.wrapTailsWith;if(r){if(!Y(e))return e;const r=function(e,t){const r=Object.prototype.hasOwnProperty;if(void 0===e)throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_01] The input is missing!");if("string"!=typeof e)return e;if(t&&!c(t))throw new Error(`string-remove-duplicate-heads-tails: [THROW_ID_03] The given options are not a plain object but ${typeof t}!`);const n={...t};if(n&&r.call(n,"heads")){if(!T(n.heads).every((e=>"string"==typeof e||Array.isArray(e))))throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_04] The opts.heads contains elements which are not string-type!");"string"==typeof n.heads&&(n.heads=T(n.heads))}if(n&&r.call(n,"tails")){if(!T(n.tails).every((e=>"string"==typeof e||Array.isArray(e))))throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_05] The opts.tails contains elements which are not string-type!");"string"==typeof n.tails&&(n.tails=T(n.tails))}const i=K(e).res;if(0===i.length)return e;e=i;const s={heads:["{{"],tails:["}}"],...n};s.heads=s.heads.map((e=>e.trim())),s.tails=s.tails.map((e=>e.trim()));let o=!1,a=!1;const l=new P({limitToBeAddedWhitespace:!0}),u=new P({limitToBeAddedWhitespace:!0});let f=!0,h=!0,g="";function p(e,t){let r;return E(e,0,t.heads,{trimBeforeMatching:!0,cb:(e,t,n)=>(r=n,!0)})&&E(e,r,t.tails,{trimBeforeMatching:!0,cb:(e,t,n)=>(r=n,!0)})?e.slice(r):e}for(;e!==p(e,s);)e=K(p(e,s)).res;function y(e,t){let r;return j(e,e.length-1,t.tails,{trimBeforeMatching:!0,cb:(e,t,n)=>(r=n,!0)})&&r&&j(e,r,t.heads,{trimBeforeMatching:!0,cb:(e,t,n)=>(r=n,!0)})?e.slice(0,r+1):e}for(;e!==y(e,s);)e=K(y(e,s)).res;if(!(s.heads.length&&E(e,0,s.heads,{trimBeforeMatching:!0})&&s.tails.length&&j(e,e.length-1,s.tails,{trimBeforeMatching:!0})))return K(e).res;for(let t=0,r=e.length;t<r;t++)if(""===e[t].trim());else{let r;if(E(e,t,s.heads,{trimBeforeMatching:!0,cb:(e,t,n)=>(r=n,!0)})&&r){let n;h=!0,f&&(f=!0),E(e,r,s.tails,{trimBeforeMatching:!0,cb:(e,t,r)=>(n=r,!0)})&&l.push(t,n),u.current()&&o&&"tails"!==g&&l.push(u.current()),o||u.current()&&(l.push(u.current()),u.wipe()),u.push(t,r),g="heads",t=r-1;continue}if(E(e,t,s.tails,{trimBeforeMatching:!0,cb:(t,n,i)=>(r=Number.isInteger(i)?i:e.length,!0)})&&r){h=!0,f?("heads"===g&&u.wipe(),f=!1):u.push(t,r),g="tails",t=r-1;continue}f&&(f=!0),h&&!o?(o=!0,h=!1):h&&!a?(a=!0,f=!0,h=!1,"heads"===g&&u.wipe()):h&&a&&u.wipe()}return u.current()&&l.push(u.current()),l.current()?z(e,l.current()).trim():e.trim()}(e,{heads:t.wrapHeadsWith,tails:t.wrapTailsWith});return Y(r)?function(e,t,r){let n,i;return"string"==typeof e&&e.length>0&&E(e,0,t,{trimBeforeMatching:!0,cb:(e,t,r)=>(n=r,!0)})&&j(e,e.length-1,r,{trimBeforeMatching:!0,cb:(e,t,r)=>(i=r+1,!0)})?e.slice(n,i):e}(r,t.wrapHeadsWith,t.wrapTailsWith):r}return e}function ue(e,t,r,n){let i;if(-1!==r.indexOf(".")){let s=r,o=!0;if(n.lookForDataContainers&&"string"==typeof n.dataContainerIdentifierTails&&n.dataContainerIdentifierTails.length>0&&!s.endsWith(n.dataContainerIdentifierTails)){const r=_.get(e,s+n.dataContainerIdentifierTails);te(r)&&_.get(r,t)&&(i=_.get(r,t),o=!1)}for(;o&&-1!==s.indexOf(".");){if(s=se(s),oe(s)===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 "${oe(s)}" is called the same as the variable "${t}" we're looking for.`);if(n.lookForDataContainers&&"string"==typeof n.dataContainerIdentifierTails&&n.dataContainerIdentifierTails.length>0&&!s.endsWith(n.dataContainerIdentifierTails)){const r=_.get(e,s+n.dataContainerIdentifierTails);te(r)&&_.get(r,t)&&(i=_.get(r,t),o=!1)}if(void 0===i){const r=_.get(e,s);te(r)&&_.get(r,t)&&(i=_.get(r,t),o=!1)}}}if(void 0===i){const r=_.get(e,t);void 0!==r&&(i=r)}if(void 0===i)if(-1===t.indexOf(".")){const n=H(e,t);if(n.length>0)for(let e=0,s=n.length;e<s;e++){if(Y(n[e].val)||Z(n[e].val)||ee(n[e].val)){i=n[e].val;break}if("number"==typeof n[e].val){i=String(n[e].val);break}if(Array.isArray(n[e].val)){i=n[e].val.join("");break}throw new Error(`json-variables/findValues(): [THROW_ID_21] While trying to resolve: "${t}" at path "${r}", we actually found the key named ${t}, but it was not equal to a string but to:\n${JSON.stringify(n[e],null,4)}\nWe can't resolve a string with that! It should be a string.`)}}else{const r=H(e,function(e){if("string"==typeof e&&e.length>0&&-1!==e.indexOf("."))for(let t=0,r=e.length;t<r;t++)if("."===e[t])return e.slice(0,t);return e}(t));if(r.length>0)for(let e=0,n=r.length;e<n;e++){const n=_.get(r[e].val,ie(t));n&&Y(n)&&(i=n)}}return i}function fe(e,t,r,n,i=[]){if(i.includes(r)){let e="";if(i.length>1){const t=" →\n";e=i.reduce(((e,n,i)=>e+(0===i?"":t)+(n===r?"💥 ":" ")+n)," Here's the path we travelled up until we hit the recursion:\n\n"),e+=`${t}💥 ${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."${e}`)}const s={},o=Array.from(i);o.push(r);const a=new P;function l(i,l,u){for(let f=0,h=i.length;f<h;f++){const h=i[f],c=t.slice(h.headsEndAt,h.tailsStartAt);if(0===c.length)a.push(h.headsStartAt,h.tailsEndAt);else if(Q.call(s,c)&&Y(s[c]))a.push(h.headsStartAt,h.tailsEndAt,s[c]);else{let i=ue(e,c.trim(),r,n);if(void 0===i)if(!0===n.allowUnresolved)i="";else{if("string"!=typeof n.allowUnresolved)throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_18] We couldn't find the value to resolve the variable ${t.slice(h.headsEndAt,h.tailsStartAt)}. We're at path: "${r}".`);i=n.allowUnresolved}if(!u&&n.throwWhenNonStringInsertedInString&&!Y(i))throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_23] While resolving the variable ${t.slice(h.headsEndAt,h.tailsStartAt)} at path ${r}, it resolved into a non-string value, ${JSON.stringify(i,null,4)}. This is happening because options setting "throwWhenNonStringInsertedInString" is active (set to "true").`);if(Z(i)){if(n.resolveToBoolIfAnyValuesContainBool)return a.wipe(),!n.resolveToFalseIfAnyValuesContainBool&&i;i=""}else{if(ee(i)&&u)return a.wipe(),i;i=Array.isArray(i)?String(i.join("")):ee(i)?"":String(i)}const f=r.includes(".")?`${se(r)}.${c}`:c;if(ae(i,n)){const t=le(fe(e,i,f,n,o),n,l,0,0,c.trim());Y(t)&&a.push(h.headsStartAt,h.tailsEndAt,t)}else{s[c]=i;const e=le(i,n,l,0,0,c.trim());Y(e)&&a.push(h.headsStartAt,h.tailsEndAt,e)}}}}let u;try{u=N(t,n.heads,n.tails,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(e){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:\n${e}`)}let f=!1;1===u.length&&""===z(t,[[u[0].headsStartAt,u[0].tailsEndAt]]).trim()&&(f=!0);const h=l(u,!1,f);if(Z(h))return h;if(ee(h))return h;try{u=N(t,n.headsNoWrap,n.tailsNoWrap,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(e){throw new Error(`json-variables/resolveString(): [THROW_ID_22] While trying to resolve string: "${t}" at path ${r}, something wrong with no-wrap heads and no-wrap tails was detected! Here's the internal error message:\n${e}`)}1===u.length&&""===z(t,[[u[0].headsStartAt,u[0].tailsEndAt]]).trim()&&(f=!0);const c=l(u,!0,f);return Z(c)||ee(c)?c:a&&a.current()?z(t,a.current()):t}e.defaults=X,e.jVar=function(e,t){if(!arguments.length)throw new Error("json-variables/jVar(): [THROW_ID_01] Alas! Inputs are missing!");if(!te(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&&!te(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));const r={...X,...t};let n,i,s;if(r.dontWrapVars?Array.isArray(r.dontWrapVars)||(r.dontWrapVars=T(r.dontWrapVars)):r.dontWrapVars=[],r.dontWrapVars.length>0&&!r.dontWrapVars.every(((e,t)=>!!Y(e)||(n=e,i=t,!1))))throw new Error(`json-variables/jVar(): [THROW_ID_05] Alas! All variable names set in opts.dontWrapVars should be of a string type. Computer detected a value "${n}" at index ${i}, which is not string but ${Array.isArray(n)?"array":typeof n}!`);if(""===r.heads)throw new Error("json-variables/jVar(): [THROW_ID_06] Alas! opts.heads are empty!");if(""===r.tails)throw new Error("json-variables/jVar(): [THROW_ID_07] Alas! opts.tails are empty!");if(r.lookForDataContainers&&""===r.dataContainerIdentifierTails)throw new Error("json-variables/jVar(): [THROW_ID_08] Alas! opts.dataContainerIdentifierTails is empty!");if(r.heads===r.tails)throw new Error("json-variables/jVar(): [THROW_ID_09] Alas! opts.heads and opts.tails can't be equal!");if(r.heads===r.headsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_10] Alas! opts.heads and opts.headsNoWrap can't be equal!");if(r.tails===r.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_11] Alas! opts.tails and opts.tailsNoWrap can't be equal!");if(""===r.headsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_12] Alas! opts.headsNoWrap is an empty string!");if(""===r.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_13] Alas! opts.tailsNoWrap is an empty string!");if(r.headsNoWrap===r.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_14] Alas! opts.headsNoWrap and opts.tailsNoWrap can't be equal!");return p(e,((t,n,i)=>{if(re(n)&&ae(t,r))throw new Error(`json-variables/jVar(): [THROW_ID_15] Alas! Object keys can't contain variables!\nPlease check the following key: ${t}`);if(s=void 0!==n?n:t,""===s)return s;if(0!==r.heads.length&&ne(s)===ne(r.heads)||0!==r.tails.length&&ne(s)===ne(r.tails)||0!==r.headsNoWrap.length&&ne(s)===ne(r.headsNoWrap)||0!==r.tailsNoWrap.length&&ne(s)===ne(r.tailsNoWrap)){if(!r.noSingleMarkers)return s;throw new Error(`json-variables/jVar(): [THROW_ID_16] Alas! While processing the input, we stumbled upon ${ne(s)} which is equal to ${ne(s)===ne(r.heads)?"heads":""}${ne(s)===ne(r.tails)?"tails":""}${Y(r.headsNoWrap)&&ne(s)===ne(r.headsNoWrap)?"headsNoWrap":""}${Y(r.tailsNoWrap)&&ne(s)===ne(r.tailsNoWrap)?"tailsNoWrap":""}. If you wouldn't have set opts.noSingleMarkers to "true" this error would not happen and computer would have left the current element (${ne(s)}) alone`)}return Y(s)&&ae(s,r)?fe(e,s,i.path,r):s}))},e.version="11.0.3",Object.defineProperty(e,"__esModule",{value:!0})}));
114
+ */const Q=Object.prototype.hasOwnProperty,X={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 Y(e){return"string"==typeof e}function Z(e){return"boolean"==typeof e}function ee(e){return null===e}function te(e){return e&&"object"==typeof e&&!Array.isArray(e)}function re(e){return null!=e}function ne(e){return Y(e)?e.trim():e}function ie(e){if("string"==typeof e&&e.length>0&&-1!==e.indexOf("."))for(let t=0,r=e.length;t<r;t++)if("."===e[t])return e.slice(t+1);return e}function se(e){if("string"==typeof e&&e.length>0&&-1!==e.indexOf("."))for(let t=e.length;t--;)if("."===e[t])return e.slice(0,t);return e}function oe(e){if("string"==typeof e&&e.length>0&&-1!==e.indexOf("."))for(let t=e.length;t--;)if("."===e[t])return e.slice(t+1);return e}function ae(e,t){return!("string"!=typeof e||!e.trim())&&!!(e.includes(t.heads)||e.includes(t.tails)||Y(t.headsNoWrap)&&t.headsNoWrap.length>0&&e.includes(t.headsNoWrap)||Y(t.tailsNoWrap)&&t.tailsNoWrap.length>0&&e.includes(t.tailsNoWrap))}function le(e,t,r=!1,n,i,s){if(t.wrapHeadsWith||(t.wrapHeadsWith=""),t.wrapTailsWith||(t.wrapTailsWith=""),Y(e)&&!r&&t.wrapGlobalFlipSwitch&&!t.dontWrapVars.some((e=>w(s,e)))&&(!t.preventDoubleWrapping||t.preventDoubleWrapping&&Y(e)&&!e.includes(t.wrapHeadsWith)&&!e.includes(t.wrapTailsWith)))return t.wrapHeadsWith+e+t.wrapTailsWith;if(r){if(!Y(e))return e;const r=function(e,t){const r=Object.prototype.hasOwnProperty;if(void 0===e)throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_01] The input is missing!");if("string"!=typeof e)return e;if(t&&!c(t))throw new Error(`string-remove-duplicate-heads-tails: [THROW_ID_03] The given options are not a plain object but ${typeof t}!`);const n={...t};if(n&&r.call(n,"heads")){if(!T(n.heads).every((e=>"string"==typeof e||Array.isArray(e))))throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_04] The opts.heads contains elements which are not string-type!");"string"==typeof n.heads&&(n.heads=T(n.heads))}if(n&&r.call(n,"tails")){if(!T(n.tails).every((e=>"string"==typeof e||Array.isArray(e))))throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_05] The opts.tails contains elements which are not string-type!");"string"==typeof n.tails&&(n.tails=T(n.tails))}const i=K(e).res;if(0===i.length)return e;e=i;const s={heads:["{{"],tails:["}}"],...n};s.heads=s.heads.map((e=>e.trim())),s.tails=s.tails.map((e=>e.trim()));let o=!1,a=!1;const l=new P({limitToBeAddedWhitespace:!0}),u=new P({limitToBeAddedWhitespace:!0});let f=!0,h=!0,g="";function p(e,t){let r;return E(e,0,t.heads,{trimBeforeMatching:!0,cb:(e,t,n)=>(r=n,!0)})&&E(e,r,t.tails,{trimBeforeMatching:!0,cb:(e,t,n)=>(r=n,!0)})?e.slice(r):e}for(;e!==p(e,s);)e=K(p(e,s)).res;function y(e,t){let r;return j(e,e.length-1,t.tails,{trimBeforeMatching:!0,cb:(e,t,n)=>(r=n,!0)})&&r&&j(e,r,t.heads,{trimBeforeMatching:!0,cb:(e,t,n)=>(r=n,!0)})?e.slice(0,r+1):e}for(;e!==y(e,s);)e=K(y(e,s)).res;if(!(s.heads.length&&E(e,0,s.heads,{trimBeforeMatching:!0})&&s.tails.length&&j(e,e.length-1,s.tails,{trimBeforeMatching:!0})))return K(e).res;for(let t=0,r=e.length;t<r;t++)if(""===e[t].trim());else{let r;if(E(e,t,s.heads,{trimBeforeMatching:!0,cb:(e,t,n)=>(r=n,!0)})&&r){let n;h=!0,f&&(f=!0),E(e,r,s.tails,{trimBeforeMatching:!0,cb:(e,t,r)=>(n=r,!0)})&&l.push(t,n),u.current()&&o&&"tails"!==g&&l.push(u.current()),o||u.current()&&(l.push(u.current()),u.wipe()),u.push(t,r),g="heads",t=r-1;continue}if(E(e,t,s.tails,{trimBeforeMatching:!0,cb:(t,n,i)=>(r=Number.isInteger(i)?i:e.length,!0)})&&r){h=!0,f?("heads"===g&&u.wipe(),f=!1):u.push(t,r),g="tails",t=r-1;continue}f&&(f=!0),h&&!o?(o=!0,h=!1):h&&!a?(a=!0,f=!0,h=!1,"heads"===g&&u.wipe()):h&&a&&u.wipe()}return u.current()&&l.push(u.current()),l.current()?z(e,l.current()).trim():e.trim()}(e,{heads:t.wrapHeadsWith,tails:t.wrapTailsWith});return Y(r)?function(e,t,r){let n,i;return"string"==typeof e&&e.length>0&&E(e,0,t,{trimBeforeMatching:!0,cb:(e,t,r)=>(n=r,!0)})&&j(e,e.length-1,r,{trimBeforeMatching:!0,cb:(e,t,r)=>(i=r+1,!0)})?e.slice(n,i):e}(r,t.wrapHeadsWith,t.wrapTailsWith):r}return e}function ue(e,t,r,n){let i;if(-1!==r.indexOf(".")){let s=r,o=!0;if(n.lookForDataContainers&&"string"==typeof n.dataContainerIdentifierTails&&n.dataContainerIdentifierTails.length>0&&!s.endsWith(n.dataContainerIdentifierTails)){const r=_.get(e,s+n.dataContainerIdentifierTails);te(r)&&_.get(r,t)&&(i=_.get(r,t),o=!1)}for(;o&&-1!==s.indexOf(".");){if(s=se(s),oe(s)===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 "${oe(s)}" is called the same as the variable "${t}" we're looking for.`);if(n.lookForDataContainers&&"string"==typeof n.dataContainerIdentifierTails&&n.dataContainerIdentifierTails.length>0&&!s.endsWith(n.dataContainerIdentifierTails)){const r=_.get(e,s+n.dataContainerIdentifierTails);te(r)&&_.get(r,t)&&(i=_.get(r,t),o=!1)}if(void 0===i){const r=_.get(e,s);te(r)&&_.get(r,t)&&(i=_.get(r,t),o=!1)}}}if(void 0===i){const r=_.get(e,t);void 0!==r&&(i=r)}if(void 0===i)if(-1===t.indexOf(".")){const n=H(e,t);if(n.length>0)for(let e=0,s=n.length;e<s;e++){if(Y(n[e].val)||Z(n[e].val)||ee(n[e].val)){i=n[e].val;break}if("number"==typeof n[e].val){i=String(n[e].val);break}if(Array.isArray(n[e].val)){i=n[e].val.join("");break}throw new Error(`json-variables/findValues(): [THROW_ID_21] While trying to resolve: "${t}" at path "${r}", we actually found the key named ${t}, but it was not equal to a string but to:\n${JSON.stringify(n[e],null,4)}\nWe can't resolve a string with that! It should be a string.`)}}else{const r=H(e,function(e){if("string"==typeof e&&e.length>0&&-1!==e.indexOf("."))for(let t=0,r=e.length;t<r;t++)if("."===e[t])return e.slice(0,t);return e}(t));if(r.length>0)for(let e=0,n=r.length;e<n;e++){const n=_.get(r[e].val,ie(t));n&&Y(n)&&(i=n)}}return i}function fe(e,t,r,n,i=[]){if(i.includes(r)){let e="";if(i.length>1){const t=" →\n";e=i.reduce(((e,n,i)=>e+(0===i?"":t)+(n===r?"💥 ":" ")+n)," Here's the path we travelled up until we hit the recursion:\n\n"),e+=`${t}💥 ${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."${e}`)}const s={},o=Array.from(i);o.push(r);const a=new P;function l(i,l,u){for(let f=0,h=i.length;f<h;f++){const h=i[f],c=t.slice(h.headsEndAt,h.tailsStartAt);if(0===c.length)a.push(h.headsStartAt,h.tailsEndAt);else if(Q.call(s,c)&&Y(s[c]))a.push(h.headsStartAt,h.tailsEndAt,s[c]);else{let i=ue(e,c.trim(),r,n);if(void 0===i)if(!0===n.allowUnresolved)i="";else{if("string"!=typeof n.allowUnresolved)throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_18] We couldn't find the value to resolve the variable ${t.slice(h.headsEndAt,h.tailsStartAt)}. We're at path: "${r}".`);i=n.allowUnresolved}if(!u&&n.throwWhenNonStringInsertedInString&&!Y(i))throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_23] While resolving the variable ${t.slice(h.headsEndAt,h.tailsStartAt)} at path ${r}, it resolved into a non-string value, ${JSON.stringify(i,null,4)}. This is happening because options setting "throwWhenNonStringInsertedInString" is active (set to "true").`);if(Z(i)){if(n.resolveToBoolIfAnyValuesContainBool)return a.wipe(),!n.resolveToFalseIfAnyValuesContainBool&&i;i=""}else{if(ee(i)&&u)return a.wipe(),i;i=Array.isArray(i)?String(i.join("")):ee(i)?"":String(i)}const f=r.includes(".")?`${se(r)}.${c}`:c;if(ae(i,n)){const t=le(fe(e,i,f,n,o),n,l,0,0,c.trim());Y(t)&&a.push(h.headsStartAt,h.tailsEndAt,t)}else{s[c]=i;const e=le(i,n,l,0,0,c.trim());Y(e)&&a.push(h.headsStartAt,h.tailsEndAt,e)}}}}let u;try{u=N(t,n.heads,n.tails,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(e){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:\n${e}`)}let f=!1;1===u.length&&""===z(t,[[u[0].headsStartAt,u[0].tailsEndAt]]).trim()&&(f=!0);const h=l(u,!1,f);if(Z(h))return h;if(ee(h))return h;try{u=N(t,n.headsNoWrap,n.tailsNoWrap,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(e){throw new Error(`json-variables/resolveString(): [THROW_ID_22] While trying to resolve string: "${t}" at path ${r}, something wrong with no-wrap heads and no-wrap tails was detected! Here's the internal error message:\n${e}`)}1===u.length&&""===z(t,[[u[0].headsStartAt,u[0].tailsEndAt]]).trim()&&(f=!0);const c=l(u,!0,f);return Z(c)||ee(c)?c:a&&a.current()?z(t,a.current()):t}e.defaults=X,e.jVar=function(e,t){if(!arguments.length)throw new Error("json-variables/jVar(): [THROW_ID_01] Alas! Inputs are missing!");if(!te(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&&!te(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));const r={...X,...t};let n,i,s;if(r.dontWrapVars?Array.isArray(r.dontWrapVars)||(r.dontWrapVars=T(r.dontWrapVars)):r.dontWrapVars=[],r.dontWrapVars.length>0&&!r.dontWrapVars.every(((e,t)=>!!Y(e)||(n=e,i=t,!1))))throw new Error(`json-variables/jVar(): [THROW_ID_05] Alas! All variable names set in opts.dontWrapVars should be of a string type. Computer detected a value "${n}" at index ${i}, which is not string but ${Array.isArray(n)?"array":typeof n}!`);if(""===r.heads)throw new Error("json-variables/jVar(): [THROW_ID_06] Alas! opts.heads are empty!");if(""===r.tails)throw new Error("json-variables/jVar(): [THROW_ID_07] Alas! opts.tails are empty!");if(r.lookForDataContainers&&""===r.dataContainerIdentifierTails)throw new Error("json-variables/jVar(): [THROW_ID_08] Alas! opts.dataContainerIdentifierTails is empty!");if(r.heads===r.tails)throw new Error("json-variables/jVar(): [THROW_ID_09] Alas! opts.heads and opts.tails can't be equal!");if(r.heads===r.headsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_10] Alas! opts.heads and opts.headsNoWrap can't be equal!");if(r.tails===r.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_11] Alas! opts.tails and opts.tailsNoWrap can't be equal!");if(""===r.headsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_12] Alas! opts.headsNoWrap is an empty string!");if(""===r.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_13] Alas! opts.tailsNoWrap is an empty string!");if(r.headsNoWrap===r.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_14] Alas! opts.headsNoWrap and opts.tailsNoWrap can't be equal!");return p(e,((t,n,i)=>{if(re(n)&&ae(t,r))throw new Error(`json-variables/jVar(): [THROW_ID_15] Alas! Object keys can't contain variables!\nPlease check the following key: ${t}`);if(s=void 0!==n?n:t,""===s)return s;if(0!==r.heads.length&&ne(s)===ne(r.heads)||0!==r.tails.length&&ne(s)===ne(r.tails)||0!==r.headsNoWrap.length&&ne(s)===ne(r.headsNoWrap)||0!==r.tailsNoWrap.length&&ne(s)===ne(r.tailsNoWrap)){if(!r.noSingleMarkers)return s;throw new Error(`json-variables/jVar(): [THROW_ID_16] Alas! While processing the input, we stumbled upon ${ne(s)} which is equal to ${ne(s)===ne(r.heads)?"heads":""}${ne(s)===ne(r.tails)?"tails":""}${Y(r.headsNoWrap)&&ne(s)===ne(r.headsNoWrap)?"headsNoWrap":""}${Y(r.tailsNoWrap)&&ne(s)===ne(r.tailsNoWrap)?"tailsNoWrap":""}. If you wouldn't have set opts.noSingleMarkers to "true" this error would not happen and computer would have left the current element (${ne(s)}) alone`)}return Y(s)&&ae(s,r)?fe(e,s,i.path,r):s}))},e.version="11.0.4",Object.defineProperty(e,"__esModule",{value:!0})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-variables",
3
- "version": "11.0.3",
3
+ "version": "11.0.4",
4
4
  "description": "Resolves custom-marked, cross-referenced paths in parsed JSON",
5
5
  "keywords": [
6
6
  "comb",
@@ -87,16 +87,16 @@
87
87
  },
88
88
  "dependencies": {
89
89
  "@babel/runtime": "^7.16.0",
90
- "arrayiffy-if-string": "^4.0.3",
91
- "ast-get-values-by-key": "^4.0.3",
92
- "ast-monkey-traverse": "^3.0.3",
90
+ "arrayiffy-if-string": "^4.0.4",
91
+ "ast-get-values-by-key": "^4.0.4",
92
+ "ast-monkey-traverse": "^3.0.4",
93
93
  "matcher": "^5.0.0",
94
94
  "object-path": "^0.11.8",
95
- "ranges-apply": "^6.0.3",
96
- "ranges-push": "^6.0.3",
97
- "string-find-heads-tails": "^5.0.3",
98
- "string-match-left-right": "^8.0.3",
99
- "string-remove-duplicate-heads-tails": "^6.0.3"
95
+ "ranges-apply": "^6.0.4",
96
+ "ranges-push": "^6.0.4",
97
+ "string-find-heads-tails": "^5.0.4",
98
+ "string-match-left-right": "^8.0.4",
99
+ "string-remove-duplicate-heads-tails": "^6.0.4"
100
100
  },
101
101
  "devDependencies": {
102
102
  "@babel/cli": "^7.16.0",
@@ -120,12 +120,12 @@
120
120
  "@rollup/plugin-typescript": "^8.3.0",
121
121
  "@types/node": "^16.11.6",
122
122
  "@types/tap": "^15.0.5",
123
- "@typescript-eslint/eslint-plugin": "^5.2.0",
124
- "@typescript-eslint/parser": "^5.2.0",
125
- "core-js": "^3.19.0",
123
+ "@typescript-eslint/eslint-plugin": "^5.3.0",
124
+ "@typescript-eslint/parser": "^5.3.0",
125
+ "core-js": "^3.19.1",
126
126
  "cross-env": "^7.0.3",
127
127
  "eslint": "^8.1.0",
128
- "lect": "^0.18.3",
128
+ "lect": "^0.18.4",
129
129
  "rollup": "^2.59.0",
130
130
  "rollup-plugin-ascii": "^0.0.3",
131
131
  "rollup-plugin-banner": "^0.2.1",