json-variables 11.0.3 → 11.0.7

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
@@ -3,26 +3,6 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## 11.0.3 (2021-11-02)
7
-
8
- ### Bug Fixes
9
-
10
- - bump TS and separate ESLint plugins away from this monorepo ([b1ebce1](https://github.com/codsen/codsen/commit/b1ebce1637d8c41c2d848fc24b0ba4058865bd5d))
11
-
12
- ### Features
13
-
14
- - migrate to ES Modules ([c579dff](https://github.com/codsen/codsen/commit/c579dff3b23205e383035ca10ddcec671e35d0fe))
15
-
16
- ### BREAKING CHANGES
17
-
18
- - programs now are in ES Modules and won't work with Common JS require()
19
-
20
- ## 11.0.1 (2021-09-13)
21
-
22
- ### Bug Fixes
23
-
24
- - bump TS and separate ESLint plugins away from this monorepo ([2e07d42](https://github.com/codsen/codsen/commit/2e07d424222b6ffedf5fb45c83ad453627ec2904))
25
-
26
6
  ## 11.0.0 (2021-09-09)
27
7
 
28
8
  ### Features
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2010-%YEAR% Roy Revelt and other contributors
3
+ Copyright (c) 2010-2021 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
@@ -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.7
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/json-variables/}
@@ -18,426 +18,494 @@ 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.7";
22
22
 
23
23
  const version = version$1;
24
24
  const has = Object.prototype.hasOwnProperty;
25
25
  const defaults = {
26
- heads: "%%_",
27
- tails: "_%%",
28
- headsNoWrap: "%%-",
29
- tailsNoWrap: "-%%",
30
- lookForDataContainers: true,
31
- dataContainerIdentifierTails: "_data",
32
- wrapHeadsWith: "",
33
- wrapTailsWith: "",
34
- dontWrapVars: [],
35
- preventDoubleWrapping: true,
36
- wrapGlobalFlipSwitch: true,
37
- noSingleMarkers: false,
38
- resolveToBoolIfAnyValuesContainBool: true,
39
- resolveToFalseIfAnyValuesContainBool: true,
40
- throwWhenNonStringInsertedInString: false,
41
- allowUnresolved: false
26
+ heads: "%%_",
27
+ tails: "_%%",
28
+ headsNoWrap: "%%-",
29
+ tailsNoWrap: "-%%",
30
+ lookForDataContainers: true,
31
+ dataContainerIdentifierTails: "_data",
32
+ wrapHeadsWith: "",
33
+ wrapTailsWith: "",
34
+ dontWrapVars: [],
35
+ preventDoubleWrapping: true,
36
+ wrapGlobalFlipSwitch: true,
37
+ noSingleMarkers: false,
38
+ resolveToBoolIfAnyValuesContainBool: true,
39
+ resolveToFalseIfAnyValuesContainBool: true,
40
+ throwWhenNonStringInsertedInString: false,
41
+ allowUnresolved: false,
42
42
  };
43
43
  function isStr(something) {
44
- return typeof something === "string";
44
+ return typeof something === "string";
45
45
  }
46
46
  function isNum(something) {
47
- return typeof something === "number";
47
+ return typeof something === "number";
48
48
  }
49
49
  function isBool(something) {
50
- return typeof something === "boolean";
50
+ return typeof something === "boolean";
51
51
  }
52
52
  function isNull(something) {
53
- return something === null;
53
+ return something === null;
54
54
  }
55
55
  function isObj(something) {
56
- return something && typeof something === "object" && !Array.isArray(something);
56
+ return (something && typeof something === "object" && !Array.isArray(something));
57
57
  }
58
58
  function existy(x) {
59
- return x != null;
59
+ return x != null;
60
60
  }
61
61
  function trimIfString(something) {
62
- return isStr(something) ? something.trim() : something;
62
+ return isStr(something) ? something.trim() : something;
63
63
  }
64
64
  function getTopmostKey(str) {
65
- if (typeof str === "string" && str.length > 0 && str.indexOf(".") !== -1) {
66
- for (let i = 0, len = str.length; i < len; i++) {
67
- if (str[i] === ".") {
68
- return str.slice(0, i);
69
- }
70
- }
71
- }
72
- return str;
65
+ if (typeof str === "string" && str.length > 0 && str.indexOf(".") !== -1) {
66
+ for (let i = 0, len = str.length; i < len; i++) {
67
+ if (str[i] === ".") {
68
+ return str.slice(0, i);
69
+ }
70
+ }
71
+ }
72
+ return str;
73
73
  }
74
74
  function withoutTopmostKey(str) {
75
- if (typeof str === "string" && str.length > 0 && str.indexOf(".") !== -1) {
76
- for (let i = 0, len = str.length; i < len; i++) {
77
- if (str[i] === ".") {
78
- return str.slice(i + 1);
79
- }
80
- }
81
- }
82
- return str;
75
+ if (typeof str === "string" && str.length > 0 && str.indexOf(".") !== -1) {
76
+ for (let i = 0, len = str.length; i < len; i++) {
77
+ if (str[i] === ".") {
78
+ return str.slice(i + 1);
79
+ }
80
+ }
81
+ }
82
+ return str;
83
83
  }
84
84
  function goLevelUp(str) {
85
- if (typeof str === "string" && str.length > 0 && str.indexOf(".") !== -1) {
86
- for (let i = str.length; i--;) {
87
- if (str[i] === ".") {
88
- return str.slice(0, i);
89
- }
90
- }
91
- }
92
- return str;
85
+ if (typeof str === "string" && str.length > 0 && str.indexOf(".") !== -1) {
86
+ for (let i = str.length; i--;) {
87
+ if (str[i] === ".") {
88
+ return str.slice(0, i);
89
+ }
90
+ }
91
+ }
92
+ return str;
93
93
  }
94
94
  function getLastKey(str) {
95
- if (typeof str === "string" && str.length > 0 && str.indexOf(".") !== -1) {
96
- for (let i = str.length; i--;) {
97
- if (str[i] === ".") {
98
- return str.slice(i + 1);
99
- }
100
- }
101
- }
102
- return str;
95
+ if (typeof str === "string" && str.length > 0 && str.indexOf(".") !== -1) {
96
+ for (let i = str.length; i--;) {
97
+ if (str[i] === ".") {
98
+ return str.slice(i + 1);
99
+ }
100
+ }
101
+ }
102
+ return str;
103
103
  }
104
104
  function containsHeadsOrTails(str, opts) {
105
- if (typeof str !== "string" || !str.trim()) {
105
+ if (typeof str !== "string" || !str.trim()) {
106
+ return false;
107
+ }
108
+ if (str.includes(opts.heads) ||
109
+ str.includes(opts.tails) ||
110
+ (isStr(opts.headsNoWrap) &&
111
+ opts.headsNoWrap.length > 0 &&
112
+ str.includes(opts.headsNoWrap)) ||
113
+ (isStr(opts.tailsNoWrap) &&
114
+ opts.tailsNoWrap.length > 0 &&
115
+ str.includes(opts.tailsNoWrap))) {
116
+ return true;
117
+ }
106
118
  return false;
107
- }
108
- if (str.includes(opts.heads) || str.includes(opts.tails) || isStr(opts.headsNoWrap) && opts.headsNoWrap.length > 0 && str.includes(opts.headsNoWrap) || isStr(opts.tailsNoWrap) && opts.tailsNoWrap.length > 0 && str.includes(opts.tailsNoWrap)) {
109
- return true;
110
- }
111
- return false;
112
119
  }
113
120
  function removeWrappingHeadsAndTails(str, heads, tails) {
114
- let tempFrom;
115
- let tempTo;
116
- if (typeof str === "string" && str.length > 0 && matchRightIncl(str, 0, heads, {
117
- trimBeforeMatching: true,
118
- cb: (_c, _t, index) => {
119
- tempFrom = index;
120
- return true;
121
- }
122
- }) && matchLeftIncl(str, str.length - 1, tails, {
123
- trimBeforeMatching: true,
124
- cb: (_c, _t, index) => {
125
- tempTo = index + 1;
126
- return true;
127
- }
128
- })) {
129
- return str.slice(tempFrom, tempTo);
130
- }
131
- return str;
121
+ let tempFrom;
122
+ let tempTo;
123
+ if (typeof str === "string" &&
124
+ str.length > 0 &&
125
+ matchRightIncl(str, 0, heads, {
126
+ trimBeforeMatching: true,
127
+ cb: (_c, _t, index) => {
128
+ tempFrom = index;
129
+ return true;
130
+ },
131
+ }) &&
132
+ matchLeftIncl(str, str.length - 1, tails, {
133
+ trimBeforeMatching: true,
134
+ cb: (_c, _t, index) => {
135
+ tempTo = index + 1;
136
+ return true;
137
+ },
138
+ })) {
139
+ return str.slice(tempFrom, tempTo);
140
+ }
141
+ return str;
132
142
  }
133
143
  function wrap(placementValue, opts, dontWrapTheseVars = false, breadCrumbPath, newPath, oldVarName) {
134
- if (!opts.wrapHeadsWith) {
135
- opts.wrapHeadsWith = "";
136
- }
137
- if (!opts.wrapTailsWith) {
138
- opts.wrapTailsWith = "";
139
- }
140
- if (isStr(placementValue) && !dontWrapTheseVars && opts.wrapGlobalFlipSwitch && !opts.dontWrapVars.some(val => isMatch(oldVarName, val)) && (
141
- !opts.preventDoubleWrapping || opts.preventDoubleWrapping && isStr(placementValue) && !placementValue.includes(opts.wrapHeadsWith) && !placementValue.includes(opts.wrapTailsWith))) {
142
- return opts.wrapHeadsWith + placementValue + opts.wrapTailsWith;
143
- }
144
- if (dontWrapTheseVars) {
145
- if (!isStr(placementValue)) {
146
- return placementValue;
147
- }
148
- const tempValue = remDup(placementValue, {
149
- heads: opts.wrapHeadsWith,
150
- tails: opts.wrapTailsWith
151
- });
152
- if (!isStr(tempValue)) {
153
- return tempValue;
144
+ if (!opts.wrapHeadsWith) {
145
+ opts.wrapHeadsWith = "";
146
+ }
147
+ if (!opts.wrapTailsWith) {
148
+ opts.wrapTailsWith = "";
154
149
  }
155
- return removeWrappingHeadsAndTails(tempValue, opts.wrapHeadsWith, opts.wrapTailsWith);
156
- }
157
- return placementValue;
150
+ if (isStr(placementValue) &&
151
+ !dontWrapTheseVars &&
152
+ opts.wrapGlobalFlipSwitch &&
153
+ !opts.dontWrapVars.some((val) => isMatch(oldVarName, val)) &&
154
+ (!opts.preventDoubleWrapping ||
155
+ (opts.preventDoubleWrapping &&
156
+ isStr(placementValue) &&
157
+ !placementValue.includes(opts.wrapHeadsWith) &&
158
+ !placementValue.includes(opts.wrapTailsWith)))) {
159
+ return opts.wrapHeadsWith + placementValue + opts.wrapTailsWith;
160
+ }
161
+ if (dontWrapTheseVars) {
162
+ if (!isStr(placementValue)) {
163
+ return placementValue;
164
+ }
165
+ const tempValue = remDup(placementValue, {
166
+ heads: opts.wrapHeadsWith,
167
+ tails: opts.wrapTailsWith,
168
+ });
169
+ if (!isStr(tempValue)) {
170
+ return tempValue;
171
+ }
172
+ return removeWrappingHeadsAndTails(tempValue, opts.wrapHeadsWith, opts.wrapTailsWith);
173
+ }
174
+ return placementValue;
158
175
  }
159
176
  function findValues(input, varName, path, opts) {
160
- let resolveValue;
161
- if (path.indexOf(".") !== -1) {
162
- let currentPath = path;
163
- let handBrakeOff = true;
164
- if (opts.lookForDataContainers && typeof opts.dataContainerIdentifierTails === "string" && opts.dataContainerIdentifierTails.length > 0 && !currentPath.endsWith(opts.dataContainerIdentifierTails)) {
165
- const gotPath = objectPath.get(input, currentPath + opts.dataContainerIdentifierTails);
166
- if (isObj(gotPath) && objectPath.get(gotPath, varName)) {
167
- resolveValue = objectPath.get(gotPath, varName);
168
- handBrakeOff = false;
169
- }
170
- }
171
- while (handBrakeOff && currentPath.indexOf(".") !== -1) {
172
- currentPath = goLevelUp(currentPath);
173
- if (getLastKey(currentPath) === varName) {
174
- throw new Error(`json-variables/findValues(): [THROW_ID_20] While trying to resolve: "${varName}" at path "${path}", we encountered a closed loop. The parent key "${getLastKey(currentPath)}" is called the same as the variable "${varName}" we're looking for.`);
175
- }
176
- if (opts.lookForDataContainers && typeof opts.dataContainerIdentifierTails === "string" && opts.dataContainerIdentifierTails.length > 0 && !currentPath.endsWith(opts.dataContainerIdentifierTails)) {
177
- const gotPath = objectPath.get(input, currentPath + opts.dataContainerIdentifierTails);
178
- if (isObj(gotPath) && objectPath.get(gotPath, varName)) {
179
- resolveValue = objectPath.get(gotPath, varName);
180
- handBrakeOff = false;
177
+ let resolveValue;
178
+ if (path.indexOf(".") !== -1) {
179
+ let currentPath = path;
180
+ let handBrakeOff = true;
181
+ if (opts.lookForDataContainers &&
182
+ typeof opts.dataContainerIdentifierTails === "string" &&
183
+ opts.dataContainerIdentifierTails.length > 0 &&
184
+ !currentPath.endsWith(opts.dataContainerIdentifierTails)) {
185
+ const gotPath = objectPath.get(input, currentPath + opts.dataContainerIdentifierTails);
186
+ if (isObj(gotPath) && objectPath.get(gotPath, varName)) {
187
+ resolveValue = objectPath.get(gotPath, varName);
188
+ handBrakeOff = false;
189
+ }
181
190
  }
182
- }
183
- if (resolveValue === undefined) {
184
- const gotPath = objectPath.get(input, currentPath);
185
- if (isObj(gotPath) && objectPath.get(gotPath, varName)) {
186
- resolveValue = objectPath.get(gotPath, varName);
187
- handBrakeOff = false;
191
+ while (handBrakeOff && currentPath.indexOf(".") !== -1) {
192
+ currentPath = goLevelUp(currentPath);
193
+ if (getLastKey(currentPath) === varName) {
194
+ throw new Error(`json-variables/findValues(): [THROW_ID_20] While trying to resolve: "${varName}" at path "${path}", we encountered a closed loop. The parent key "${getLastKey(currentPath)}" is called the same as the variable "${varName}" we're looking for.`);
195
+ }
196
+ if (opts.lookForDataContainers &&
197
+ typeof opts.dataContainerIdentifierTails === "string" &&
198
+ opts.dataContainerIdentifierTails.length > 0 &&
199
+ !currentPath.endsWith(opts.dataContainerIdentifierTails)) {
200
+ const gotPath = objectPath.get(input, currentPath + opts.dataContainerIdentifierTails);
201
+ if (isObj(gotPath) && objectPath.get(gotPath, varName)) {
202
+ resolveValue = objectPath.get(gotPath, varName);
203
+ handBrakeOff = false;
204
+ }
205
+ }
206
+ if (resolveValue === undefined) {
207
+ const gotPath = objectPath.get(input, currentPath);
208
+ if (isObj(gotPath) && objectPath.get(gotPath, varName)) {
209
+ resolveValue = objectPath.get(gotPath, varName);
210
+ handBrakeOff = false;
211
+ }
212
+ }
213
+ }
214
+ }
215
+ if (resolveValue === undefined) {
216
+ const gotPath = objectPath.get(input, varName);
217
+ if (gotPath !== undefined) {
218
+ resolveValue = gotPath;
188
219
  }
189
- }
190
- }
191
- }
192
- if (resolveValue === undefined) {
193
- const gotPath = objectPath.get(input, varName);
194
- if (gotPath !== undefined) {
195
- resolveValue = gotPath;
196
- }
197
- }
198
- if (resolveValue === undefined) {
199
- if (varName.indexOf(".") === -1) {
200
- const gotPathArr = getByKey(input, varName);
201
- if (gotPathArr.length > 0) {
202
- for (let y = 0, len2 = gotPathArr.length; y < len2; y++) {
203
- if (isStr(gotPathArr[y].val) || isBool(gotPathArr[y].val) || isNull(gotPathArr[y].val)) {
204
- resolveValue = gotPathArr[y].val;
205
- break;
206
- } else if (isNum(gotPathArr[y].val)) {
207
- resolveValue = String(gotPathArr[y].val);
208
- break;
209
- } else if (Array.isArray(gotPathArr[y].val)) {
210
- resolveValue = gotPathArr[y].val.join("");
211
- break;
212
- } else {
213
- throw new Error(`json-variables/findValues(): [THROW_ID_21] While trying to resolve: "${varName}" at path "${path}", we actually found the key named ${varName}, but it was not equal to a string but to:\n${JSON.stringify(gotPathArr[y], null, 4)}\nWe can't resolve a string with that! It should be a string.`);
214
- }
220
+ }
221
+ if (resolveValue === undefined) {
222
+ if (varName.indexOf(".") === -1) {
223
+ const gotPathArr = getByKey(input, varName);
224
+ if (gotPathArr.length > 0) {
225
+ for (let y = 0, len2 = gotPathArr.length; y < len2; y++) {
226
+ if (isStr(gotPathArr[y].val) ||
227
+ isBool(gotPathArr[y].val) ||
228
+ isNull(gotPathArr[y].val)) {
229
+ resolveValue = gotPathArr[y].val;
230
+ break;
231
+ }
232
+ else if (isNum(gotPathArr[y].val)) {
233
+ resolveValue = String(gotPathArr[y].val);
234
+ break;
235
+ }
236
+ else if (Array.isArray(gotPathArr[y].val)) {
237
+ resolveValue = gotPathArr[y].val.join("");
238
+ break;
239
+ }
240
+ else {
241
+ throw new Error(`json-variables/findValues(): [THROW_ID_21] While trying to resolve: "${varName}" at path "${path}", we actually found the key named ${varName}, but it was not equal to a string but to:\n${JSON.stringify(gotPathArr[y], null, 4)}\nWe can't resolve a string with that! It should be a string.`);
242
+ }
243
+ }
244
+ }
215
245
  }
216
- }
217
- } else {
218
- const gotPath = getByKey(input, getTopmostKey(varName));
219
- if (gotPath.length > 0) {
220
- for (let y = 0, len2 = gotPath.length; y < len2; y++) {
221
- const temp = objectPath.get(gotPath[y].val, withoutTopmostKey(varName));
222
- if (temp && isStr(temp)) {
223
- resolveValue = temp;
224
- }
246
+ else {
247
+ const gotPath = getByKey(input, getTopmostKey(varName));
248
+ if (gotPath.length > 0) {
249
+ for (let y = 0, len2 = gotPath.length; y < len2; y++) {
250
+ const temp = objectPath.get(gotPath[y].val, withoutTopmostKey(varName));
251
+ if (temp && isStr(temp)) {
252
+ resolveValue = temp;
253
+ }
254
+ }
255
+ }
225
256
  }
226
- }
227
257
  }
228
- }
229
- return resolveValue;
258
+ return resolveValue;
230
259
  }
231
260
  function resolveString(input, string, path, opts, incomingBreadCrumbPath = []) {
232
- if (incomingBreadCrumbPath.includes(path)) {
233
- let extra = "";
234
- if (incomingBreadCrumbPath.length > 1) {
235
- const separator = " →\n";
236
- extra = incomingBreadCrumbPath.reduce((accum, curr, idx) => accum + (idx === 0 ? "" : separator) + (curr === path ? "💥 " : " ") + curr, " Here's the path we travelled up until we hit the recursion:\n\n");
237
- extra += `${separator}💥 ${path}`;
238
- }
239
- throw new Error(`json-variables/resolveString(): [THROW_ID_19] While trying to resolve: "${string}" at path "${path}", we encountered a closed loop, the key is referencing itself."${extra}`);
240
- }
241
- const secretResolvedVarsStash = {};
242
- const breadCrumbPath = Array.from(incomingBreadCrumbPath);
243
- breadCrumbPath.push(path);
244
- const finalRangesArr = new Ranges();
245
- function processHeadsAndTails(arr, dontWrapTheseVars, wholeValueIsVariable) {
246
- for (let i = 0, len = arr.length; i < len; i++) {
247
- const obj = arr[i];
248
- const varName = string.slice(obj.headsEndAt, obj.tailsStartAt);
249
- if (varName.length === 0) {
250
- finalRangesArr.push(obj.headsStartAt,
251
- obj.tailsEndAt
252
- );
253
- } else if (has.call(secretResolvedVarsStash, varName) && isStr(secretResolvedVarsStash[varName])) {
254
- finalRangesArr.push(obj.headsStartAt,
255
- obj.tailsEndAt,
256
- secretResolvedVarsStash[varName]
257
- );
258
- } else {
259
- let resolvedValue = findValues(input,
260
- varName.trim(),
261
- path,
262
- opts
263
- );
264
- if (resolvedValue === undefined) {
265
- if (opts.allowUnresolved === true) {
266
- resolvedValue = "";
267
- } else if (typeof opts.allowUnresolved === "string") {
268
- resolvedValue = opts.allowUnresolved;
269
- } else {
270
- throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_18] We couldn't find the value to resolve the variable ${string.slice(obj.headsEndAt, obj.tailsStartAt)}. We're at path: "${path}".`);
271
- }
272
- }
273
- if (!wholeValueIsVariable && opts.throwWhenNonStringInsertedInString && !isStr(resolvedValue)) {
274
- throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_23] While resolving the variable ${string.slice(obj.headsEndAt, obj.tailsStartAt)} at path ${path}, it resolved into a non-string value, ${JSON.stringify(resolvedValue, null, 4)}. This is happening because options setting "throwWhenNonStringInsertedInString" is active (set to "true").`);
261
+ if (incomingBreadCrumbPath.includes(path)) {
262
+ let extra = "";
263
+ if (incomingBreadCrumbPath.length > 1) {
264
+ const separator = " →\n";
265
+ extra = incomingBreadCrumbPath.reduce((accum, curr, idx) => accum +
266
+ (idx === 0 ? "" : separator) +
267
+ (curr === path ? "💥 " : " ") +
268
+ curr, " Here's the path we travelled up until we hit the recursion:\n\n");
269
+ extra += `${separator}💥 ${path}`;
275
270
  }
276
- if (isBool(resolvedValue)) {
277
- if (opts.resolveToBoolIfAnyValuesContainBool) {
278
- finalRangesArr.wipe();
279
- if (!opts.resolveToFalseIfAnyValuesContainBool) {
280
- return resolvedValue;
271
+ throw new Error(`json-variables/resolveString(): [THROW_ID_19] While trying to resolve: "${string}" at path "${path}", we encountered a closed loop, the key is referencing itself."${extra}`);
272
+ }
273
+ const secretResolvedVarsStash = {};
274
+ const breadCrumbPath = Array.from(incomingBreadCrumbPath);
275
+ breadCrumbPath.push(path);
276
+ const finalRangesArr = new Ranges();
277
+ function processHeadsAndTails(arr, dontWrapTheseVars, wholeValueIsVariable) {
278
+ for (let i = 0, len = arr.length; i < len; i++) {
279
+ const obj = arr[i];
280
+ const varName = string.slice(obj.headsEndAt, obj.tailsStartAt);
281
+ if (varName.length === 0) {
282
+ finalRangesArr.push(obj.headsStartAt,
283
+ obj.tailsEndAt
284
+ );
285
+ }
286
+ else if (has.call(secretResolvedVarsStash, varName) &&
287
+ isStr(secretResolvedVarsStash[varName])) {
288
+ finalRangesArr.push(obj.headsStartAt,
289
+ obj.tailsEndAt,
290
+ secretResolvedVarsStash[varName]
291
+ );
292
+ }
293
+ else {
294
+ let resolvedValue = findValues(input,
295
+ varName.trim(),
296
+ path,
297
+ opts
298
+ );
299
+ if (resolvedValue === undefined) {
300
+ if (opts.allowUnresolved === true) {
301
+ resolvedValue = "";
302
+ }
303
+ else if (typeof opts.allowUnresolved === "string") {
304
+ resolvedValue = opts.allowUnresolved;
305
+ }
306
+ else {
307
+ throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_18] We couldn't find the value to resolve the variable ${string.slice(obj.headsEndAt, obj.tailsStartAt)}. We're at path: "${path}".`);
308
+ }
309
+ }
310
+ if (!wholeValueIsVariable &&
311
+ opts.throwWhenNonStringInsertedInString &&
312
+ !isStr(resolvedValue)) {
313
+ throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_23] While resolving the variable ${string.slice(obj.headsEndAt, obj.tailsStartAt)} at path ${path}, it resolved into a non-string value, ${JSON.stringify(resolvedValue, null, 4)}. This is happening because options setting "throwWhenNonStringInsertedInString" is active (set to "true").`);
314
+ }
315
+ if (isBool(resolvedValue)) {
316
+ if (opts.resolveToBoolIfAnyValuesContainBool) {
317
+ finalRangesArr.wipe();
318
+ if (!opts.resolveToFalseIfAnyValuesContainBool) {
319
+ return resolvedValue;
320
+ }
321
+ return false;
322
+ }
323
+ resolvedValue = "";
324
+ }
325
+ else if (isNull(resolvedValue) && wholeValueIsVariable) {
326
+ finalRangesArr.wipe();
327
+ return resolvedValue;
328
+ }
329
+ else if (Array.isArray(resolvedValue)) {
330
+ resolvedValue = String(resolvedValue.join(""));
331
+ }
332
+ else if (isNull(resolvedValue)) {
333
+ resolvedValue = "";
334
+ }
335
+ else {
336
+ resolvedValue = String(resolvedValue);
337
+ }
338
+ const newPath = path.includes(".")
339
+ ? `${goLevelUp(path)}.${varName}`
340
+ : varName;
341
+ if (containsHeadsOrTails(resolvedValue, opts)) {
342
+ const replacementVal = wrap(resolveString(
343
+ input, resolvedValue, newPath, opts, breadCrumbPath), opts, dontWrapTheseVars, breadCrumbPath, newPath, varName.trim());
344
+ if (isStr(replacementVal)) {
345
+ finalRangesArr.push(obj.headsStartAt,
346
+ obj.tailsEndAt,
347
+ replacementVal);
348
+ }
349
+ }
350
+ else {
351
+ secretResolvedVarsStash[varName] = resolvedValue;
352
+ const replacementVal = wrap(resolvedValue, opts, dontWrapTheseVars, breadCrumbPath, newPath, varName.trim());
353
+ if (isStr(replacementVal)) {
354
+ finalRangesArr.push(obj.headsStartAt,
355
+ obj.tailsEndAt,
356
+ replacementVal);
357
+ }
358
+ }
281
359
  }
282
- return false;
283
- }
284
- resolvedValue = "";
285
- } else if (isNull(resolvedValue) && wholeValueIsVariable) {
286
- finalRangesArr.wipe();
287
- return resolvedValue;
288
- } else if (Array.isArray(resolvedValue)) {
289
- resolvedValue = String(resolvedValue.join(""));
290
- } else if (isNull(resolvedValue)) {
291
- resolvedValue = "";
292
- } else {
293
- resolvedValue = String(resolvedValue);
294
- }
295
- const newPath = path.includes(".") ? `${goLevelUp(path)}.${varName}` : varName;
296
- if (containsHeadsOrTails(resolvedValue, opts)) {
297
- const replacementVal = wrap(resolveString(
298
- input, resolvedValue, newPath, opts, breadCrumbPath), opts, dontWrapTheseVars, breadCrumbPath, newPath, varName.trim());
299
- if (isStr(replacementVal)) {
300
- finalRangesArr.push(obj.headsStartAt,
301
- obj.tailsEndAt,
302
- replacementVal);
303
- }
304
- } else {
305
- secretResolvedVarsStash[varName] = resolvedValue;
306
- const replacementVal = wrap(resolvedValue, opts, dontWrapTheseVars, breadCrumbPath, newPath, varName.trim());
307
- if (isStr(replacementVal)) {
308
- finalRangesArr.push(obj.headsStartAt,
309
- obj.tailsEndAt,
310
- replacementVal);
311
- }
312
360
  }
313
- }
314
- }
315
- return undefined;
316
- }
317
- let foundHeadsAndTails;
318
- try {
319
- foundHeadsAndTails = strFindHeadsTails(string, opts.heads, opts.tails, {
320
- source: "",
321
- throwWhenSomethingWrongIsDetected: false
322
- });
323
- } catch (error) {
324
- throw new Error(`json-variables/resolveString(): [THROW_ID_17] While trying to resolve string: "${string}" at path ${path}, something wrong with heads and tails was detected! Here's the internal error message:\n${error}`);
325
- }
326
- let wholeValueIsVariable = false;
327
- if (foundHeadsAndTails.length === 1 && rApply(string, [[foundHeadsAndTails[0].headsStartAt, foundHeadsAndTails[0].tailsEndAt]]).trim() === "") {
328
- wholeValueIsVariable = true;
329
- }
330
- const temp1 = processHeadsAndTails(foundHeadsAndTails, false, wholeValueIsVariable);
331
- if (isBool(temp1)) {
332
- return temp1;
333
- }
334
- if (isNull(temp1)) {
335
- return temp1;
336
- }
337
- try {
338
- foundHeadsAndTails = strFindHeadsTails(string, opts.headsNoWrap, opts.tailsNoWrap, {
339
- source: "",
340
- throwWhenSomethingWrongIsDetected: false
341
- });
342
- } catch (error) {
343
- throw new Error(`json-variables/resolveString(): [THROW_ID_22] While trying to resolve string: "${string}" at path ${path}, something wrong with no-wrap heads and no-wrap tails was detected! Here's the internal error message:\n${error}`);
344
- }
345
- if (foundHeadsAndTails.length === 1 && rApply(string, [[foundHeadsAndTails[0].headsStartAt, foundHeadsAndTails[0].tailsEndAt]]).trim() === "") {
346
- wholeValueIsVariable = true;
347
- }
348
- const temp2 = processHeadsAndTails(foundHeadsAndTails, true, wholeValueIsVariable);
349
- if (isBool(temp2)) {
350
- return temp2;
351
- }
352
- if (isNull(temp2)) {
353
- return temp2;
354
- }
355
- if (finalRangesArr && finalRangesArr.current()) {
356
- return rApply(string, finalRangesArr.current());
357
- }
358
- return string;
361
+ return undefined;
362
+ }
363
+ let foundHeadsAndTails;
364
+ try {
365
+ foundHeadsAndTails = strFindHeadsTails(string, opts.heads, opts.tails, {
366
+ source: "",
367
+ throwWhenSomethingWrongIsDetected: false,
368
+ });
369
+ }
370
+ catch (error) {
371
+ throw new Error(`json-variables/resolveString(): [THROW_ID_17] While trying to resolve string: "${string}" at path ${path}, something wrong with heads and tails was detected! Here's the internal error message:\n${error}`);
372
+ }
373
+ let wholeValueIsVariable = false;
374
+ if (foundHeadsAndTails.length === 1 &&
375
+ rApply(string, [
376
+ [foundHeadsAndTails[0].headsStartAt, foundHeadsAndTails[0].tailsEndAt],
377
+ ]).trim() === "") {
378
+ wholeValueIsVariable = true;
379
+ }
380
+ const temp1 = processHeadsAndTails(foundHeadsAndTails, false, wholeValueIsVariable);
381
+ if (isBool(temp1)) {
382
+ return temp1;
383
+ }
384
+ if (isNull(temp1)) {
385
+ return temp1;
386
+ }
387
+ try {
388
+ foundHeadsAndTails = strFindHeadsTails(string, opts.headsNoWrap, opts.tailsNoWrap, {
389
+ source: "",
390
+ throwWhenSomethingWrongIsDetected: false,
391
+ });
392
+ }
393
+ catch (error) {
394
+ throw new Error(`json-variables/resolveString(): [THROW_ID_22] While trying to resolve string: "${string}" at path ${path}, something wrong with no-wrap heads and no-wrap tails was detected! Here's the internal error message:\n${error}`);
395
+ }
396
+ if (foundHeadsAndTails.length === 1 &&
397
+ rApply(string, [
398
+ [foundHeadsAndTails[0].headsStartAt, foundHeadsAndTails[0].tailsEndAt],
399
+ ]).trim() === "") {
400
+ wholeValueIsVariable = true;
401
+ }
402
+ const temp2 = processHeadsAndTails(foundHeadsAndTails, true, wholeValueIsVariable);
403
+ if (isBool(temp2)) {
404
+ return temp2;
405
+ }
406
+ if (isNull(temp2)) {
407
+ return temp2;
408
+ }
409
+ if (finalRangesArr && finalRangesArr.current()) {
410
+ return rApply(string, finalRangesArr.current());
411
+ }
412
+ return string;
359
413
  }
360
414
  function jVar(input, originalOpts) {
361
- if (!arguments.length) {
362
- throw new Error("json-variables/jVar(): [THROW_ID_01] Alas! Inputs are missing!");
363
- }
364
- if (!isObj(input)) {
365
- throw new TypeError(`json-variables/jVar(): [THROW_ID_02] Alas! The input must be a plain object! Currently it's: ${Array.isArray(input) ? "array" : typeof input}`);
366
- }
367
- if (originalOpts && !isObj(originalOpts)) {
368
- throw new TypeError(`json-variables/jVar(): [THROW_ID_03] Alas! An Optional Options Object must be a plain object! Currently it's: ${Array.isArray(originalOpts) ? "array" : typeof originalOpts}`);
369
- }
370
- const opts = { ...defaults,
371
- ...originalOpts
372
- };
373
- if (!opts.dontWrapVars) {
374
- opts.dontWrapVars = [];
375
- } else if (!Array.isArray(opts.dontWrapVars)) {
376
- opts.dontWrapVars = arrayiffy(opts.dontWrapVars);
377
- }
378
- let culpritVal;
379
- let culpritIndex;
380
- if (opts.dontWrapVars.length > 0 && !opts.dontWrapVars.every((el, idx) => {
381
- if (!isStr(el)) {
382
- culpritVal = el;
383
- culpritIndex = idx;
384
- return false;
385
- }
386
- return true;
387
- })) {
388
- 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 "${culpritVal}" at index ${culpritIndex}, which is not string but ${Array.isArray(culpritVal) ? "array" : typeof culpritVal}!`);
389
- }
390
- if (opts.heads === "") {
391
- throw new Error("json-variables/jVar(): [THROW_ID_06] Alas! opts.heads are empty!");
392
- }
393
- if (opts.tails === "") {
394
- throw new Error("json-variables/jVar(): [THROW_ID_07] Alas! opts.tails are empty!");
395
- }
396
- if (opts.lookForDataContainers && opts.dataContainerIdentifierTails === "") {
397
- throw new Error("json-variables/jVar(): [THROW_ID_08] Alas! opts.dataContainerIdentifierTails is empty!");
398
- }
399
- if (opts.heads === opts.tails) {
400
- throw new Error("json-variables/jVar(): [THROW_ID_09] Alas! opts.heads and opts.tails can't be equal!");
401
- }
402
- if (opts.heads === opts.headsNoWrap) {
403
- throw new Error("json-variables/jVar(): [THROW_ID_10] Alas! opts.heads and opts.headsNoWrap can't be equal!");
404
- }
405
- if (opts.tails === opts.tailsNoWrap) {
406
- throw new Error("json-variables/jVar(): [THROW_ID_11] Alas! opts.tails and opts.tailsNoWrap can't be equal!");
407
- }
408
- if (opts.headsNoWrap === "") {
409
- throw new Error("json-variables/jVar(): [THROW_ID_12] Alas! opts.headsNoWrap is an empty string!");
410
- }
411
- if (opts.tailsNoWrap === "") {
412
- throw new Error("json-variables/jVar(): [THROW_ID_13] Alas! opts.tailsNoWrap is an empty string!");
413
- }
414
- if (opts.headsNoWrap === opts.tailsNoWrap) {
415
- throw new Error("json-variables/jVar(): [THROW_ID_14] Alas! opts.headsNoWrap and opts.tailsNoWrap can't be equal!");
416
- }
417
- let current;
418
- return traverse(input, (key, val, innerObj) => {
419
- if (existy(val) && containsHeadsOrTails(key, opts)) {
420
- throw new Error(`json-variables/jVar(): [THROW_ID_15] Alas! Object keys can't contain variables!\nPlease check the following key: ${key}`);
421
- }
422
- if (val !== undefined) {
423
- current = val;
424
- } else {
425
- current = key;
426
- }
427
- if (current === "") {
428
- return current;
429
- }
430
- if (opts.heads.length !== 0 && trimIfString(current) === trimIfString(opts.heads) || opts.tails.length !== 0 && trimIfString(current) === trimIfString(opts.tails) || opts.headsNoWrap.length !== 0 && trimIfString(current) === trimIfString(opts.headsNoWrap) || opts.tailsNoWrap.length !== 0 && trimIfString(current) === trimIfString(opts.tailsNoWrap)) {
431
- if (!opts.noSingleMarkers) {
432
- return current;
433
- }
434
- throw new Error(`json-variables/jVar(): [THROW_ID_16] Alas! While processing the input, we stumbled upon ${trimIfString(current)} which is equal to ${trimIfString(current) === trimIfString(opts.heads) ? "heads" : ""}${trimIfString(current) === trimIfString(opts.tails) ? "tails" : ""}${isStr(opts.headsNoWrap) && trimIfString(current) === trimIfString(opts.headsNoWrap) ? "headsNoWrap" : ""}${isStr(opts.tailsNoWrap) && trimIfString(current) === trimIfString(opts.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 (${trimIfString(current)}) alone`);
415
+ if (!arguments.length) {
416
+ throw new Error("json-variables/jVar(): [THROW_ID_01] Alas! Inputs are missing!");
417
+ }
418
+ if (!isObj(input)) {
419
+ throw new TypeError(`json-variables/jVar(): [THROW_ID_02] Alas! The input must be a plain object! Currently it's: ${Array.isArray(input) ? "array" : typeof input}`);
420
+ }
421
+ if (originalOpts && !isObj(originalOpts)) {
422
+ throw new TypeError(`json-variables/jVar(): [THROW_ID_03] Alas! An Optional Options Object must be a plain object! Currently it's: ${Array.isArray(originalOpts) ? "array" : typeof originalOpts}`);
423
+ }
424
+ const opts = { ...defaults, ...originalOpts };
425
+ if (!opts.dontWrapVars) {
426
+ opts.dontWrapVars = [];
427
+ }
428
+ else if (!Array.isArray(opts.dontWrapVars)) {
429
+ opts.dontWrapVars = arrayiffy(opts.dontWrapVars);
430
+ }
431
+ let culpritVal;
432
+ let culpritIndex;
433
+ if (opts.dontWrapVars.length > 0 &&
434
+ !opts.dontWrapVars.every((el, idx) => {
435
+ if (!isStr(el)) {
436
+ culpritVal = el;
437
+ culpritIndex = idx;
438
+ return false;
439
+ }
440
+ return true;
441
+ })) {
442
+ 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 "${culpritVal}" at index ${culpritIndex}, which is not string but ${Array.isArray(culpritVal) ? "array" : typeof culpritVal}!`);
443
+ }
444
+ if (opts.heads === "") {
445
+ throw new Error("json-variables/jVar(): [THROW_ID_06] Alas! opts.heads are empty!");
446
+ }
447
+ if (opts.tails === "") {
448
+ throw new Error("json-variables/jVar(): [THROW_ID_07] Alas! opts.tails are empty!");
449
+ }
450
+ if (opts.lookForDataContainers && opts.dataContainerIdentifierTails === "") {
451
+ throw new Error("json-variables/jVar(): [THROW_ID_08] Alas! opts.dataContainerIdentifierTails is empty!");
452
+ }
453
+ if (opts.heads === opts.tails) {
454
+ throw new Error("json-variables/jVar(): [THROW_ID_09] Alas! opts.heads and opts.tails can't be equal!");
455
+ }
456
+ if (opts.heads === opts.headsNoWrap) {
457
+ throw new Error("json-variables/jVar(): [THROW_ID_10] Alas! opts.heads and opts.headsNoWrap can't be equal!");
458
+ }
459
+ if (opts.tails === opts.tailsNoWrap) {
460
+ throw new Error("json-variables/jVar(): [THROW_ID_11] Alas! opts.tails and opts.tailsNoWrap can't be equal!");
461
+ }
462
+ if (opts.headsNoWrap === "") {
463
+ throw new Error("json-variables/jVar(): [THROW_ID_12] Alas! opts.headsNoWrap is an empty string!");
464
+ }
465
+ if (opts.tailsNoWrap === "") {
466
+ throw new Error("json-variables/jVar(): [THROW_ID_13] Alas! opts.tailsNoWrap is an empty string!");
435
467
  }
436
- if (isStr(current) && containsHeadsOrTails(current, opts)) {
437
- return resolveString(input, current, innerObj.path, opts);
468
+ if (opts.headsNoWrap === opts.tailsNoWrap) {
469
+ throw new Error("json-variables/jVar(): [THROW_ID_14] Alas! opts.headsNoWrap and opts.tailsNoWrap can't be equal!");
438
470
  }
439
- return current;
440
- });
471
+ let current;
472
+ return traverse(input, (key, val, innerObj) => {
473
+ if (existy(val) && containsHeadsOrTails(key, opts)) {
474
+ throw new Error(`json-variables/jVar(): [THROW_ID_15] Alas! Object keys can't contain variables!\nPlease check the following key: ${key}`);
475
+ }
476
+ if (val !== undefined) {
477
+ current = val;
478
+ }
479
+ else {
480
+ current = key;
481
+ }
482
+ if (current === "") {
483
+ return current;
484
+ }
485
+ if ((opts.heads.length !== 0 &&
486
+ trimIfString(current) === trimIfString(opts.heads)) ||
487
+ (opts.tails.length !== 0 &&
488
+ trimIfString(current) === trimIfString(opts.tails)) ||
489
+ (opts.headsNoWrap.length !== 0 &&
490
+ trimIfString(current) === trimIfString(opts.headsNoWrap)) ||
491
+ (opts.tailsNoWrap.length !== 0 &&
492
+ trimIfString(current) === trimIfString(opts.tailsNoWrap))) {
493
+ if (!opts.noSingleMarkers) {
494
+ return current;
495
+ }
496
+ throw new Error(`json-variables/jVar(): [THROW_ID_16] Alas! While processing the input, we stumbled upon ${trimIfString(current)} which is equal to ${trimIfString(current) === trimIfString(opts.heads) ? "heads" : ""}${trimIfString(current) === trimIfString(opts.tails) ? "tails" : ""}${isStr(opts.headsNoWrap) &&
497
+ trimIfString(current) === trimIfString(opts.headsNoWrap)
498
+ ? "headsNoWrap"
499
+ : ""}${isStr(opts.tailsNoWrap) &&
500
+ trimIfString(current) === trimIfString(opts.tailsNoWrap)
501
+ ? "tailsNoWrap"
502
+ : ""}. If you wouldn't have set opts.noSingleMarkers to "true" this error would not happen and computer would have left the current element (${trimIfString(current)}) alone`);
503
+ }
504
+ if (isStr(current) && containsHeadsOrTails(current, opts)) {
505
+ return resolveString(input, current, innerObj.path, opts);
506
+ }
507
+ return current;
508
+ });
441
509
  }
442
510
 
443
511
  export { defaults, jVar, version };
@@ -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.7
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.7
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.7
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.7
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.7
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.7
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.7
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.7
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.7
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.7
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.7
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.7
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.7
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.7
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.7",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.7",
4
4
  "description": "Resolves custom-marked, cross-referenced paths in parsed JSON",
5
5
  "keywords": [
6
6
  "comb",
@@ -41,13 +41,12 @@
41
41
  "types": "types/index.d.ts",
42
42
  "scripts": {
43
43
  "build": "rollup -c",
44
- "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent --output-file=testStats.md && npm run clean_cov",
45
- "clean_cov": "../../scripts/leaveCoverageTotalOnly.js",
44
+ "build:esbuild": "node '../../scripts/esbuild.js'",
45
+ "build:esbuild:dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
46
+ "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent",
46
47
  "clean_types": "../../scripts/cleanTypes.js",
47
48
  "dev": "rollup -c --dev",
48
49
  "devunittest": "npm run dev && tap --only -R 'base'",
49
- "esbuild": "node '../../scripts/esbuild.js'",
50
- "esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
51
50
  "format": "npm run lect && npm run prettier && npm run lint",
52
51
  "lect": "lect",
53
52
  "lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
@@ -56,17 +55,14 @@
56
55
  "republish": "npm publish || :",
57
56
  "tap": "tap",
58
57
  "pretest": "npm run build",
59
- "test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format",
58
+ "test": "npm run test:ci && npm run perf",
59
+ "test:ci": "npm run unittest && npm run test:examples && npm run format",
60
60
  "test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
61
61
  "tsc": "tsc",
62
- "unittest": "tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf"
62
+ "unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
63
63
  },
64
64
  "tap": {
65
65
  "check-coverage": false,
66
- "coverage-report": [
67
- "json-summary",
68
- "text"
69
- ],
70
66
  "node-arg": [
71
67
  "--no-warnings",
72
68
  "--experimental-loader",
@@ -86,17 +82,17 @@
86
82
  }
87
83
  },
88
84
  "dependencies": {
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",
85
+ "@babel/runtime": "^7.16.3",
86
+ "arrayiffy-if-string": "^4.0.7",
87
+ "ast-get-values-by-key": "^4.0.7",
88
+ "ast-monkey-traverse": "^3.0.7",
93
89
  "matcher": "^5.0.0",
94
90
  "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"
91
+ "ranges-apply": "^6.0.7",
92
+ "ranges-push": "^6.0.7",
93
+ "string-find-heads-tails": "^5.0.7",
94
+ "string-match-left-right": "^8.0.7",
95
+ "string-remove-duplicate-heads-tails": "^6.0.7"
100
96
  },
101
97
  "devDependencies": {
102
98
  "@babel/cli": "^7.16.0",
@@ -107,8 +103,8 @@
107
103
  "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
108
104
  "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
109
105
  "@babel/plugin-proposal-optional-chaining": "^7.16.0",
110
- "@babel/plugin-transform-runtime": "^7.16.0",
111
- "@babel/preset-env": "^7.16.0",
106
+ "@babel/plugin-transform-runtime": "^7.16.4",
107
+ "@babel/preset-env": "^7.16.4",
112
108
  "@babel/preset-typescript": "^7.16.0",
113
109
  "@babel/register": "^7.16.0",
114
110
  "@istanbuljs/esm-loader-hook": "^0.1.2",
@@ -118,25 +114,25 @@
118
114
  "@rollup/plugin-node-resolve": "^13.0.6",
119
115
  "@rollup/plugin-strip": "^2.1.0",
120
116
  "@rollup/plugin-typescript": "^8.3.0",
121
- "@types/node": "^16.11.6",
117
+ "@types/node": "^16.11.10",
122
118
  "@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",
119
+ "@typescript-eslint/eslint-plugin": "^5.5.0",
120
+ "@typescript-eslint/parser": "^5.5.0",
121
+ "core-js": "^3.19.2",
126
122
  "cross-env": "^7.0.3",
127
- "eslint": "^8.1.0",
128
- "lect": "^0.18.3",
129
- "rollup": "^2.59.0",
123
+ "eslint": "^8.3.0",
124
+ "lect": "^0.18.7",
125
+ "rollup": "^2.60.1",
130
126
  "rollup-plugin-ascii": "^0.0.3",
131
127
  "rollup-plugin-banner": "^0.2.1",
132
128
  "rollup-plugin-cleanup": "^3.2.1",
133
- "rollup-plugin-dts": "^4.0.0",
129
+ "rollup-plugin-dts": "^4.0.1",
134
130
  "rollup-plugin-terser": "^7.0.2",
135
- "tap": "^15.0.10",
131
+ "tap": "^15.1.5",
136
132
  "tslib": "^2.3.1",
137
- "typescript": "^4.4.4"
133
+ "typescript": "^4.5.2"
138
134
  },
139
135
  "engines": {
140
- "node": ">=12"
136
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
141
137
  }
142
138
  }