fig-tree-evaluator 2.5.0 → 2.5.2
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/README.md +5 -5
- package/build/FigTreeEvaluator.js +32 -75
- package/build/cache.js +29 -75
- package/build/evaluate.js +68 -159
- package/build/helpers.js +55 -133
- package/build/index.js +1 -1
- package/build/operators/_operatorUtils.js +48 -109
- package/build/operators/buildObject.js +26 -84
- package/build/operators/conditional.js +18 -70
- package/build/operators/count.js +14 -48
- package/build/operators/customFunctions.js +25 -95
- package/build/operators/divide.js +26 -61
- package/build/operators/equal.js +23 -57
- package/build/operators/getRequest.js +36 -97
- package/build/operators/graphQL.js +40 -101
- package/build/operators/greaterThan.js +20 -54
- package/build/operators/lessThan.js +20 -54
- package/build/operators/logicalAnd.js +16 -61
- package/build/operators/logicalOr.js +14 -48
- package/build/operators/match.js +38 -101
- package/build/operators/multiply.js +14 -48
- package/build/operators/notEqual.js +23 -57
- package/build/operators/objectProperties.js +21 -66
- package/build/operators/passThru.js +15 -58
- package/build/operators/pgSQL.js +54 -135
- package/build/operators/plus.js +24 -70
- package/build/operators/postRequest.js +28 -82
- package/build/operators/regex.js +24 -70
- package/build/operators/split.js +29 -74
- package/build/operators/stringSubstitution.js +25 -79
- package/build/operators/subtract.js +16 -50
- package/build/typeCheck.js +22 -27
- package/package.json +2 -2
package/build/operators/split.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -19,39 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
19
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
9
|
});
|
|
21
10
|
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
12
|
exports.SPLIT = void 0;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
13
|
+
const _operatorUtils_1 = require("./_operatorUtils");
|
|
14
|
+
const requiredProperties = ['value'];
|
|
15
|
+
const operatorAliases = ['split', 'arraySplit'];
|
|
16
|
+
const propertyAliases = {
|
|
55
17
|
string: 'value',
|
|
56
18
|
separator: 'delimiter',
|
|
57
19
|
trim: 'trimWhiteSpace',
|
|
@@ -59,38 +21,31 @@ var propertyAliases = {
|
|
|
59
21
|
removeTrailing: 'excludeTrailing',
|
|
60
22
|
excludeTrailingDelimiter: 'excludeTrailing',
|
|
61
23
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
var _a,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return [2, splitValues];
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}); };
|
|
86
|
-
var parseChildren = function (expression) {
|
|
87
|
-
var _a = expression.children, value = _a[0], _b = _a[1], delimiter = _b === void 0 ? DEFAULT_DELIMITER : _b;
|
|
88
|
-
return __assign(__assign({}, expression), { value: value, delimiter: delimiter });
|
|
24
|
+
const DEFAULT_DELIMITER = ' ';
|
|
25
|
+
const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
var _a, _b, _c;
|
|
27
|
+
const [value, delimiter, trimWhiteSpace, excludeTrailing] = (yield (0, _operatorUtils_1.evaluateArray)([
|
|
28
|
+
expression.value,
|
|
29
|
+
(_a = expression.delimiter) !== null && _a !== void 0 ? _a : DEFAULT_DELIMITER,
|
|
30
|
+
(_b = expression.trimWhiteSpace) !== null && _b !== void 0 ? _b : true,
|
|
31
|
+
(_c = expression.excludeTrailing) !== null && _c !== void 0 ? _c : true,
|
|
32
|
+
], config));
|
|
33
|
+
config.typeChecker({ name: 'value', value: value, expectedType: 'string' }, { name: 'delimiter', value: delimiter, expectedType: 'string' }, { name: 'trimWhiteSpace', value: trimWhiteSpace, expectedType: 'boolean' }, { name: 'excludeTrailing', value: excludeTrailing, expectedType: 'boolean' });
|
|
34
|
+
let splitValues = value.split(delimiter);
|
|
35
|
+
if (trimWhiteSpace)
|
|
36
|
+
splitValues = splitValues.map((val) => val.trim());
|
|
37
|
+
if (excludeTrailing && splitValues[splitValues.length - 1] === '')
|
|
38
|
+
splitValues.pop();
|
|
39
|
+
return splitValues;
|
|
40
|
+
});
|
|
41
|
+
const parseChildren = (expression) => {
|
|
42
|
+
const [value, delimiter = DEFAULT_DELIMITER] = expression.children;
|
|
43
|
+
return Object.assign(Object.assign({}, expression), { value, delimiter });
|
|
89
44
|
};
|
|
90
45
|
exports.SPLIT = {
|
|
91
|
-
requiredProperties
|
|
92
|
-
operatorAliases
|
|
93
|
-
propertyAliases
|
|
94
|
-
evaluate
|
|
95
|
-
parseChildren
|
|
46
|
+
requiredProperties,
|
|
47
|
+
operatorAliases,
|
|
48
|
+
propertyAliases,
|
|
49
|
+
evaluate,
|
|
50
|
+
parseChildren,
|
|
96
51
|
};
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -19,76 +8,33 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
19
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
9
|
});
|
|
21
10
|
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
50
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
-
if (ar || !(i in from)) {
|
|
52
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
-
ar[i] = from[i];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
57
|
-
};
|
|
58
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
12
|
exports.STRING_SUBSTITUTION = void 0;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
.join('')];
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}); };
|
|
84
|
-
var parseChildren = function (expression) {
|
|
85
|
-
var _a = expression.children, string = _a[0], substitutions = _a.slice(1);
|
|
86
|
-
return __assign(__assign({}, expression), { string: string, substitutions: substitutions });
|
|
13
|
+
const _operatorUtils_1 = require("./_operatorUtils");
|
|
14
|
+
const requiredProperties = ['string', 'substitutions'];
|
|
15
|
+
const operatorAliases = ['stringSubstitution', 'substitute', 'stringSub', 'replace'];
|
|
16
|
+
const propertyAliases = { replacements: 'substitutions' };
|
|
17
|
+
const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
const [string, ...substitutions] = (yield (0, _operatorUtils_1.evaluateArray)([expression.string, ...expression.substitutions], config));
|
|
19
|
+
config.typeChecker({ name: 'string', value: string, expectedType: 'string' });
|
|
20
|
+
config.typeChecker({ name: 'substitutions', value: substitutions, expectedType: 'array' });
|
|
21
|
+
const regex = /(%[\d]+)/g;
|
|
22
|
+
const parameters = (string.match(regex) || []).sort((a, b) => Number(a.slice(1)) - Number(b.slice(1)));
|
|
23
|
+
const uniqueParameters = new Set(parameters);
|
|
24
|
+
const replacementsObj = (0, _operatorUtils_1.zipArraysToObject)(Array.from(uniqueParameters), substitutions);
|
|
25
|
+
return string
|
|
26
|
+
.split(regex)
|
|
27
|
+
.map((fragment) => (fragment in replacementsObj ? replacementsObj[fragment] : fragment))
|
|
28
|
+
.join('');
|
|
29
|
+
});
|
|
30
|
+
const parseChildren = (expression) => {
|
|
31
|
+
const [string, ...substitutions] = expression.children;
|
|
32
|
+
return Object.assign(Object.assign({}, expression), { string, substitutions });
|
|
87
33
|
};
|
|
88
34
|
exports.STRING_SUBSTITUTION = {
|
|
89
|
-
requiredProperties
|
|
90
|
-
operatorAliases
|
|
91
|
-
propertyAliases
|
|
92
|
-
evaluate
|
|
93
|
-
parseChildren
|
|
35
|
+
requiredProperties,
|
|
36
|
+
operatorAliases,
|
|
37
|
+
propertyAliases,
|
|
38
|
+
evaluate,
|
|
39
|
+
parseChildren,
|
|
94
40
|
};
|
|
@@ -8,59 +8,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
12
|
exports.SUBTRACT = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var values;
|
|
13
|
+
const logicalAnd_1 = require("./logicalAnd");
|
|
14
|
+
const _operatorUtils_1 = require("./_operatorUtils");
|
|
15
|
+
const requiredProperties = [];
|
|
16
|
+
const operatorAliases = ['-', 'subtract', 'minus', 'takeaway'];
|
|
17
|
+
const propertyAliases = { subtractFrom: 'from' };
|
|
18
|
+
const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
19
|
var _a;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (values.length < 2)
|
|
55
|
-
throw new Error('- Not enough values provided');
|
|
56
|
-
return [2, values[0] - values[1]];
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}); };
|
|
20
|
+
const values = (yield (0, _operatorUtils_1.evaluateArray)((_a = expression.values) !== null && _a !== void 0 ? _a : [expression.from, expression.subtract], config));
|
|
21
|
+
config.typeChecker({ name: 'values', value: values, expectedType: 'array' });
|
|
22
|
+
if (values.length < 2)
|
|
23
|
+
throw new Error('- Not enough values provided');
|
|
24
|
+
return values[0] - values[1];
|
|
25
|
+
});
|
|
60
26
|
exports.SUBTRACT = {
|
|
61
|
-
requiredProperties
|
|
62
|
-
operatorAliases
|
|
63
|
-
propertyAliases
|
|
64
|
-
evaluate
|
|
27
|
+
requiredProperties,
|
|
28
|
+
operatorAliases,
|
|
29
|
+
propertyAliases,
|
|
30
|
+
evaluate,
|
|
65
31
|
parseChildren: logicalAnd_1.parseChildren,
|
|
66
32
|
};
|
package/build/typeCheck.js
CHANGED
|
@@ -1,53 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.typeCheck = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var result;
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
const typeCheckItem = ({ value, name, not = false, expectedType, }) => {
|
|
6
|
+
let result;
|
|
8
7
|
if (Array.isArray(expectedType)) {
|
|
9
|
-
result = expectedType.some(
|
|
8
|
+
result = expectedType.some((type) => typeCheckItem({ value, name, expectedType: type }) === true);
|
|
10
9
|
if (not)
|
|
11
10
|
result = !result;
|
|
12
11
|
return result ? true : makeErrorString(name, value, expectedType.join('|'), not);
|
|
13
12
|
}
|
|
14
13
|
else {
|
|
15
|
-
|
|
14
|
+
const checker = typeCheckMap[expectedType];
|
|
16
15
|
result = checker(value);
|
|
17
16
|
if (not)
|
|
18
17
|
result = !result;
|
|
19
18
|
return result ? true : makeErrorString(name, value, expectedType, not);
|
|
20
19
|
}
|
|
21
20
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
var errorStrings = [];
|
|
28
|
-
args.forEach(function (item) {
|
|
29
|
-
var result = typeCheckItem(item);
|
|
21
|
+
const typeCheck = (...args) => {
|
|
22
|
+
const errorStrings = [];
|
|
23
|
+
args.forEach((item) => {
|
|
24
|
+
const result = typeCheckItem(item);
|
|
30
25
|
if (result !== true)
|
|
31
26
|
errorStrings.push(result);
|
|
32
27
|
});
|
|
33
28
|
return errorStrings.length > 0 ? errorStrings.join('\n') : true;
|
|
34
29
|
};
|
|
35
30
|
exports.typeCheck = typeCheck;
|
|
36
|
-
|
|
37
|
-
string:
|
|
38
|
-
number:
|
|
39
|
-
boolean:
|
|
40
|
-
array:
|
|
41
|
-
undefined:
|
|
42
|
-
null:
|
|
43
|
-
object:
|
|
31
|
+
const typeCheckMap = {
|
|
32
|
+
string: (value) => typeof value === 'string',
|
|
33
|
+
number: (value) => typeof value === 'number',
|
|
34
|
+
boolean: (value) => typeof value === 'boolean',
|
|
35
|
+
array: (value) => Array.isArray(value),
|
|
36
|
+
undefined: (value) => value === undefined,
|
|
37
|
+
null: (value) => value === null,
|
|
38
|
+
object: (value) => typeof value === 'object' && !Array.isArray(value) && value !== null,
|
|
44
39
|
};
|
|
45
|
-
|
|
40
|
+
const makeErrorString = (name, value, type, not) => {
|
|
46
41
|
if (name !== undefined)
|
|
47
|
-
return
|
|
48
|
-
return
|
|
42
|
+
return `- Property "${name}" (value: ${stringifyValue(value)}) is not of type: ${not ? `!(${type})` : type}`;
|
|
43
|
+
return `- ${stringifyValue(value)} is not of type: ${not ? `!(${type})` : type}`;
|
|
49
44
|
};
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
const stringifyValue = (value) => {
|
|
46
|
+
const stringValue = value === undefined || Number.isNaN(value) ? String(value) : JSON.stringify(value);
|
|
52
47
|
return (0, helpers_1.truncateString)(stringValue, 50);
|
|
53
48
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fig-tree-evaluator",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.2",
|
|
4
4
|
"description": "Module to evaluate JSON-structured expression trees",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"build": "yarn generate && rimraf ./build && tsc",
|
|
32
32
|
"dev": "cp -n src/dev/playground_example.ts src/dev/playground.ts || ts-node src/dev/playground.ts",
|
|
33
33
|
"demo": "cd demo && yarn start",
|
|
34
|
-
"
|
|
34
|
+
"prepublishOnly": "yarn build"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"axios": "^0.27.2",
|