json-variables 11.1.7 → 11.1.8

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/CHANGELOG.md CHANGED
@@ -79,29 +79,29 @@ Accidental version bump during migration to sourcehut. Sorry about that.
79
79
 
80
80
  ## 7.7.0 (2019-01-20)
81
81
 
82
- - Various documentation and setup tweaks after we migrated to monorepo
83
- - Setup refresh: updated dependencies and all config files using automated tools
82
+ - Various documentation and setup tweaks after we migrated to monorepo
83
+ - Setup refresh: updated dependencies and all config files using automated tools
84
84
 
85
85
  ## 7.5.0 (2018-10-28)
86
86
 
87
- - Updated all dependencies
88
- - Restored unit test coverage tracking: reporting in terminal and coveralls.io
89
- - Restored unit test linting
87
+ - Updated all dependencies
88
+ - Restored unit test coverage tracking: reporting in terminal and coveralls.io
89
+ - Restored unit test linting
90
90
 
91
91
  ## 7.4.0 (2018-06-20)
92
92
 
93
- - Two `range-` dependencies have been renamed, namely [ranges-push](https://www.npmjs.com/package/ranges-push) and [ranges-apply](https://www.npmjs.com/package/ranges-apply). We tapped them.
93
+ - Two `range-` dependencies have been renamed, namely [ranges-push](https://www.npmjs.com/package/ranges-push) and [ranges-apply](https://www.npmjs.com/package/ranges-apply). We tapped them.
94
94
 
95
95
  ## 7.3.0 (2018-06-10)
96
96
 
97
- - Migrated to BitBucket (to host repo + perform CI) and Codacy (for code quality audit)
98
- - Dropped BitHound (RIP) and Travis
99
- - Remove `package-lock`
97
+ - Migrated to BitBucket (to host repo + perform CI) and Codacy (for code quality audit)
98
+ - Dropped BitHound (RIP) and Travis
99
+ - Remove `package-lock`
100
100
 
101
101
  ## 7.2.0 (2018-03-28)
102
102
 
103
- - Fixed one edge case where variables were resolving to non-strings and error was thrown.
104
- - Set up prettier and removed `.editorconfig`.
103
+ - Fixed one edge case where variables were resolving to non-strings and error was thrown.
104
+ - Set up prettier and removed `.editorconfig`.
105
105
 
106
106
  ## 7.1.2 (2018-03-06)
107
107
 
@@ -109,16 +109,16 @@ Accidental version bump during migration to sourcehut. Sorry about that.
109
109
 
110
110
  ## 7.1.0 (2018-02-16)
111
111
 
112
- - Updated all dependencies.
113
- - Fixed some edge-cases where variables could have been wrapped where they shouldn't have been wrapped and the opposite.
112
+ - Updated all dependencies.
113
+ - Fixed some edge-cases where variables could have been wrapped where they shouldn't have been wrapped and the opposite.
114
114
 
115
115
  ## 7.0.0 (2018-02-14)
116
116
 
117
- - Full rewrite. Same and more unit tests.
118
- - Variables now can be fetched from the parent nodes, all the way up until root. Priority order: 1. key with variable's name at the same level; 2. data store at same level; 3. key with variable's name at parent node's level; 4. data store at parent's level ... and so on, until root is reached.
119
- - Now the program will pretty much never throw. If you feed incomplete heads or tails, it will leave them unouched rather than throw an error about them. I'll implement strict mode later.
120
- - Way leaner and efficient algorithm and dependencies' choice.
121
- - Added more unit tests too.
117
+ - Full rewrite. Same and more unit tests.
118
+ - Variables now can be fetched from the parent nodes, all the way up until root. Priority order: 1. key with variable's name at the same level; 2. data store at same level; 3. key with variable's name at parent node's level; 4. data store at parent's level ... and so on, until root is reached.
119
+ - Now the program will pretty much never throw. If you feed incomplete heads or tails, it will leave them unouched rather than throw an error about them. I'll implement strict mode later.
120
+ - Way leaner and efficient algorithm and dependencies' choice.
121
+ - Added more unit tests too.
122
122
 
123
123
  ## 6.0.0 (2018-01-02)
124
124
 
@@ -132,38 +132,38 @@ Accidental version bump during migration to sourcehut. Sorry about that.
132
132
 
133
133
  ### Improved
134
134
 
135
- - Improved _head_ and _tail_ detection algorithm. Previously we used simple string search, without considering the order of the findings. Wrong order now will help to rule-out more false positives.
136
- - Tapped [ast-monkey-traverse](https://www.npmjs.com/package/ast-monkey-traverse) directly, without the need for the whole [ast-monkey](https://www.npmjs.com/package/ast-monkey).
137
- - Many other improvements on the setup
135
+ - Improved _head_ and _tail_ detection algorithm. Previously we used simple string search, without considering the order of the findings. Wrong order now will help to rule-out more false positives.
136
+ - Tapped [ast-monkey-traverse](https://www.npmjs.com/package/ast-monkey-traverse) directly, without the need for the whole [ast-monkey](https://www.npmjs.com/package/ast-monkey).
137
+ - Many other improvements on the setup
138
138
 
139
139
  ## 5.0.0 (2017-12-15)
140
140
 
141
- - Rebased in ES Modules
142
- - Set up Rollup to generate three builds: CommonJS, UMD and ES Modules
143
- - Dropped JS Standard and tapped raw ESLint on `airbnb-base` preset, with an override to ban semicolons
141
+ - Rebased in ES Modules
142
+ - Set up Rollup to generate three builds: CommonJS, UMD and ES Modules
143
+ - Dropped JS Standard and tapped raw ESLint on `airbnb-base` preset, with an override to ban semicolons
144
144
 
145
145
  ## 4.6.0 (2017-07-29)
146
146
 
147
- - Replaced `object-assign` with ES6 `Object.assign`
147
+ - Replaced `object-assign` with ES6 `Object.assign`
148
148
 
149
149
  ## 4.5.0 (2017-05-23)
150
150
 
151
- - Separated the `arrayiffy-if-string` into a standalone library and tapped it.
151
+ - Separated the `arrayiffy-if-string` into a standalone library and tapped it.
152
152
 
153
153
  ## 4.4.0 (2017-05-20)
154
154
 
155
- - Updated all deps
156
- - Updated Codsen name
155
+ - Updated all deps
156
+ - Updated Codsen name
157
157
 
158
158
  ## 4.3.0 (2017-05-15)
159
159
 
160
- - Switched to [check-types-mini](https://www.npmjs.com/package/check-types-mini) and removed internal equivalents.
160
+ - Switched to [check-types-mini](https://www.npmjs.com/package/check-types-mini) and removed internal equivalents.
161
161
 
162
162
  ## 4.2.0 (2017-05-05)
163
163
 
164
- - `opts.resolveToFalseIfAnyValuesContainBool` (on by default)
165
- - `opts.throwWhenNonStringInsertedInString` (off by default)
166
- - Now allowing to query deeper-level values. For example:
164
+ - `opts.resolveToFalseIfAnyValuesContainBool` (on by default)
165
+ - `opts.throwWhenNonStringInsertedInString` (off by default)
166
+ - Now allowing to query deeper-level values. For example:
167
167
 
168
168
  ```js
169
169
  jv({
@@ -184,27 +184,27 @@ Accidental version bump during migration to sourcehut. Sorry about that.
184
184
  // }
185
185
  ```
186
186
 
187
- - Obviously, the new changes above threw the `opts.dontWrapVars` out of track a little bit since instead of `key` now we've possibly got `key.key[element.key]`, so I fixed that too and added more unit tests.
187
+ - Obviously, the new changes above threw the `opts.dontWrapVars` out of track a little bit since instead of `key` now we've possibly got `key.key[element.key]`, so I fixed that too and added more unit tests.
188
188
 
189
189
  Blimey, we've got 99 unit tests! 🍾 We'll need to celebrate the 100th! 🍻✨
190
190
 
191
191
  ## 4.1.0 (2017-05-03)
192
192
 
193
- - Variables are not correctly resolved from linking to the same (deeper) level. If not found, search continues in that level's data store key (default key name for data stores is `<same-key-name>_data`). If not found there, search jumps to root level, and looks for key there. If not found, search continues for data store at the root. If failed, error is thrown.
194
- - Some rebasing done to clean things up 🚿.
193
+ - Variables are not correctly resolved from linking to the same (deeper) level. If not found, search continues in that level's data store key (default key name for data stores is `<same-key-name>_data`). If not found there, search jumps to root level, and looks for key there. If not found, search continues for data store at the root. If failed, error is thrown.
194
+ - Some rebasing done to clean things up 🚿.
195
195
 
196
196
  ## 4.0.0 (2017-04-30)
197
197
 
198
198
  Breaking changes in the API, or rather output. When Boolean values are encountered and written as values (and no other string characters are present on the original placeholder), we output empty string, not `false` or `true`. Nobody needs Booleans converted to String. I need this for my email templating projects. 🦄
199
199
 
200
- - JSON specs allow various kinds of types to be placed as key values: Booleans, arrays, plain objects and even `null`. In this release we loosen the restrictions and allow these different types to be resolved as values, particularly, `null` and Booleans.
200
+ - JSON specs allow various kinds of types to be placed as key values: Booleans, arrays, plain objects and even `null`. In this release we loosen the restrictions and allow these different types to be resolved as values, particularly, `null` and Booleans.
201
201
 
202
- - Added `opts.resolveToBoolIfAnyValuesContainBool` - if `true` (default), if any variable's value is Boolean, upon resolving it will set the whole value to itself. For example, `aaaa %%_var_%% bbbbb` and `var=true` would resolve to `true`. If setting is `false`, it will resolve to empty string, in this example's case, `aaaa bbbbb`. I don't see why anybody would set it to other value than `default`, but hey, the more freedom the better.
203
- - `opts.resolveToFalseIfAnyValuesContainBool` - if Boolean variable is enountered, the whole thing always resolves to `false`. Even if the first encountered variable's value was `true`. This is needed for email templating, so that when Booleans are encountered, we bail setting the whole thing to `false`.
202
+ - Added `opts.resolveToBoolIfAnyValuesContainBool` - if `true` (default), if any variable's value is Boolean, upon resolving it will set the whole value to itself. For example, `aaaa %%_var_%% bbbbb` and `var=true` would resolve to `true`. If setting is `false`, it will resolve to empty string, in this example's case, `aaaa bbbbb`. I don't see why anybody would set it to other value than `default`, but hey, the more freedom the better.
203
+ - `opts.resolveToFalseIfAnyValuesContainBool` - if Boolean variable is enountered, the whole thing always resolves to `false`. Even if the first encountered variable's value was `true`. This is needed for email templating, so that when Booleans are encountered, we bail setting the whole thing to `false`.
204
204
 
205
205
  ## 3.0.0 (2017-04-27)
206
206
 
207
- - `opts.headsNoWrap` (default `%%-`) & `opts.tailsNoWrap` (default `-%%`). When the same string has multiple occasions of a variable and we want some variables to be wrapped but some not it was previously impossible. Wrapping ignores were global. Now not. I came with an idea to allow different (customiseable) `heads` and `tails` which prevent wrapping on the variable it marks.
207
+ - `opts.headsNoWrap` (default `%%-`) & `opts.tailsNoWrap` (default `-%%`). When the same string has multiple occasions of a variable and we want some variables to be wrapped but some not it was previously impossible. Wrapping ignores were global. Now not. I came with an idea to allow different (customiseable) `heads` and `tails` which prevent wrapping on the variable it marks.
208
208
  - 💥 `opts.wrapHeads` is now `opts.wrapHeadsWith`
209
209
  - 💥 `opts.wrapTails` is now `opts.wrapTailsWith`
210
210
 
@@ -214,14 +214,14 @@ Breaking changes in the API, or rather output. When Boolean values are encounter
214
214
 
215
215
  ## 1.2.0 (2017-04-20)
216
216
 
217
- - If any key's value contains only a heads or tails marker and nothing else, it will not throw. You can force throwing (that's previous version's behaviour) setting `opts.noSingleMarkers` to `true`. But the default is `false`.
218
- - Did some code rebasing.
217
+ - If any key's value contains only a heads or tails marker and nothing else, it will not throw. You can force throwing (that's previous version's behaviour) setting `opts.noSingleMarkers` to `true`. But the default is `false`.
218
+ - Did some code rebasing.
219
219
 
220
220
  ## 1.1.0 (2017-04-06)
221
221
 
222
- - Fixed one edge case where the source was array, it was querying variable from `_data` key store, which was in turn querying variable from its key data store.
223
- - More tests to keep coverage at 100%
222
+ - Fixed one edge case where the source was array, it was querying variable from `_data` key store, which was in turn querying variable from its key data store.
223
+ - More tests to keep coverage at 100%
224
224
 
225
225
  ## 1.0.0 (2017-03-28)
226
226
 
227
- - First public release
227
+ - First public release
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * @name json-variables
3
3
  * @fileoverview Resolves custom-marked, cross-referenced paths in parsed JSON
4
- * @version 11.1.7
4
+ * @version 11.1.8
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/json-variables/}
8
8
  */
9
9
 
10
- import{traverse as C}from"ast-monkey-traverse";import{isMatch as x}from"matcher";import h from"object-path";import{arrayiffy as F}from"arrayiffy-if-string";import{strFindHeadsTails as I}from"string-find-heads-tails";import{getByKey as _}from"ast-get-values-by-key";import{Ranges as B}from"ranges-push";import{rApply as A}from"ranges-apply";import{remDup as L}from"string-remove-duplicate-heads-tails";import{matchLeftIncl as U,matchRightIncl as M}from"string-match-left-right";var j="11.1.7";var he=j,q=Object.prototype.hasOwnProperty,K={heads:"%%_",tails:"_%%",headsNoWrap:"%%-",tailsNoWrap:"-%%",lookForDataContainers:!0,dataContainerIdentifierTails:"_data",wrapHeadsWith:"",wrapTailsWith:"",dontWrapVars:[],preventDoubleWrapping:!0,wrapGlobalFlipSwitch:!0,noSingleMarkers:!1,resolveToBoolIfAnyValuesContainBool:!0,resolveToFalseIfAnyValuesContainBool:!0,throwWhenNonStringInsertedInString:!1,allowUnresolved:!1};function g(e){return typeof e=="string"}function G(e){return typeof e=="number"}function O(e){return typeof e=="boolean"}function N(e){return e===null}function V(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function z(e){return e!=null}function u(e){return g(e)?e.trim():e}function Y(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let t=0,r=e.length;t<r;t++)if(e[t]===".")return e.slice(0,t)}return e}function Q(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let t=0,r=e.length;t<r;t++)if(e[t]===".")return e.slice(t+1)}return e}function J(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let t=e.length;t--;)if(e[t]===".")return e.slice(0,t)}return e}function P(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let t=e.length;t--;)if(e[t]===".")return e.slice(t+1)}return e}function T(e,t){return typeof e!="string"||!e.trim()?!1:!!(e.includes(t.heads)||e.includes(t.tails)||g(t.headsNoWrap)&&t.headsNoWrap.length&&e.includes(t.headsNoWrap)||g(t.tailsNoWrap)&&t.tailsNoWrap.length&&e.includes(t.tailsNoWrap))}function X(e,t,r){let o,i;return typeof e=="string"&&e.length&&M(e,0,t,{trimBeforeMatching:!0,cb:(n,a,l)=>(o=l,!0)})&&U(e,e.length-1,r,{trimBeforeMatching:!0,cb:(n,a,l)=>(i=(l||0)+1,!0)})?e.slice(o,i):e}function H(e,t,r=!1,o,i,n){if(t.wrapHeadsWith||(t.wrapHeadsWith=""),t.wrapTailsWith||(t.wrapTailsWith=""),g(e)&&!r&&t.wrapGlobalFlipSwitch&&!t.dontWrapVars.some(a=>x(n,a))&&(!t.preventDoubleWrapping||t.preventDoubleWrapping&&g(e)&&!e.includes(t.wrapHeadsWith)&&!e.includes(t.wrapTailsWith)))return`${t.wrapHeadsWith}${e}${t.wrapTailsWith}`;if(r){if(!g(e))return e;let a=L(e,{heads:t.wrapHeadsWith,tails:t.wrapTailsWith});return g(a)?X(a,t.wrapHeadsWith,t.wrapTailsWith):a}return e}function Z(e,t,r,o){let i;if(r.indexOf(".")!==-1){let n=r,a=!0;if(o.lookForDataContainers&&typeof o.dataContainerIdentifierTails=="string"&&o.dataContainerIdentifierTails.length&&!n.endsWith(o.dataContainerIdentifierTails)){let l=h.get(e,n+o.dataContainerIdentifierTails);V(l)&&h.get(l,t)&&(i=h.get(l,t),a=!1)}for(;a&&n.indexOf(".")!==-1;){if(n=J(n),P(n)===t)throw new Error(`json-variables/findValues(): [THROW_ID_20] While trying to resolve: "${t}" at path "${r}", we encountered a closed loop. The parent key "${P(n)}" is called the same as the variable "${t}" we're looking for.`);if(o.lookForDataContainers&&typeof o.dataContainerIdentifierTails=="string"&&o.dataContainerIdentifierTails.length&&!n.endsWith(o.dataContainerIdentifierTails)){let l=h.get(e,n+o.dataContainerIdentifierTails);V(l)&&h.get(l,t)&&(i=h.get(l,t),a=!1)}if(i===void 0){let l=h.get(e,n);V(l)&&h.get(l,t)&&(i=h.get(l,t),a=!1)}}}if(i===void 0){let n=h.get(e,t);n!==void 0&&(i=n)}if(i===void 0)if(t.indexOf(".")===-1){let n=_(e,t);if(n.length){for(let a=0,l=n.length;a<l;a++)if(g(n[a].val)||O(n[a].val)||N(n[a].val)){i=n[a].val;break}else if(G(n[a].val)){i=String(n[a].val);break}else if(Array.isArray(n[a].val)){i=n[a].val.join("");break}}}else{let n=_(e,Y(t));if(n.length)for(let a=0,l=n.length;a<l;a++){let y=h.get(n[a].val,Q(t));y&&g(y)&&(i=y)}}return i}function R(e,t,r,o,i=[]){if(i.includes(r)){let c="";if(i.length>1){let w=` \u2192
10
+ import{traverse as C}from"ast-monkey-traverse";import{isMatch as x}from"matcher";import h from"object-path";import{arrayiffy as F}from"arrayiffy-if-string";import{strFindHeadsTails as I}from"string-find-heads-tails";import{getByKey as _}from"ast-get-values-by-key";import{Ranges as B}from"ranges-push";import{rApply as A}from"ranges-apply";import{remDup as L}from"string-remove-duplicate-heads-tails";import{matchLeftIncl as U,matchRightIncl as M}from"string-match-left-right";var j="11.1.8";var he=j,q=Object.prototype.hasOwnProperty,K={heads:"%%_",tails:"_%%",headsNoWrap:"%%-",tailsNoWrap:"-%%",lookForDataContainers:!0,dataContainerIdentifierTails:"_data",wrapHeadsWith:"",wrapTailsWith:"",dontWrapVars:[],preventDoubleWrapping:!0,wrapGlobalFlipSwitch:!0,noSingleMarkers:!1,resolveToBoolIfAnyValuesContainBool:!0,resolveToFalseIfAnyValuesContainBool:!0,throwWhenNonStringInsertedInString:!1,allowUnresolved:!1};function g(e){return typeof e=="string"}function G(e){return typeof e=="number"}function O(e){return typeof e=="boolean"}function N(e){return e===null}function V(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function z(e){return e!=null}function u(e){return g(e)?e.trim():e}function Y(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let t=0,r=e.length;t<r;t++)if(e[t]===".")return e.slice(0,t)}return e}function Q(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let t=0,r=e.length;t<r;t++)if(e[t]===".")return e.slice(t+1)}return e}function J(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let t=e.length;t--;)if(e[t]===".")return e.slice(0,t)}return e}function P(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let t=e.length;t--;)if(e[t]===".")return e.slice(t+1)}return e}function T(e,t){return typeof e!="string"||!e.trim()?!1:!!(e.includes(t.heads)||e.includes(t.tails)||g(t.headsNoWrap)&&t.headsNoWrap.length&&e.includes(t.headsNoWrap)||g(t.tailsNoWrap)&&t.tailsNoWrap.length&&e.includes(t.tailsNoWrap))}function X(e,t,r){let o,i;return typeof e=="string"&&e.length&&M(e,0,t,{trimBeforeMatching:!0,cb:(n,a,l)=>(o=l,!0)})&&U(e,e.length-1,r,{trimBeforeMatching:!0,cb:(n,a,l)=>(i=(l||0)+1,!0)})?e.slice(o,i):e}function H(e,t,r=!1,o,i,n){if(t.wrapHeadsWith||(t.wrapHeadsWith=""),t.wrapTailsWith||(t.wrapTailsWith=""),g(e)&&!r&&t.wrapGlobalFlipSwitch&&!t.dontWrapVars.some(a=>x(n,a))&&(!t.preventDoubleWrapping||t.preventDoubleWrapping&&g(e)&&!e.includes(t.wrapHeadsWith)&&!e.includes(t.wrapTailsWith)))return`${t.wrapHeadsWith}${e}${t.wrapTailsWith}`;if(r){if(!g(e))return e;let a=L(e,{heads:t.wrapHeadsWith,tails:t.wrapTailsWith});return g(a)?X(a,t.wrapHeadsWith,t.wrapTailsWith):a}return e}function Z(e,t,r,o){let i;if(r.indexOf(".")!==-1){let n=r,a=!0;if(o.lookForDataContainers&&typeof o.dataContainerIdentifierTails=="string"&&o.dataContainerIdentifierTails.length&&!n.endsWith(o.dataContainerIdentifierTails)){let l=h.get(e,n+o.dataContainerIdentifierTails);V(l)&&h.get(l,t)&&(i=h.get(l,t),a=!1)}for(;a&&n.indexOf(".")!==-1;){if(n=J(n),P(n)===t)throw new Error(`json-variables/findValues(): [THROW_ID_20] While trying to resolve: "${t}" at path "${r}", we encountered a closed loop. The parent key "${P(n)}" is called the same as the variable "${t}" we're looking for.`);if(o.lookForDataContainers&&typeof o.dataContainerIdentifierTails=="string"&&o.dataContainerIdentifierTails.length&&!n.endsWith(o.dataContainerIdentifierTails)){let l=h.get(e,n+o.dataContainerIdentifierTails);V(l)&&h.get(l,t)&&(i=h.get(l,t),a=!1)}if(i===void 0){let l=h.get(e,n);V(l)&&h.get(l,t)&&(i=h.get(l,t),a=!1)}}}if(i===void 0){let n=h.get(e,t);n!==void 0&&(i=n)}if(i===void 0)if(t.indexOf(".")===-1){let n=_(e,t);if(n.length){for(let a=0,l=n.length;a<l;a++)if(g(n[a].val)||O(n[a].val)||N(n[a].val)){i=n[a].val;break}else if(G(n[a].val)){i=String(n[a].val);break}else if(Array.isArray(n[a].val)){i=n[a].val.join("");break}}}else{let n=_(e,Y(t));if(n.length)for(let a=0,l=n.length;a<l;a++){let y=h.get(n[a].val,Q(t));y&&g(y)&&(i=y)}}return i}function R(e,t,r,o,i=[]){if(i.includes(r)){let c="";if(i.length>1){let w=` \u2192
11
11
  `;c=i.reduce((D,b,S)=>D+(S===0?"":w)+(b===r?"\u{1F4A5} ":" ")+b,` Here's the path we travelled up until we hit the recursion:
12
12
 
13
13
  `),c+=`${w}\u{1F4A5} ${r}`}throw new Error(`json-variables/resolveString(): [THROW_ID_19] While trying to resolve: "${t}" at path "${r}", we encountered a closed loop, the key is referencing itself."${c}`)}let n={},a=Array.from(i);a.push(r);let l=new B;function y(c,w,D){for(let b=0,S=c.length;b<S;b++){let f=c[b],p=t.slice(f.headsEndAt,f.tailsStartAt);if(p.length===0)l.push(f.headsStartAt,f.tailsEndAt);else if(q.call(n,p)&&g(n[p]))l.push(f.headsStartAt,f.tailsEndAt,n[p]);else{let s=Z(e,p.trim(),r,o);if(s===void 0)if(o.allowUnresolved===!0)s="";else if(typeof o.allowUnresolved=="string")s=o.allowUnresolved;else throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_18] We couldn't find the value to resolve the variable ${t.slice(f.headsEndAt,f.tailsStartAt)}. We're at path: "${r}".`);if(!D&&o.throwWhenNonStringInsertedInString&&!g(s))throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_23] While resolving the variable ${t.slice(f.headsEndAt,f.tailsStartAt)} at path ${r}, it resolved into a non-string value, ${JSON.stringify(s,null,4)}. This is happening because options setting "throwWhenNonStringInsertedInString" is active (set to "true").`);if(O(s)){if(o.resolveToBoolIfAnyValuesContainBool)return l.wipe(),o.resolveToFalseIfAnyValuesContainBool?!1:s;s=""}else{if(N(s)&&D)return l.wipe(),s;Array.isArray(s)?s=String(s.join("")):N(s)?s="":s=String(s)}let v=r.includes(".")?`${J(r)}.${p}`:p;if(T(s,o)){let m=H(R(e,s,v,o,a),o,w,a,v,p.trim());typeof m=="string"&&l.push(f.headsStartAt,f.tailsEndAt,m)}else{n[p]=s;let m=H(s,o,w,a,v,p.trim());typeof m=="string"&&l.push(f.headsStartAt,f.tailsEndAt,m)}}}}let d;try{d=I(t,o.heads,o.tails,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(c){throw new Error(`json-variables/resolveString(): [THROW_ID_17] While trying to resolve string: "${t}" at path ${r}, something wrong with heads and tails was detected! Here's the internal error message:
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @name json-variables
3
3
  * @fileoverview Resolves custom-marked, cross-referenced paths in parsed JSON
4
- * @version 11.1.7
4
+ * @version 11.1.8
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 l=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]=l,this.last()[2],this.last()[2]!==null&&C(r)){let o=this.last()[2]&&this.last()[2].length&&(!((n=this.opts)!=null&&n.mergeType)||this.opts.mergeType===1)?`${this.last()[2]}${r}`:r;this.opts.limitToBeAddedWhitespace&&(o=pe(o,this.opts.limitLinebreaksCount)),X(o)&&!o.length||(this.last()[2]=o)}}else{this.ranges||(this.ranges=[]);let o=r!==void 0&&!(X(r)&&!r.length)?[i,l,r&&this.opts.limitToBeAddedWhitespace?pe(r,this.opts.limitLinebreaksCount):r]:[i,l];this.ranges.push(o)}}else throw j(i)&&i>=0?new TypeError(`ranges-push/Ranges/add(): [THROW_ID_10] "to" value, the second input argument, must be a natural number or zero! Currently it's of a type "${typeof l}" equal to: ${JSON.stringify(l,null,4)}`):new TypeError(`ranges-push/Ranges/add(): [THROW_ID_09] "from" value, the first input argument, must be a natural number or zero! Currently it's of a type "${typeof i}" equal to: ${JSON.stringify(i,null,4)}`)}push(e,t,r){this.add(e,t,r)}current(){return Array.isArray(this.ranges)&&this.ranges.length?(this.ranges=si(this.ranges,{mergeType:this.opts.mergeType}),this.ranges&&this.opts.limitToBeAddedWhitespace?this.ranges.map(e=>C(e[2])?[e[0],e[1],pe(e[2],this.opts.limitLinebreaksCount)]:e):this.ranges):null}wipe(){this.ranges=[]}replace(e){if(Array.isArray(e)&&e.length)if(Array.isArray(e[0])&&j(e[0][0]))this.ranges=Array.from(e);else throw new Error(`ranges-push/Ranges/replace(): [THROW_ID_11] Single range was given but we expected array of arrays! The first element, ${JSON.stringify(e[0],null,4)} should be an array and its first element should be an integer, a string index.`);else this.ranges=[]}last(){return Array.isArray(this.ranges)&&this.ranges.length?this.ranges[this.ranges.length-1]:null}};var li={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function Fe(e,t){if(!Array.isArray(e)||!e.length)return e;let r=$($({},li),t),i,l;if(r.strictlyTwoElementsInRangeArrays&&!e.every((a,g)=>!Array.isArray(a)||a.length!==2?(i=g,l=a.length,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_03] The first argument should be an array and must consist of arrays which are natural number indexes representing TWO string index ranges. However, ${i}th range (${JSON.stringify(e[i],null,4)}) has not two but ${l} elements!`);if(!e.every((a,g)=>!Array.isArray(a)||!Number.isInteger(a[0])||a[0]<0||!Number.isInteger(a[1])||a[1]<0?(i=g,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_04] The first argument should be an array and must consist of arrays which are natural number indexes representing string index ranges. However, ${i}th range (${JSON.stringify(e[i],null,4)}) does not consist of only natural numbers!`);let n=e.length**2,o=0;return Array.from(e).sort((a,g)=>(r.progressFn&&(o+=1,r.progressFn(Math.floor(o*100/n))),a[0]===g[0]?a[1]<g[1]?-1:a[1]>g[1]?1:0:a[0]<g[0]?-1:1))}var zt={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function Yt(e,t){function r(s){return!!s&&typeof s=="object"&&!Array.isArray(s)}if(!Array.isArray(e)||!e.length)return null;let i;if(t)if(r(t)){if(i=$($({},zt),t),i.progressFn&&r(i.progressFn)&&!Object.keys(i.progressFn).length)i.progressFn=null;else if(i.progressFn&&typeof i.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof i.progressFn}", equal to ${JSON.stringify(i.progressFn,null,4)}`);if(![1,2,"1","2"].includes(i.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof i.mergeType}", equal to ${JSON.stringify(i.mergeType,null,4)}`);if(typeof i.joinRangesThatTouchEdges!="boolean")throw new Error(`ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof i.joinRangesThatTouchEdges}", equal to ${JSON.stringify(i.joinRangesThatTouchEdges,null,4)}`)}else throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as:
38
38
  ${JSON.stringify(t,null,4)} (type ${typeof t})`);else i=$({},zt);let l=e.filter(s=>Array.isArray(s)).map(s=>[...s]).filter(s=>s[2]!==void 0||s[0]!==s[1]),n,o,a;i.progressFn?n=Fe(l,{progressFn:s=>{a=Math.floor(s/5),a!==o&&(o=a,i.progressFn(a))}}):n=Fe(l);let g=n.length-1;for(let s=g;s>0;s--)i.progressFn&&(a=Math.floor((1-s/g)*78)+21,a!==o&&a>o&&(o=a,i.progressFn(a))),(n[s][0]<=n[s-1][0]||!i.joinRangesThatTouchEdges&&n[s][0]<n[s-1][1]||i.joinRangesThatTouchEdges&&n[s][0]<=n[s-1][1])&&(n[s-1][0]=Math.min(n[s][0],n[s-1][0]),n[s-1][1]=Math.max(n[s][1],n[s-1][1]),n[s][2]!==void 0&&(n[s-1][0]>=n[s][0]||n[s-1][1]<=n[s][1])&&n[s-1][2]!==null&&(n[s][2]===null&&n[s-1][2]!==null?n[s-1][2]=null:n[s-1][2]!=null?+i.mergeType==2&&n[s-1][0]===n[s][0]?n[s-1][2]=n[s][2]:n[s-1][2]+=n[s][2]:n[s-1][2]=n[s][2]),n.splice(s,1),s=n.length);return n.length?n:null}var fi=!0,ke="Invariant failed";function Xt(e,t){if(!e){if(fi)throw new Error(ke);var r=typeof t=="function"?t():t,i=r?"".concat(ke,": ").concat(r):ke;throw new Error(i)}}function L(e,t,r){let i=0,l=0;if(arguments.length===0)throw new Error("ranges-apply: [THROW_ID_01] inputs missing!");if(typeof e!="string")throw new TypeError(`ranges-apply: [THROW_ID_02] first input argument must be a string! Currently it's: ${typeof e}, equal to: ${JSON.stringify(e,null,4)}`);if(t&&!Array.isArray(t))throw new TypeError(`ranges-apply: [THROW_ID_03] second input argument must be an array (or null)! Currently it's: ${typeof t}, equal to: ${JSON.stringify(t,null,4)}`);if(r&&typeof r!="function")throw new TypeError(`ranges-apply: [THROW_ID_04] the third input argument must be a function (or falsey)! Currently it's: ${typeof r}, equal to: ${JSON.stringify(r,null,4)}`);if(!t||!t.filter(h=>h).length)return e;let n;Array.isArray(t)&&Number.isInteger(t[0])&&Number.isInteger(t[1])?n=[Array.from(t)]:n=Array.from(t);let o=n.length,a=0;n.filter(h=>h).forEach((h,c)=>{if(r&&(i=Math.floor(a/o*10),i!==l&&(l=i,r(i))),!Array.isArray(h))throw new TypeError(`ranges-apply: [THROW_ID_05] ranges array, second input arg., has ${c}th element not an array: ${JSON.stringify(h,null,4)}, which is ${typeof h}`);if(!Number.isInteger(h[0])){if(!Number.isInteger(+h[0])||+h[0]<0)throw new TypeError(`ranges-apply: [THROW_ID_06] ranges array, second input arg. has ${c}th element, array ${JSON.stringify(h,null,0)}. Its first element is not an integer, string index, but ${typeof h[0]}, equal to: ${JSON.stringify(h[0],null,4)}.`);n[c][0]=+n[c][0]}if(!Number.isInteger(h[1])){if(!Number.isInteger(+h[1])||+h[1]<0)throw new TypeError(`ranges-apply: [THROW_ID_07] ranges array, second input arg. has ${c}th element, array ${JSON.stringify(h,null,0)}. Its second element is not an integer, string index, but ${typeof h[1]}, equal to: ${JSON.stringify(h[1],null,4)}.`);n[c][1]=+n[c][1]}a+=1});let g=Yt(n,{progressFn:h=>{r&&(i=10+Math.floor(h/10),i!==l&&(l=i,r(i)))}});Xt(g);let s=g.length;if(s>0){let h=e.slice(g[s-1][1]);e=g.reduce((c,T,y,u)=>{r&&(i=20+Math.floor(y/s*80),i!==l&&(l=i,r(i)));let w=y===0?0:u[y-1][1],d=u[y][0];return`${c}${e.slice(w,d)}${u[y][2]||""}`},""),e+=h}return e}var Zt=U(je(),1);var ui={classicTrim:!1,cr:!1,lf:!1,tab:!1,space:!0,nbsp:!1};function Q(e,t){if(typeof e!="string")throw new Error(`string-trim-spaces-only: [THROW_ID_01] input must be string! It was given as ${typeof e}, equal to:
39
39
  ${JSON.stringify(e,null,4)}`);let r=$($({},ui),t);function i(o){return r.classicTrim&&!o.trim()||!r.classicTrim&&(r.space&&o===" "||r.cr&&o==="\r"||r.lf&&o===`
40
- `||r.tab&&o===" "||r.nbsp&&o==="\xA0")}let l,n;if(e.length){if(i(e[0]))for(let o=0,a=e.length;o<a;o++){if(!i(e[o])){l=o;break}if(o===e.length-1)return{res:"",ranges:[[0,e.length]]}}if(i(e[e.length-1])){for(let o=e.length;o--;)if(!i(e[o])){n=o+1;break}}return l?n?{res:e.slice(l,n),ranges:[[0,l],[n,e.length]]}:{res:e.slice(l),ranges:[[0,l]]}:n?{res:e.slice(0,n),ranges:[[n,e.length]]}:{res:e,ranges:[]}}return{res:"",ranges:[]}}var gi={heads:["{{"],tails:["}}"]};function Qt(e,t){let r=Object.prototype.hasOwnProperty;if(e===void 0)throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_01] The input is missing!");if(typeof e!="string")return e;if(t&&!(0,Zt.default)(t))throw new Error(`string-remove-duplicate-heads-tails: [THROW_ID_03] The given options are not a plain object but ${typeof t}!`);let i=$({},t);if(i&&r.call(i,"heads"))if(I(i.heads).every(w=>typeof w=="string"||Array.isArray(w)))typeof i.heads=="string"&&(i.heads=I(i.heads));else throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_04] The resolvedOpts.heads contains elements which are not string-type!");if(i&&r.call(i,"tails"))if(I(i.tails).every(w=>typeof w=="string"||Array.isArray(w)))typeof i.tails=="string"&&(i.tails=I(i.tails));else throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_05] The resolvedOpts.tails contains elements which are not string-type!");let l=Q(e).res;if(l.length===0)return e;e=l;let n=$($({},gi),i);n.heads=n.heads.map(w=>w.trim()),n.tails=n.tails.map(w=>w.trim());let o=!1,a=!1,g=new Z({limitToBeAddedWhitespace:!0}),s=new Z({limitToBeAddedWhitespace:!0}),h=!0,c=!0,T="";function y(w,d){let f;return S(w,0,d.heads,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=b,!0)})&&S(w,f,d.tails,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=b,!0)})?w.slice(f):w}for(;e!==y(e,n);)e=Q(y(e,n)).res;function u(w,d){let f;return!k(w,w.length-1,d.tails,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=b,!0)})||!f?w:k(w,f,d.heads,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=b,!0)})?w.slice(0,f+1):w}for(;e!==u(e,n);)e=Q(u(e,n)).res;if(!n.heads.length||!S(e,0,n.heads,{trimBeforeMatching:!0})||!n.tails.length||!k(e,e.length-1,n.tails,{trimBeforeMatching:!0}))return Q(e).res;for(let w=0,d=e.length;w<d;w++)if(e[w].trim()!==""){let f;if(S(e,w,n.heads,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=b,!0)})&&f){c=!0,h&&(h=!0);let p;S(e,f,n.tails,{trimBeforeMatching:!0,cb:(m,b,v)=>(p=v,!0)})&&g.push(w,p),s.current()&&o&&T!=="tails"&&g.push(s.current()),o||s.current()&&(g.push(s.current()),s.wipe()),s.push(w,f),T="heads",w=f-1;continue}if(S(e,w,n.tails,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=Number.isInteger(b)?b:e.length,!0)})&&f){c=!0,h?(T==="heads"&&s.wipe(),h=!1):s.push(w,f),T="tails",w=f-1;continue}h&&(h=!0),c&&!o?(o=!0,c=!1):c&&!a?(a=!0,h=!0,c=!1,T==="heads"&&s.wipe()):c&&a&&s.wipe()}return s.current()&&g.push(s.current()),g.current()?L(e,g.current()).trim():e.trim()}var er="11.1.7";var ci=er,pi=Object.prototype.hasOwnProperty,nr={heads:"%%_",tails:"_%%",headsNoWrap:"%%-",tailsNoWrap:"-%%",lookForDataContainers:!0,dataContainerIdentifierTails:"_data",wrapHeadsWith:"",wrapTailsWith:"",dontWrapVars:[],preventDoubleWrapping:!0,wrapGlobalFlipSwitch:!0,noSingleMarkers:!1,resolveToBoolIfAnyValuesContainBool:!0,resolveToFalseIfAnyValuesContainBool:!0,throwWhenNonStringInsertedInString:!1,allowUnresolved:!1};function A(e){return typeof e=="string"}function di(e){return typeof e=="number"}function Le(e){return typeof e=="boolean"}function de(e){return e===null}function ee(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function yi(e){return e!=null}function _(e){return A(e)?e.trim():e}function mi(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let t=0,r=e.length;t<r;t++)if(e[t]===".")return e.slice(0,t)}return e}function wi(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let t=0,r=e.length;t<r;t++)if(e[t]===".")return e.slice(t+1)}return e}function ir(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let t=e.length;t--;)if(e[t]===".")return e.slice(0,t)}return e}function tr(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let t=e.length;t--;)if(e[t]===".")return e.slice(t+1)}return e}function qe(e,t){return typeof e!="string"||!e.trim()?!1:!!(e.includes(t.heads)||e.includes(t.tails)||A(t.headsNoWrap)&&t.headsNoWrap.length&&e.includes(t.headsNoWrap)||A(t.tailsNoWrap)&&t.tailsNoWrap.length&&e.includes(t.tailsNoWrap))}function bi(e,t,r){let i,l;return typeof e=="string"&&e.length&&S(e,0,t,{trimBeforeMatching:!0,cb:(n,o,a)=>(i=a,!0)})&&k(e,e.length-1,r,{trimBeforeMatching:!0,cb:(n,o,a)=>(l=(a||0)+1,!0)})?e.slice(i,l):e}function rr(e,t,r=!1,i,l,n){if(t.wrapHeadsWith||(t.wrapHeadsWith=""),t.wrapTailsWith||(t.wrapTailsWith=""),A(e)&&!r&&t.wrapGlobalFlipSwitch&&!t.dontWrapVars.some(o=>ge(n,o))&&(!t.preventDoubleWrapping||t.preventDoubleWrapping&&A(e)&&!e.includes(t.wrapHeadsWith)&&!e.includes(t.wrapTailsWith)))return`${t.wrapHeadsWith}${e}${t.wrapTailsWith}`;if(r){if(!A(e))return e;let o=Qt(e,{heads:t.wrapHeadsWith,tails:t.wrapTailsWith});return A(o)?bi(o,t.wrapHeadsWith,t.wrapTailsWith):o}return e}function Ti(e,t,r,i){let l;if(r.indexOf(".")!==-1){let n=r,o=!0;if(i.lookForDataContainers&&typeof i.dataContainerIdentifierTails=="string"&&i.dataContainerIdentifierTails.length&&!n.endsWith(i.dataContainerIdentifierTails)){let a=W.default.get(e,n+i.dataContainerIdentifierTails);ee(a)&&W.default.get(a,t)&&(l=W.default.get(a,t),o=!1)}for(;o&&n.indexOf(".")!==-1;){if(n=ir(n),tr(n)===t)throw new Error(`json-variables/findValues(): [THROW_ID_20] While trying to resolve: "${t}" at path "${r}", we encountered a closed loop. The parent key "${tr(n)}" is called the same as the variable "${t}" we're looking for.`);if(i.lookForDataContainers&&typeof i.dataContainerIdentifierTails=="string"&&i.dataContainerIdentifierTails.length&&!n.endsWith(i.dataContainerIdentifierTails)){let a=W.default.get(e,n+i.dataContainerIdentifierTails);ee(a)&&W.default.get(a,t)&&(l=W.default.get(a,t),o=!1)}if(l===void 0){let a=W.default.get(e,n);ee(a)&&W.default.get(a,t)&&(l=W.default.get(a,t),o=!1)}}}if(l===void 0){let n=W.default.get(e,t);n!==void 0&&(l=n)}if(l===void 0)if(t.indexOf(".")===-1){let n=Be(e,t);if(n.length){for(let o=0,a=n.length;o<a;o++)if(A(n[o].val)||Le(n[o].val)||de(n[o].val)){l=n[o].val;break}else if(di(n[o].val)){l=String(n[o].val);break}else if(Array.isArray(n[o].val)){l=n[o].val.join("");break}}}else{let n=Be(e,mi(t));if(n.length)for(let o=0,a=n.length;o<a;o++){let g=W.default.get(n[o].val,wi(t));g&&A(g)&&(l=g)}}return l}function ar(e,t,r,i,l=[]){if(l.includes(r)){let y="";if(l.length>1){let u=` \u2192
40
+ `||r.tab&&o===" "||r.nbsp&&o==="\xA0")}let l,n;if(e.length){if(i(e[0]))for(let o=0,a=e.length;o<a;o++){if(!i(e[o])){l=o;break}if(o===e.length-1)return{res:"",ranges:[[0,e.length]]}}if(i(e[e.length-1])){for(let o=e.length;o--;)if(!i(e[o])){n=o+1;break}}return l?n?{res:e.slice(l,n),ranges:[[0,l],[n,e.length]]}:{res:e.slice(l),ranges:[[0,l]]}:n?{res:e.slice(0,n),ranges:[[n,e.length]]}:{res:e,ranges:[]}}return{res:"",ranges:[]}}var gi={heads:["{{"],tails:["}}"]};function Qt(e,t){let r=Object.prototype.hasOwnProperty;if(e===void 0)throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_01] The input is missing!");if(typeof e!="string")return e;if(t&&!(0,Zt.default)(t))throw new Error(`string-remove-duplicate-heads-tails: [THROW_ID_03] The given options are not a plain object but ${typeof t}!`);let i=$({},t);if(i&&r.call(i,"heads"))if(I(i.heads).every(w=>typeof w=="string"||Array.isArray(w)))typeof i.heads=="string"&&(i.heads=I(i.heads));else throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_04] The resolvedOpts.heads contains elements which are not string-type!");if(i&&r.call(i,"tails"))if(I(i.tails).every(w=>typeof w=="string"||Array.isArray(w)))typeof i.tails=="string"&&(i.tails=I(i.tails));else throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_05] The resolvedOpts.tails contains elements which are not string-type!");let l=Q(e).res;if(l.length===0)return e;e=l;let n=$($({},gi),i);n.heads=n.heads.map(w=>w.trim()),n.tails=n.tails.map(w=>w.trim());let o=!1,a=!1,g=new Z({limitToBeAddedWhitespace:!0}),s=new Z({limitToBeAddedWhitespace:!0}),h=!0,c=!0,T="";function y(w,d){let f;return S(w,0,d.heads,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=b,!0)})&&S(w,f,d.tails,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=b,!0)})?w.slice(f):w}for(;e!==y(e,n);)e=Q(y(e,n)).res;function u(w,d){let f;return!k(w,w.length-1,d.tails,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=b,!0)})||!f?w:k(w,f,d.heads,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=b,!0)})?w.slice(0,f+1):w}for(;e!==u(e,n);)e=Q(u(e,n)).res;if(!n.heads.length||!S(e,0,n.heads,{trimBeforeMatching:!0})||!n.tails.length||!k(e,e.length-1,n.tails,{trimBeforeMatching:!0}))return Q(e).res;for(let w=0,d=e.length;w<d;w++)if(e[w].trim()!==""){let f;if(S(e,w,n.heads,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=b,!0)})&&f){c=!0,h&&(h=!0);let p;S(e,f,n.tails,{trimBeforeMatching:!0,cb:(m,b,v)=>(p=v,!0)})&&g.push(w,p),s.current()&&o&&T!=="tails"&&g.push(s.current()),o||s.current()&&(g.push(s.current()),s.wipe()),s.push(w,f),T="heads",w=f-1;continue}if(S(e,w,n.tails,{trimBeforeMatching:!0,cb:(p,m,b)=>(f=Number.isInteger(b)?b:e.length,!0)})&&f){c=!0,h?(T==="heads"&&s.wipe(),h=!1):s.push(w,f),T="tails",w=f-1;continue}h&&(h=!0),c&&!o?(o=!0,c=!1):c&&!a?(a=!0,h=!0,c=!1,T==="heads"&&s.wipe()):c&&a&&s.wipe()}return s.current()&&g.push(s.current()),g.current()?L(e,g.current()).trim():e.trim()}var er="11.1.8";var ci=er,pi=Object.prototype.hasOwnProperty,nr={heads:"%%_",tails:"_%%",headsNoWrap:"%%-",tailsNoWrap:"-%%",lookForDataContainers:!0,dataContainerIdentifierTails:"_data",wrapHeadsWith:"",wrapTailsWith:"",dontWrapVars:[],preventDoubleWrapping:!0,wrapGlobalFlipSwitch:!0,noSingleMarkers:!1,resolveToBoolIfAnyValuesContainBool:!0,resolveToFalseIfAnyValuesContainBool:!0,throwWhenNonStringInsertedInString:!1,allowUnresolved:!1};function A(e){return typeof e=="string"}function di(e){return typeof e=="number"}function Le(e){return typeof e=="boolean"}function de(e){return e===null}function ee(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function yi(e){return e!=null}function _(e){return A(e)?e.trim():e}function mi(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let t=0,r=e.length;t<r;t++)if(e[t]===".")return e.slice(0,t)}return e}function wi(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let t=0,r=e.length;t<r;t++)if(e[t]===".")return e.slice(t+1)}return e}function ir(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let t=e.length;t--;)if(e[t]===".")return e.slice(0,t)}return e}function tr(e){if(typeof e=="string"&&e.length&&e.indexOf(".")!==-1){for(let t=e.length;t--;)if(e[t]===".")return e.slice(t+1)}return e}function qe(e,t){return typeof e!="string"||!e.trim()?!1:!!(e.includes(t.heads)||e.includes(t.tails)||A(t.headsNoWrap)&&t.headsNoWrap.length&&e.includes(t.headsNoWrap)||A(t.tailsNoWrap)&&t.tailsNoWrap.length&&e.includes(t.tailsNoWrap))}function bi(e,t,r){let i,l;return typeof e=="string"&&e.length&&S(e,0,t,{trimBeforeMatching:!0,cb:(n,o,a)=>(i=a,!0)})&&k(e,e.length-1,r,{trimBeforeMatching:!0,cb:(n,o,a)=>(l=(a||0)+1,!0)})?e.slice(i,l):e}function rr(e,t,r=!1,i,l,n){if(t.wrapHeadsWith||(t.wrapHeadsWith=""),t.wrapTailsWith||(t.wrapTailsWith=""),A(e)&&!r&&t.wrapGlobalFlipSwitch&&!t.dontWrapVars.some(o=>ge(n,o))&&(!t.preventDoubleWrapping||t.preventDoubleWrapping&&A(e)&&!e.includes(t.wrapHeadsWith)&&!e.includes(t.wrapTailsWith)))return`${t.wrapHeadsWith}${e}${t.wrapTailsWith}`;if(r){if(!A(e))return e;let o=Qt(e,{heads:t.wrapHeadsWith,tails:t.wrapTailsWith});return A(o)?bi(o,t.wrapHeadsWith,t.wrapTailsWith):o}return e}function Ti(e,t,r,i){let l;if(r.indexOf(".")!==-1){let n=r,o=!0;if(i.lookForDataContainers&&typeof i.dataContainerIdentifierTails=="string"&&i.dataContainerIdentifierTails.length&&!n.endsWith(i.dataContainerIdentifierTails)){let a=W.default.get(e,n+i.dataContainerIdentifierTails);ee(a)&&W.default.get(a,t)&&(l=W.default.get(a,t),o=!1)}for(;o&&n.indexOf(".")!==-1;){if(n=ir(n),tr(n)===t)throw new Error(`json-variables/findValues(): [THROW_ID_20] While trying to resolve: "${t}" at path "${r}", we encountered a closed loop. The parent key "${tr(n)}" is called the same as the variable "${t}" we're looking for.`);if(i.lookForDataContainers&&typeof i.dataContainerIdentifierTails=="string"&&i.dataContainerIdentifierTails.length&&!n.endsWith(i.dataContainerIdentifierTails)){let a=W.default.get(e,n+i.dataContainerIdentifierTails);ee(a)&&W.default.get(a,t)&&(l=W.default.get(a,t),o=!1)}if(l===void 0){let a=W.default.get(e,n);ee(a)&&W.default.get(a,t)&&(l=W.default.get(a,t),o=!1)}}}if(l===void 0){let n=W.default.get(e,t);n!==void 0&&(l=n)}if(l===void 0)if(t.indexOf(".")===-1){let n=Be(e,t);if(n.length){for(let o=0,a=n.length;o<a;o++)if(A(n[o].val)||Le(n[o].val)||de(n[o].val)){l=n[o].val;break}else if(di(n[o].val)){l=String(n[o].val);break}else if(Array.isArray(n[o].val)){l=n[o].val.join("");break}}}else{let n=Be(e,mi(t));if(n.length)for(let o=0,a=n.length;o<a;o++){let g=W.default.get(n[o].val,wi(t));g&&A(g)&&(l=g)}}return l}function ar(e,t,r,i,l=[]){if(l.includes(r)){let y="";if(l.length>1){let u=` \u2192
41
41
  `;y=l.reduce((w,d,f)=>w+(f===0?"":u)+(d===r?"\u{1F4A5} ":" ")+d,` Here's the path we travelled up until we hit the recursion:
42
42
 
43
43
  `),y+=`${u}\u{1F4A5} ${r}`}throw new Error(`json-variables/resolveString(): [THROW_ID_19] While trying to resolve: "${t}" at path "${r}", we encountered a closed loop, the key is referencing itself."${y}`)}let n={},o=Array.from(l);o.push(r);let a=new Z;function g(y,u,w){for(let d=0,f=y.length;d<f;d++){let p=y[d],m=t.slice(p.headsEndAt,p.tailsStartAt);if(m.length===0)a.push(p.headsStartAt,p.tailsEndAt);else if(pi.call(n,m)&&A(n[m]))a.push(p.headsStartAt,p.tailsEndAt,n[m]);else{let b=Ti(e,m.trim(),r,i);if(b===void 0)if(i.allowUnresolved===!0)b="";else if(typeof i.allowUnresolved=="string")b=i.allowUnresolved;else throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_18] We couldn't find the value to resolve the variable ${t.slice(p.headsEndAt,p.tailsStartAt)}. We're at path: "${r}".`);if(!w&&i.throwWhenNonStringInsertedInString&&!A(b))throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_23] While resolving the variable ${t.slice(p.headsEndAt,p.tailsStartAt)} at path ${r}, it resolved into a non-string value, ${JSON.stringify(b,null,4)}. This is happening because options setting "throwWhenNonStringInsertedInString" is active (set to "true").`);if(Le(b)){if(i.resolveToBoolIfAnyValuesContainBool)return a.wipe(),i.resolveToFalseIfAnyValuesContainBool?!1:b;b=""}else{if(de(b)&&w)return a.wipe(),b;Array.isArray(b)?b=String(b.join("")):de(b)?b="":b=String(b)}let v=r.includes(".")?`${ir(r)}.${m}`:m;if(qe(b,i)){let E=rr(ar(e,b,v,i,o),i,u,o,v,m.trim());typeof E=="string"&&a.push(p.headsStartAt,p.tailsEndAt,E)}else{n[m]=b;let E=rr(b,i,u,o,v,m.trim());typeof E=="string"&&a.push(p.headsStartAt,p.tailsEndAt,E)}}}}let s;try{s=Pe(t,i.heads,i.tails,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(y){throw new Error(`json-variables/resolveString(): [THROW_ID_17] While trying to resolve string: "${t}" at path ${r}, something wrong with heads and tails was detected! Here's the internal error message:
@@ -47,7 +47,7 @@ Please check the following key: ${o}`);if(a!==void 0?n=a:n=o,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.1.1
50
+ * @version 4.1.2
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(a!==void 0?n=a:n=o,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.1.1
58
+ * @version 4.1.2
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: ${o}`);if(a!==void 0?n=a:n=o,n==="")return n;if(
63
63
  /**
64
64
  * @name ast-monkey-traverse
65
65
  * @fileoverview Utility library to traverse AST
66
- * @version 3.1.1
66
+ * @version 3.1.2
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: ${o}`);if(a!==void 0?n=a:n=o,n==="")return n;if(
71
71
  /**
72
72
  * @name ast-monkey-util
73
73
  * @fileoverview Utility library of AST helper functions
74
- * @version 2.1.1
74
+ * @version 2.1.2
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: ${o}`);if(a!==void 0?n=a:n=o,n==="")return n;if(
79
79
  /**
80
80
  * @name ranges-apply
81
81
  * @fileoverview Take an array of string index ranges, delete/replace the string according to them
82
- * @version 6.2.7
82
+ * @version 6.2.8
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: ${o}`);if(a!==void 0?n=a:n=o,n==="")return n;if(
87
87
  /**
88
88
  * @name ranges-merge
89
89
  * @fileoverview Merge and sort string index ranges
90
- * @version 8.2.2
90
+ * @version 8.2.3
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: ${o}`);if(a!==void 0?n=a:n=o,n==="")return n;if(
95
95
  /**
96
96
  * @name ranges-push
97
97
  * @fileoverview Gather string index ranges
98
- * @version 6.2.2
98
+ * @version 6.2.3
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: ${o}`);if(a!==void 0?n=a:n=o,n==="")return n;if(
103
103
  /**
104
104
  * @name ranges-sort
105
105
  * @fileoverview Sort string index ranges
106
- * @version 5.1.1
106
+ * @version 5.1.2
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: ${o}`);if(a!==void 0?n=a:n=o,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.1.2
114
+ * @version 6.1.3
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: ${o}`);if(a!==void 0?n=a:n=o,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.1.2
122
+ * @version 5.1.3
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: ${o}`);if(a!==void 0?n=a:n=o,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.2.2
130
+ * @version 8.2.3
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: ${o}`);if(a!==void 0?n=a:n=o,n==="")return n;if(
135
135
  /**
136
136
  * @name string-remove-duplicate-heads-tails
137
137
  * @fileoverview Detect and (recursively) remove head and tail wrappings around the input string
138
- * @version 6.1.7
138
+ * @version 6.1.8
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: ${o}`);if(a!==void 0?n=a:n=o,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.1.1
146
+ * @version 4.1.2
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.1.7",
3
+ "version": "11.1.8",
4
4
  "description": "Resolves custom-marked, cross-referenced paths in parsed JSON",
5
5
  "keywords": [
6
6
  "comb",
@@ -76,15 +76,15 @@
76
76
  "various": {}
77
77
  },
78
78
  "dependencies": {
79
- "arrayiffy-if-string": "^4.1.1",
80
- "ast-get-values-by-key": "^4.1.1",
81
- "ast-monkey-traverse": "^3.1.1",
79
+ "arrayiffy-if-string": "^4.1.2",
80
+ "ast-get-values-by-key": "^4.1.2",
81
+ "ast-monkey-traverse": "^3.1.2",
82
82
  "matcher": "^5.0.0",
83
83
  "object-path": "^0.11.8",
84
- "ranges-apply": "^6.2.7",
85
- "ranges-push": "^6.2.2",
86
- "string-find-heads-tails": "^5.1.2",
87
- "string-match-left-right": "^8.2.2",
88
- "string-remove-duplicate-heads-tails": "^6.1.7"
84
+ "ranges-apply": "^6.2.8",
85
+ "ranges-push": "^6.2.3",
86
+ "string-find-heads-tails": "^5.1.3",
87
+ "string-match-left-right": "^8.2.3",
88
+ "string-remove-duplicate-heads-tails": "^6.1.8"
89
89
  }
90
90
  }