json-variables 10.1.0 → 11.0.3
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 +30 -0
- package/README.md +4 -0
- package/dist/json-variables.esm.js +4 -4
- package/dist/json-variables.umd.js +34 -34
- package/package.json +60 -52
- package/dist/json-variables.cjs.js +0 -463
- package/dist/json-variables.dev.umd.js +0 -4376
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-variables",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.3",
|
|
4
4
|
"description": "Resolves custom-marked, cross-referenced paths in parsed JSON",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"comb",
|
|
@@ -33,17 +33,21 @@
|
|
|
33
33
|
"email": "roy@codsen.com",
|
|
34
34
|
"url": "https://codsen.com"
|
|
35
35
|
},
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
36
|
+
"type": "module",
|
|
37
|
+
"exports": {
|
|
38
|
+
"script": "./dist/json-variables.umd.js",
|
|
39
|
+
"default": "./dist/json-variables.esm.js"
|
|
40
|
+
},
|
|
39
41
|
"types": "types/index.d.ts",
|
|
40
42
|
"scripts": {
|
|
41
43
|
"build": "rollup -c",
|
|
42
|
-
"esbuild": "node '../../scripts/esbuild.js'",
|
|
43
|
-
"esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
|
|
44
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",
|
|
46
|
+
"clean_types": "../../scripts/cleanTypes.js",
|
|
45
47
|
"dev": "rollup -c --dev",
|
|
46
48
|
"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'",
|
|
47
51
|
"format": "npm run lect && npm run prettier && npm run lint",
|
|
48
52
|
"lect": "lect",
|
|
49
53
|
"lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
|
|
@@ -51,22 +55,22 @@
|
|
|
51
55
|
"prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
|
|
52
56
|
"republish": "npm publish || :",
|
|
53
57
|
"tap": "tap",
|
|
54
|
-
"tsc": "tsc",
|
|
55
58
|
"pretest": "npm run build",
|
|
56
59
|
"test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format",
|
|
57
60
|
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"clean_types": "../../scripts/cleanTypes.js"
|
|
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"
|
|
61
63
|
},
|
|
62
64
|
"tap": {
|
|
65
|
+
"check-coverage": false,
|
|
63
66
|
"coverage-report": [
|
|
64
67
|
"json-summary",
|
|
65
68
|
"text"
|
|
66
69
|
],
|
|
67
|
-
"
|
|
68
|
-
"--
|
|
69
|
-
"--
|
|
70
|
+
"node-arg": [
|
|
71
|
+
"--no-warnings",
|
|
72
|
+
"--experimental-loader",
|
|
73
|
+
"@istanbuljs/esm-loader-hook"
|
|
70
74
|
],
|
|
71
75
|
"timeout": 0
|
|
72
76
|
},
|
|
@@ -82,53 +86,57 @@
|
|
|
82
86
|
}
|
|
83
87
|
},
|
|
84
88
|
"dependencies": {
|
|
85
|
-
"@babel/runtime": "^7.
|
|
86
|
-
"arrayiffy-if-string": "^
|
|
87
|
-
"ast-get-values-by-key": "^
|
|
88
|
-
"ast-monkey-traverse": "^
|
|
89
|
-
"matcher": "^
|
|
90
|
-
"object-path": "^0.11.
|
|
91
|
-
"ranges-apply": "^
|
|
92
|
-
"ranges-push": "^
|
|
93
|
-
"string-find-heads-tails": "^
|
|
94
|
-
"string-match-left-right": "^
|
|
95
|
-
"string-remove-duplicate-heads-tails": "^
|
|
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",
|
|
93
|
+
"matcher": "^5.0.0",
|
|
94
|
+
"object-path": "^0.11.8",
|
|
95
|
+
"ranges-apply": "^6.0.3",
|
|
96
|
+
"ranges-push": "^6.0.3",
|
|
97
|
+
"string-find-heads-tails": "^5.0.3",
|
|
98
|
+
"string-match-left-right": "^8.0.3",
|
|
99
|
+
"string-remove-duplicate-heads-tails": "^6.0.3"
|
|
96
100
|
},
|
|
97
101
|
"devDependencies": {
|
|
98
|
-
"@babel/cli": "^7.
|
|
99
|
-
"@babel/core": "^7.
|
|
100
|
-
"@babel/node": "^7.
|
|
101
|
-
"@babel/plugin-external-helpers": "^7.
|
|
102
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
|
103
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.
|
|
104
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.
|
|
105
|
-
"@babel/plugin-proposal-optional-chaining": "^7.
|
|
106
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
107
|
-
"@babel/preset-env": "^7.
|
|
108
|
-
"@babel/preset-typescript": "^7.
|
|
109
|
-
"@babel/register": "^7.
|
|
102
|
+
"@babel/cli": "^7.16.0",
|
|
103
|
+
"@babel/core": "^7.16.0",
|
|
104
|
+
"@babel/node": "^7.16.0",
|
|
105
|
+
"@babel/plugin-external-helpers": "^7.16.0",
|
|
106
|
+
"@babel/plugin-proposal-class-properties": "^7.16.0",
|
|
107
|
+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
|
|
108
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
109
|
+
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
|
|
110
|
+
"@babel/plugin-transform-runtime": "^7.16.0",
|
|
111
|
+
"@babel/preset-env": "^7.16.0",
|
|
112
|
+
"@babel/preset-typescript": "^7.16.0",
|
|
113
|
+
"@babel/register": "^7.16.0",
|
|
114
|
+
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
110
115
|
"@rollup/plugin-babel": "^5.3.0",
|
|
111
|
-
"@rollup/plugin-commonjs": "^
|
|
116
|
+
"@rollup/plugin-commonjs": "^21.0.1",
|
|
112
117
|
"@rollup/plugin-json": "^4.1.0",
|
|
113
|
-
"@rollup/plugin-node-resolve": "^13.0.
|
|
114
|
-
"@rollup/plugin-strip": "^2.0
|
|
115
|
-
"@rollup/plugin-typescript": "^8.
|
|
116
|
-
"@types/node": "^
|
|
117
|
-
"@types/tap": "^15.0.
|
|
118
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
119
|
-
"@typescript-eslint/parser": "^
|
|
120
|
-
"core-js": "^3.
|
|
118
|
+
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
119
|
+
"@rollup/plugin-strip": "^2.1.0",
|
|
120
|
+
"@rollup/plugin-typescript": "^8.3.0",
|
|
121
|
+
"@types/node": "^16.11.6",
|
|
122
|
+
"@types/tap": "^15.0.5",
|
|
123
|
+
"@typescript-eslint/eslint-plugin": "^5.2.0",
|
|
124
|
+
"@typescript-eslint/parser": "^5.2.0",
|
|
125
|
+
"core-js": "^3.19.0",
|
|
121
126
|
"cross-env": "^7.0.3",
|
|
122
|
-
"eslint": "^
|
|
123
|
-
"lect": "^0.
|
|
124
|
-
"rollup": "^2.
|
|
127
|
+
"eslint": "^8.1.0",
|
|
128
|
+
"lect": "^0.18.3",
|
|
129
|
+
"rollup": "^2.59.0",
|
|
125
130
|
"rollup-plugin-ascii": "^0.0.3",
|
|
126
131
|
"rollup-plugin-banner": "^0.2.1",
|
|
127
132
|
"rollup-plugin-cleanup": "^3.2.1",
|
|
128
|
-
"rollup-plugin-dts": "^
|
|
133
|
+
"rollup-plugin-dts": "^4.0.0",
|
|
129
134
|
"rollup-plugin-terser": "^7.0.2",
|
|
130
|
-
"tap": "^
|
|
131
|
-
"tslib": "^2.
|
|
132
|
-
"typescript": "^4.
|
|
135
|
+
"tap": "^15.0.10",
|
|
136
|
+
"tslib": "^2.3.1",
|
|
137
|
+
"typescript": "^4.4.4"
|
|
138
|
+
},
|
|
139
|
+
"engines": {
|
|
140
|
+
"node": ">=12"
|
|
133
141
|
}
|
|
134
142
|
}
|
|
@@ -1,463 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @name json-variables
|
|
3
|
-
* @fileoverview Resolves custom-marked, cross-referenced paths in parsed JSON
|
|
4
|
-
* @version 10.1.0
|
|
5
|
-
* @author Roy Revelt, Codsen Ltd
|
|
6
|
-
* @license MIT
|
|
7
|
-
* {@link https://codsen.com/os/json-variables/}
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
'use strict';
|
|
11
|
-
|
|
12
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
13
|
-
|
|
14
|
-
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
15
|
-
var _typeof = require('@babel/runtime/helpers/typeof');
|
|
16
|
-
var astMonkeyTraverse = require('ast-monkey-traverse');
|
|
17
|
-
var matcher = require('matcher');
|
|
18
|
-
var objectPath = require('object-path');
|
|
19
|
-
var arrayiffyIfString = require('arrayiffy-if-string');
|
|
20
|
-
var stringFindHeadsTails = require('string-find-heads-tails');
|
|
21
|
-
var astGetValuesByKey = require('ast-get-values-by-key');
|
|
22
|
-
var rangesPush = require('ranges-push');
|
|
23
|
-
var rangesApply = require('ranges-apply');
|
|
24
|
-
var stringRemoveDuplicateHeadsTails = require('string-remove-duplicate-heads-tails');
|
|
25
|
-
var stringMatchLeftRight = require('string-match-left-right');
|
|
26
|
-
|
|
27
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
28
|
-
|
|
29
|
-
var _objectSpread__default = /*#__PURE__*/_interopDefaultLegacy(_objectSpread);
|
|
30
|
-
var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
|
|
31
|
-
var matcher__default = /*#__PURE__*/_interopDefaultLegacy(matcher);
|
|
32
|
-
var objectPath__default = /*#__PURE__*/_interopDefaultLegacy(objectPath);
|
|
33
|
-
|
|
34
|
-
var version$1 = "10.1.0";
|
|
35
|
-
|
|
36
|
-
var version = version$1;
|
|
37
|
-
var has = Object.prototype.hasOwnProperty;
|
|
38
|
-
var defaults = {
|
|
39
|
-
heads: "%%_",
|
|
40
|
-
tails: "_%%",
|
|
41
|
-
headsNoWrap: "%%-",
|
|
42
|
-
tailsNoWrap: "-%%",
|
|
43
|
-
lookForDataContainers: true,
|
|
44
|
-
dataContainerIdentifierTails: "_data",
|
|
45
|
-
wrapHeadsWith: "",
|
|
46
|
-
wrapTailsWith: "",
|
|
47
|
-
dontWrapVars: [],
|
|
48
|
-
preventDoubleWrapping: true,
|
|
49
|
-
wrapGlobalFlipSwitch: true,
|
|
50
|
-
noSingleMarkers: false,
|
|
51
|
-
resolveToBoolIfAnyValuesContainBool: true,
|
|
52
|
-
resolveToFalseIfAnyValuesContainBool: true,
|
|
53
|
-
throwWhenNonStringInsertedInString: false,
|
|
54
|
-
allowUnresolved: false
|
|
55
|
-
};
|
|
56
|
-
function isStr(something) {
|
|
57
|
-
return typeof something === "string";
|
|
58
|
-
}
|
|
59
|
-
function isNum(something) {
|
|
60
|
-
return typeof something === "number";
|
|
61
|
-
}
|
|
62
|
-
function isBool(something) {
|
|
63
|
-
return typeof something === "boolean";
|
|
64
|
-
}
|
|
65
|
-
function isNull(something) {
|
|
66
|
-
return something === null;
|
|
67
|
-
}
|
|
68
|
-
function isObj(something) {
|
|
69
|
-
return something && _typeof__default['default'](something) === "object" && !Array.isArray(something);
|
|
70
|
-
}
|
|
71
|
-
function existy(x) {
|
|
72
|
-
return x != null;
|
|
73
|
-
}
|
|
74
|
-
function trimIfString(something) {
|
|
75
|
-
return isStr(something) ? something.trim() : something;
|
|
76
|
-
}
|
|
77
|
-
function getTopmostKey(str) {
|
|
78
|
-
if (typeof str === "string" && str.length > 0 && str.indexOf(".") !== -1) {
|
|
79
|
-
for (var i = 0, len = str.length; i < len; i++) {
|
|
80
|
-
if (str[i] === ".") {
|
|
81
|
-
return str.slice(0, i);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return str;
|
|
86
|
-
}
|
|
87
|
-
function withoutTopmostKey(str) {
|
|
88
|
-
if (typeof str === "string" && str.length > 0 && str.indexOf(".") !== -1) {
|
|
89
|
-
for (var i = 0, len = str.length; i < len; i++) {
|
|
90
|
-
if (str[i] === ".") {
|
|
91
|
-
return str.slice(i + 1);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return str;
|
|
96
|
-
}
|
|
97
|
-
function goLevelUp(str) {
|
|
98
|
-
if (typeof str === "string" && str.length > 0 && str.indexOf(".") !== -1) {
|
|
99
|
-
for (var i = str.length; i--;) {
|
|
100
|
-
if (str[i] === ".") {
|
|
101
|
-
return str.slice(0, i);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return str;
|
|
106
|
-
}
|
|
107
|
-
function getLastKey(str) {
|
|
108
|
-
if (typeof str === "string" && str.length > 0 && str.indexOf(".") !== -1) {
|
|
109
|
-
for (var i = str.length; i--;) {
|
|
110
|
-
if (str[i] === ".") {
|
|
111
|
-
return str.slice(i + 1);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return str;
|
|
116
|
-
}
|
|
117
|
-
function containsHeadsOrTails(str, opts) {
|
|
118
|
-
if (typeof str !== "string" || !str.trim()) {
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
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)) {
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
function removeWrappingHeadsAndTails(str, heads, tails) {
|
|
127
|
-
var tempFrom;
|
|
128
|
-
var tempTo;
|
|
129
|
-
if (typeof str === "string" && str.length > 0 && stringMatchLeftRight.matchRightIncl(str, 0, heads, {
|
|
130
|
-
trimBeforeMatching: true,
|
|
131
|
-
cb: function cb(_c, _t, index) {
|
|
132
|
-
tempFrom = index;
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
}) && stringMatchLeftRight.matchLeftIncl(str, str.length - 1, tails, {
|
|
136
|
-
trimBeforeMatching: true,
|
|
137
|
-
cb: function cb(_c, _t, index) {
|
|
138
|
-
tempTo = index + 1;
|
|
139
|
-
return true;
|
|
140
|
-
}
|
|
141
|
-
})) {
|
|
142
|
-
return str.slice(tempFrom, tempTo);
|
|
143
|
-
}
|
|
144
|
-
return str;
|
|
145
|
-
}
|
|
146
|
-
function wrap(placementValue, opts) {
|
|
147
|
-
var dontWrapTheseVars = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
148
|
-
var oldVarName = arguments.length > 5 ? arguments[5] : undefined;
|
|
149
|
-
if (!opts.wrapHeadsWith) {
|
|
150
|
-
opts.wrapHeadsWith = "";
|
|
151
|
-
}
|
|
152
|
-
if (!opts.wrapTailsWith) {
|
|
153
|
-
opts.wrapTailsWith = "";
|
|
154
|
-
}
|
|
155
|
-
if (isStr(placementValue) && !dontWrapTheseVars && opts.wrapGlobalFlipSwitch && !opts.dontWrapVars.some(function (val) {
|
|
156
|
-
return matcher__default['default'].isMatch(oldVarName, val);
|
|
157
|
-
}) && (
|
|
158
|
-
!opts.preventDoubleWrapping || opts.preventDoubleWrapping && isStr(placementValue) && !placementValue.includes(opts.wrapHeadsWith) && !placementValue.includes(opts.wrapTailsWith))) {
|
|
159
|
-
return opts.wrapHeadsWith + placementValue + opts.wrapTailsWith;
|
|
160
|
-
}
|
|
161
|
-
if (dontWrapTheseVars) {
|
|
162
|
-
if (!isStr(placementValue)) {
|
|
163
|
-
return placementValue;
|
|
164
|
-
}
|
|
165
|
-
var tempValue = stringRemoveDuplicateHeadsTails.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;
|
|
175
|
-
}
|
|
176
|
-
function findValues(input, varName, path, opts) {
|
|
177
|
-
var resolveValue;
|
|
178
|
-
if (path.indexOf(".") !== -1) {
|
|
179
|
-
var currentPath = path;
|
|
180
|
-
var handBrakeOff = true;
|
|
181
|
-
if (opts.lookForDataContainers && typeof opts.dataContainerIdentifierTails === "string" && opts.dataContainerIdentifierTails.length > 0 && !currentPath.endsWith(opts.dataContainerIdentifierTails)) {
|
|
182
|
-
var gotPath = objectPath__default['default'].get(input, currentPath + opts.dataContainerIdentifierTails);
|
|
183
|
-
if (isObj(gotPath) && objectPath__default['default'].get(gotPath, varName)) {
|
|
184
|
-
resolveValue = objectPath__default['default'].get(gotPath, varName);
|
|
185
|
-
handBrakeOff = false;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
while (handBrakeOff && currentPath.indexOf(".") !== -1) {
|
|
189
|
-
currentPath = goLevelUp(currentPath);
|
|
190
|
-
if (getLastKey(currentPath) === varName) {
|
|
191
|
-
throw new Error("json-variables/findValues(): [THROW_ID_20] While trying to resolve: \"".concat(varName, "\" at path \"").concat(path, "\", we encountered a closed loop. The parent key \"").concat(getLastKey(currentPath), "\" is called the same as the variable \"").concat(varName, "\" we're looking for."));
|
|
192
|
-
}
|
|
193
|
-
if (opts.lookForDataContainers && typeof opts.dataContainerIdentifierTails === "string" && opts.dataContainerIdentifierTails.length > 0 && !currentPath.endsWith(opts.dataContainerIdentifierTails)) {
|
|
194
|
-
var _gotPath = objectPath__default['default'].get(input, currentPath + opts.dataContainerIdentifierTails);
|
|
195
|
-
if (isObj(_gotPath) && objectPath__default['default'].get(_gotPath, varName)) {
|
|
196
|
-
resolveValue = objectPath__default['default'].get(_gotPath, varName);
|
|
197
|
-
handBrakeOff = false;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
if (resolveValue === undefined) {
|
|
201
|
-
var _gotPath2 = objectPath__default['default'].get(input, currentPath);
|
|
202
|
-
if (isObj(_gotPath2) && objectPath__default['default'].get(_gotPath2, varName)) {
|
|
203
|
-
resolveValue = objectPath__default['default'].get(_gotPath2, varName);
|
|
204
|
-
handBrakeOff = false;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
if (resolveValue === undefined) {
|
|
210
|
-
var _gotPath3 = objectPath__default['default'].get(input, varName);
|
|
211
|
-
if (_gotPath3 !== undefined) {
|
|
212
|
-
resolveValue = _gotPath3;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
if (resolveValue === undefined) {
|
|
216
|
-
if (varName.indexOf(".") === -1) {
|
|
217
|
-
var gotPathArr = astGetValuesByKey.getByKey(input, varName);
|
|
218
|
-
if (gotPathArr.length > 0) {
|
|
219
|
-
for (var y = 0, len2 = gotPathArr.length; y < len2; y++) {
|
|
220
|
-
if (isStr(gotPathArr[y].val) || isBool(gotPathArr[y].val) || isNull(gotPathArr[y].val)) {
|
|
221
|
-
resolveValue = gotPathArr[y].val;
|
|
222
|
-
break;
|
|
223
|
-
} else if (isNum(gotPathArr[y].val)) {
|
|
224
|
-
resolveValue = String(gotPathArr[y].val);
|
|
225
|
-
break;
|
|
226
|
-
} else if (Array.isArray(gotPathArr[y].val)) {
|
|
227
|
-
resolveValue = gotPathArr[y].val.join("");
|
|
228
|
-
break;
|
|
229
|
-
} else {
|
|
230
|
-
throw new Error("json-variables/findValues(): [THROW_ID_21] While trying to resolve: \"".concat(varName, "\" at path \"").concat(path, "\", we actually found the key named ").concat(varName, ", but it was not equal to a string but to:\n").concat(JSON.stringify(gotPathArr[y], null, 4), "\nWe can't resolve a string with that! It should be a string."));
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
} else {
|
|
235
|
-
var _gotPath4 = astGetValuesByKey.getByKey(input, getTopmostKey(varName));
|
|
236
|
-
if (_gotPath4.length > 0) {
|
|
237
|
-
for (var _y = 0, _len = _gotPath4.length; _y < _len; _y++) {
|
|
238
|
-
var temp = objectPath__default['default'].get(_gotPath4[_y].val, withoutTopmostKey(varName));
|
|
239
|
-
if (temp && isStr(temp)) {
|
|
240
|
-
resolveValue = temp;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
return resolveValue;
|
|
247
|
-
}
|
|
248
|
-
function resolveString(input, string, path, opts) {
|
|
249
|
-
var incomingBreadCrumbPath = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
|
|
250
|
-
if (incomingBreadCrumbPath.includes(path)) {
|
|
251
|
-
var extra = "";
|
|
252
|
-
if (incomingBreadCrumbPath.length > 1) {
|
|
253
|
-
var separator = " →\n";
|
|
254
|
-
extra = incomingBreadCrumbPath.reduce(function (accum, curr, idx) {
|
|
255
|
-
return accum + (idx === 0 ? "" : separator) + (curr === path ? "💥 " : " ") + curr;
|
|
256
|
-
}, " Here's the path we travelled up until we hit the recursion:\n\n");
|
|
257
|
-
extra += "".concat(separator, "\uD83D\uDCA5 ").concat(path);
|
|
258
|
-
}
|
|
259
|
-
throw new Error("json-variables/resolveString(): [THROW_ID_19] While trying to resolve: \"".concat(string, "\" at path \"").concat(path, "\", we encountered a closed loop, the key is referencing itself.\"").concat(extra));
|
|
260
|
-
}
|
|
261
|
-
var secretResolvedVarsStash = {};
|
|
262
|
-
var breadCrumbPath = Array.from(incomingBreadCrumbPath);
|
|
263
|
-
breadCrumbPath.push(path);
|
|
264
|
-
var finalRangesArr = new rangesPush.Ranges();
|
|
265
|
-
function processHeadsAndTails(arr, dontWrapTheseVars, wholeValueIsVariable) {
|
|
266
|
-
for (var i = 0, len = arr.length; i < len; i++) {
|
|
267
|
-
var obj = arr[i];
|
|
268
|
-
var varName = string.slice(obj.headsEndAt, obj.tailsStartAt);
|
|
269
|
-
if (varName.length === 0) {
|
|
270
|
-
finalRangesArr.push(obj.headsStartAt,
|
|
271
|
-
obj.tailsEndAt
|
|
272
|
-
);
|
|
273
|
-
} else if (has.call(secretResolvedVarsStash, varName) && isStr(secretResolvedVarsStash[varName])) {
|
|
274
|
-
finalRangesArr.push(obj.headsStartAt,
|
|
275
|
-
obj.tailsEndAt,
|
|
276
|
-
secretResolvedVarsStash[varName]
|
|
277
|
-
);
|
|
278
|
-
} else {
|
|
279
|
-
var resolvedValue = findValues(input,
|
|
280
|
-
varName.trim(),
|
|
281
|
-
path,
|
|
282
|
-
opts
|
|
283
|
-
);
|
|
284
|
-
if (resolvedValue === undefined) {
|
|
285
|
-
if (opts.allowUnresolved === true) {
|
|
286
|
-
resolvedValue = "";
|
|
287
|
-
} else if (typeof opts.allowUnresolved === "string") {
|
|
288
|
-
resolvedValue = opts.allowUnresolved;
|
|
289
|
-
} else {
|
|
290
|
-
throw new Error("json-variables/processHeadsAndTails(): [THROW_ID_18] We couldn't find the value to resolve the variable ".concat(string.slice(obj.headsEndAt, obj.tailsStartAt), ". We're at path: \"").concat(path, "\"."));
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
if (!wholeValueIsVariable && opts.throwWhenNonStringInsertedInString && !isStr(resolvedValue)) {
|
|
294
|
-
throw new Error("json-variables/processHeadsAndTails(): [THROW_ID_23] While resolving the variable ".concat(string.slice(obj.headsEndAt, obj.tailsStartAt), " at path ").concat(path, ", it resolved into a non-string value, ").concat(JSON.stringify(resolvedValue, null, 4), ". This is happening because options setting \"throwWhenNonStringInsertedInString\" is active (set to \"true\")."));
|
|
295
|
-
}
|
|
296
|
-
if (isBool(resolvedValue)) {
|
|
297
|
-
if (opts.resolveToBoolIfAnyValuesContainBool) {
|
|
298
|
-
finalRangesArr.wipe();
|
|
299
|
-
if (!opts.resolveToFalseIfAnyValuesContainBool) {
|
|
300
|
-
return resolvedValue;
|
|
301
|
-
}
|
|
302
|
-
return false;
|
|
303
|
-
}
|
|
304
|
-
resolvedValue = "";
|
|
305
|
-
} else if (isNull(resolvedValue) && wholeValueIsVariable) {
|
|
306
|
-
finalRangesArr.wipe();
|
|
307
|
-
return resolvedValue;
|
|
308
|
-
} else if (Array.isArray(resolvedValue)) {
|
|
309
|
-
resolvedValue = String(resolvedValue.join(""));
|
|
310
|
-
} else if (isNull(resolvedValue)) {
|
|
311
|
-
resolvedValue = "";
|
|
312
|
-
} else {
|
|
313
|
-
resolvedValue = String(resolvedValue);
|
|
314
|
-
}
|
|
315
|
-
var newPath = path.includes(".") ? "".concat(goLevelUp(path), ".").concat(varName) : varName;
|
|
316
|
-
if (containsHeadsOrTails(resolvedValue, opts)) {
|
|
317
|
-
var replacementVal = wrap(resolveString(
|
|
318
|
-
input, resolvedValue, newPath, opts, breadCrumbPath), opts, dontWrapTheseVars, breadCrumbPath, newPath, varName.trim());
|
|
319
|
-
if (isStr(replacementVal)) {
|
|
320
|
-
finalRangesArr.push(obj.headsStartAt,
|
|
321
|
-
obj.tailsEndAt,
|
|
322
|
-
replacementVal);
|
|
323
|
-
}
|
|
324
|
-
} else {
|
|
325
|
-
secretResolvedVarsStash[varName] = resolvedValue;
|
|
326
|
-
var _replacementVal = wrap(resolvedValue, opts, dontWrapTheseVars, breadCrumbPath, newPath, varName.trim());
|
|
327
|
-
if (isStr(_replacementVal)) {
|
|
328
|
-
finalRangesArr.push(obj.headsStartAt,
|
|
329
|
-
obj.tailsEndAt,
|
|
330
|
-
_replacementVal);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
return undefined;
|
|
336
|
-
}
|
|
337
|
-
var foundHeadsAndTails;
|
|
338
|
-
try {
|
|
339
|
-
foundHeadsAndTails = stringFindHeadsTails.strFindHeadsTails(string, opts.heads, opts.tails, {
|
|
340
|
-
source: "",
|
|
341
|
-
throwWhenSomethingWrongIsDetected: false
|
|
342
|
-
});
|
|
343
|
-
} catch (error) {
|
|
344
|
-
throw new Error("json-variables/resolveString(): [THROW_ID_17] While trying to resolve string: \"".concat(string, "\" at path ").concat(path, ", something wrong with heads and tails was detected! Here's the internal error message:\n").concat(error));
|
|
345
|
-
}
|
|
346
|
-
var wholeValueIsVariable = false;
|
|
347
|
-
if (foundHeadsAndTails.length === 1 && rangesApply.rApply(string, [[foundHeadsAndTails[0].headsStartAt, foundHeadsAndTails[0].tailsEndAt]]).trim() === "") {
|
|
348
|
-
wholeValueIsVariable = true;
|
|
349
|
-
}
|
|
350
|
-
var temp1 = processHeadsAndTails(foundHeadsAndTails, false, wholeValueIsVariable);
|
|
351
|
-
if (isBool(temp1)) {
|
|
352
|
-
return temp1;
|
|
353
|
-
}
|
|
354
|
-
if (isNull(temp1)) {
|
|
355
|
-
return temp1;
|
|
356
|
-
}
|
|
357
|
-
try {
|
|
358
|
-
foundHeadsAndTails = stringFindHeadsTails.strFindHeadsTails(string, opts.headsNoWrap, opts.tailsNoWrap, {
|
|
359
|
-
source: "",
|
|
360
|
-
throwWhenSomethingWrongIsDetected: false
|
|
361
|
-
});
|
|
362
|
-
} catch (error) {
|
|
363
|
-
throw new Error("json-variables/resolveString(): [THROW_ID_22] While trying to resolve string: \"".concat(string, "\" at path ").concat(path, ", something wrong with no-wrap heads and no-wrap tails was detected! Here's the internal error message:\n").concat(error));
|
|
364
|
-
}
|
|
365
|
-
if (foundHeadsAndTails.length === 1 && rangesApply.rApply(string, [[foundHeadsAndTails[0].headsStartAt, foundHeadsAndTails[0].tailsEndAt]]).trim() === "") {
|
|
366
|
-
wholeValueIsVariable = true;
|
|
367
|
-
}
|
|
368
|
-
var temp2 = processHeadsAndTails(foundHeadsAndTails, true, wholeValueIsVariable);
|
|
369
|
-
if (isBool(temp2)) {
|
|
370
|
-
return temp2;
|
|
371
|
-
}
|
|
372
|
-
if (isNull(temp2)) {
|
|
373
|
-
return temp2;
|
|
374
|
-
}
|
|
375
|
-
if (finalRangesArr && finalRangesArr.current()) {
|
|
376
|
-
return rangesApply.rApply(string, finalRangesArr.current());
|
|
377
|
-
}
|
|
378
|
-
return string;
|
|
379
|
-
}
|
|
380
|
-
function jVar(input, originalOpts) {
|
|
381
|
-
if (!arguments.length) {
|
|
382
|
-
throw new Error("json-variables/jVar(): [THROW_ID_01] Alas! Inputs are missing!");
|
|
383
|
-
}
|
|
384
|
-
if (!isObj(input)) {
|
|
385
|
-
throw new TypeError("json-variables/jVar(): [THROW_ID_02] Alas! The input must be a plain object! Currently it's: ".concat(Array.isArray(input) ? "array" : _typeof__default['default'](input)));
|
|
386
|
-
}
|
|
387
|
-
if (originalOpts && !isObj(originalOpts)) {
|
|
388
|
-
throw new TypeError("json-variables/jVar(): [THROW_ID_03] Alas! An Optional Options Object must be a plain object! Currently it's: ".concat(Array.isArray(originalOpts) ? "array" : _typeof__default['default'](originalOpts)));
|
|
389
|
-
}
|
|
390
|
-
var opts = _objectSpread__default['default'](_objectSpread__default['default']({}, defaults), originalOpts);
|
|
391
|
-
if (!opts.dontWrapVars) {
|
|
392
|
-
opts.dontWrapVars = [];
|
|
393
|
-
} else if (!Array.isArray(opts.dontWrapVars)) {
|
|
394
|
-
opts.dontWrapVars = arrayiffyIfString.arrayiffy(opts.dontWrapVars);
|
|
395
|
-
}
|
|
396
|
-
var culpritVal;
|
|
397
|
-
var culpritIndex;
|
|
398
|
-
if (opts.dontWrapVars.length > 0 && !opts.dontWrapVars.every(function (el, idx) {
|
|
399
|
-
if (!isStr(el)) {
|
|
400
|
-
culpritVal = el;
|
|
401
|
-
culpritIndex = idx;
|
|
402
|
-
return false;
|
|
403
|
-
}
|
|
404
|
-
return true;
|
|
405
|
-
})) {
|
|
406
|
-
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 \"".concat(culpritVal, "\" at index ").concat(culpritIndex, ", which is not string but ").concat(Array.isArray(culpritVal) ? "array" : _typeof__default['default'](culpritVal), "!"));
|
|
407
|
-
}
|
|
408
|
-
if (opts.heads === "") {
|
|
409
|
-
throw new Error("json-variables/jVar(): [THROW_ID_06] Alas! opts.heads are empty!");
|
|
410
|
-
}
|
|
411
|
-
if (opts.tails === "") {
|
|
412
|
-
throw new Error("json-variables/jVar(): [THROW_ID_07] Alas! opts.tails are empty!");
|
|
413
|
-
}
|
|
414
|
-
if (opts.lookForDataContainers && opts.dataContainerIdentifierTails === "") {
|
|
415
|
-
throw new Error("json-variables/jVar(): [THROW_ID_08] Alas! opts.dataContainerIdentifierTails is empty!");
|
|
416
|
-
}
|
|
417
|
-
if (opts.heads === opts.tails) {
|
|
418
|
-
throw new Error("json-variables/jVar(): [THROW_ID_09] Alas! opts.heads and opts.tails can't be equal!");
|
|
419
|
-
}
|
|
420
|
-
if (opts.heads === opts.headsNoWrap) {
|
|
421
|
-
throw new Error("json-variables/jVar(): [THROW_ID_10] Alas! opts.heads and opts.headsNoWrap can't be equal!");
|
|
422
|
-
}
|
|
423
|
-
if (opts.tails === opts.tailsNoWrap) {
|
|
424
|
-
throw new Error("json-variables/jVar(): [THROW_ID_11] Alas! opts.tails and opts.tailsNoWrap can't be equal!");
|
|
425
|
-
}
|
|
426
|
-
if (opts.headsNoWrap === "") {
|
|
427
|
-
throw new Error("json-variables/jVar(): [THROW_ID_12] Alas! opts.headsNoWrap is an empty string!");
|
|
428
|
-
}
|
|
429
|
-
if (opts.tailsNoWrap === "") {
|
|
430
|
-
throw new Error("json-variables/jVar(): [THROW_ID_13] Alas! opts.tailsNoWrap is an empty string!");
|
|
431
|
-
}
|
|
432
|
-
if (opts.headsNoWrap === opts.tailsNoWrap) {
|
|
433
|
-
throw new Error("json-variables/jVar(): [THROW_ID_14] Alas! opts.headsNoWrap and opts.tailsNoWrap can't be equal!");
|
|
434
|
-
}
|
|
435
|
-
var current;
|
|
436
|
-
return astMonkeyTraverse.traverse(input, function (key, val, innerObj) {
|
|
437
|
-
if (existy(val) && containsHeadsOrTails(key, opts)) {
|
|
438
|
-
throw new Error("json-variables/jVar(): [THROW_ID_15] Alas! Object keys can't contain variables!\nPlease check the following key: ".concat(key));
|
|
439
|
-
}
|
|
440
|
-
if (val !== undefined) {
|
|
441
|
-
current = val;
|
|
442
|
-
} else {
|
|
443
|
-
current = key;
|
|
444
|
-
}
|
|
445
|
-
if (current === "") {
|
|
446
|
-
return current;
|
|
447
|
-
}
|
|
448
|
-
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)) {
|
|
449
|
-
if (!opts.noSingleMarkers) {
|
|
450
|
-
return current;
|
|
451
|
-
}
|
|
452
|
-
throw new Error("json-variables/jVar(): [THROW_ID_16] Alas! While processing the input, we stumbled upon ".concat(trimIfString(current), " which is equal to ").concat(trimIfString(current) === trimIfString(opts.heads) ? "heads" : "").concat(trimIfString(current) === trimIfString(opts.tails) ? "tails" : "").concat(isStr(opts.headsNoWrap) && trimIfString(current) === trimIfString(opts.headsNoWrap) ? "headsNoWrap" : "").concat(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 (").concat(trimIfString(current), ") alone"));
|
|
453
|
-
}
|
|
454
|
-
if (isStr(current) && containsHeadsOrTails(current, opts)) {
|
|
455
|
-
return resolveString(input, current, innerObj.path, opts);
|
|
456
|
-
}
|
|
457
|
-
return current;
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
exports.defaults = defaults;
|
|
462
|
-
exports.jVar = jVar;
|
|
463
|
-
exports.version = version;
|