fig-tree-evaluator 2.2.0 → 2.2.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.
Files changed (40) hide show
  1. package/README.md +18 -7
  2. package/build/evaluate.js +138 -50
  3. package/build/helpers.d.ts +1 -0
  4. package/build/helpers.js +131 -45
  5. package/build/index.js +82 -28
  6. package/build/operators/_operatorUtils.js +109 -48
  7. package/build/operators/buildObject.js +84 -26
  8. package/build/operators/conditional.js +70 -16
  9. package/build/operators/count.js +48 -14
  10. package/build/operators/customFunctions.js +76 -21
  11. package/build/operators/divide.js +63 -26
  12. package/build/operators/equal.js +57 -23
  13. package/build/operators/getRequest.js +85 -31
  14. package/build/operators/graphQL.js +90 -40
  15. package/build/operators/greaterThan.js +54 -20
  16. package/build/operators/lessThan.js +54 -20
  17. package/build/operators/logicalAnd.js +61 -16
  18. package/build/operators/logicalOr.js +48 -14
  19. package/build/operators/match.js +101 -34
  20. package/build/operators/multiply.js +48 -14
  21. package/build/operators/notEqual.js +57 -23
  22. package/build/operators/objectProperties.js +66 -21
  23. package/build/operators/passThru.js +58 -15
  24. package/build/operators/pgSQL.js +118 -50
  25. package/build/operators/plus.js +70 -24
  26. package/build/operators/postRequest.js +70 -23
  27. package/build/operators/regex.js +70 -24
  28. package/build/operators/split.js +74 -29
  29. package/build/operators/stringSubstitution.js +79 -25
  30. package/build/operators/subtract.js +50 -16
  31. package/build/typeCheck.js +27 -22
  32. package/build/types.d.ts +1 -0
  33. package/package.json +2 -2
  34. package/build/.DS_Store +0 -0
  35. package/build/FigTreeEvaluator.d.ts +0 -13
  36. package/build/FigTreeEvaluator.js +0 -75
  37. package/build/evaluator.d.ts +0 -13
  38. package/build/evaluator.js +0 -75
  39. package/build/operators/objectFunctions.d.ts +0 -9
  40. package/build/operators/objectFunctions.js +0 -38
@@ -1,4 +1,15 @@
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
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,32 +19,68 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
19
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
20
  });
10
21
  };
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
+ };
11
49
  Object.defineProperty(exports, "__esModule", { value: true });
12
50
  exports.POST = void 0;
13
- const _operatorUtils_1 = require("./_operatorUtils");
14
- const getRequest_1 = require("./getRequest");
15
- const requiredProperties = ['url'];
16
- const operatorAliases = ['post'];
17
- const propertyAliases = { endpoint: 'url', outputProperty: 'returnProperty' };
18
- const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
19
- var _a, _b;
20
- const [urlObj, data, returnProperty, headers] = (yield (0, _operatorUtils_1.evaluateArray)([expression.url, expression.parameters, expression.returnProperty, expression.headers], config));
21
- const { url, headers: headersObj } = urlObj instanceof Object ? urlObj : { url: urlObj, headers: null };
22
- config.typeChecker({ name: 'url', value: url, expectedType: 'string' }, { name: 'headers', value: headersObj, expectedType: ['object', 'null'] }, { name: 'data', value: data, expectedType: ['object', 'undefined'] }, { name: 'returnProperty', value: returnProperty, expectedType: ['string', 'undefined'] });
23
- const baseUrl = (_a = config.options.baseEndpoint) !== null && _a !== void 0 ? _a : '';
24
- const httpHeaders = Object.assign(Object.assign(Object.assign({}, (_b = config.options) === null || _b === void 0 ? void 0 : _b.headers), headersObj), headers);
25
- const response = yield (0, _operatorUtils_1.axiosRequest)({
26
- url: (0, _operatorUtils_1.isFullUrl)(url) ? url : (0, _operatorUtils_1.joinUrlParts)(baseUrl, url),
27
- data,
28
- headers: httpHeaders,
29
- method: 'post',
51
+ var _operatorUtils_1 = require("./_operatorUtils");
52
+ var getRequest_1 = require("./getRequest");
53
+ var requiredProperties = ['url'];
54
+ var operatorAliases = ['post'];
55
+ var propertyAliases = { endpoint: 'url', outputProperty: 'returnProperty' };
56
+ var evaluate = function (expression, config) { return __awaiter(void 0, void 0, void 0, function () {
57
+ var _a, urlObj, data, returnProperty, headers, _b, url, headersObj, baseUrl, httpHeaders, response;
58
+ var _c, _d;
59
+ return __generator(this, function (_e) {
60
+ switch (_e.label) {
61
+ case 0: return [4, (0, _operatorUtils_1.evaluateArray)([expression.url, expression.parameters, expression.returnProperty, expression.headers], config)];
62
+ case 1:
63
+ _a = (_e.sent()), urlObj = _a[0], data = _a[1], returnProperty = _a[2], headers = _a[3];
64
+ _b = urlObj instanceof Object ? urlObj : { url: urlObj, headers: null }, url = _b.url, headersObj = _b.headers;
65
+ config.typeChecker({ name: 'url', value: url, expectedType: 'string' }, { name: 'headers', value: headersObj, expectedType: ['object', 'null'] }, { name: 'data', value: data, expectedType: ['object', 'undefined'] }, { name: 'returnProperty', value: returnProperty, expectedType: ['string', 'undefined'] });
66
+ baseUrl = (_c = config.options.baseEndpoint) !== null && _c !== void 0 ? _c : '';
67
+ httpHeaders = __assign(__assign(__assign({}, (_d = config.options) === null || _d === void 0 ? void 0 : _d.headers), headersObj), headers);
68
+ return [4, (0, _operatorUtils_1.axiosRequest)({
69
+ url: (0, _operatorUtils_1.isFullUrl)(url) ? url : (0, _operatorUtils_1.joinUrlParts)(baseUrl, url),
70
+ data: data,
71
+ headers: httpHeaders,
72
+ method: 'post',
73
+ })];
74
+ case 2:
75
+ response = _e.sent();
76
+ return [2, (0, _operatorUtils_1.extractAndSimplify)(response, returnProperty)];
77
+ }
30
78
  });
31
- return (0, _operatorUtils_1.extractAndSimplify)(response, returnProperty);
32
- });
79
+ }); };
33
80
  exports.POST = {
34
- requiredProperties,
35
- operatorAliases,
36
- propertyAliases,
37
- evaluate,
81
+ requiredProperties: requiredProperties,
82
+ operatorAliases: operatorAliases,
83
+ propertyAliases: propertyAliases,
84
+ evaluate: evaluate,
38
85
  parseChildren: getRequest_1.parseChildrenGET,
39
86
  };
@@ -1,4 +1,15 @@
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
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,13 +19,40 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
19
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
20
  });
10
21
  };
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
+ };
11
49
  Object.defineProperty(exports, "__esModule", { value: true });
12
50
  exports.REGEX = void 0;
13
- const _operatorUtils_1 = require("./_operatorUtils");
14
- const helpers_1 = require("../helpers");
15
- const requiredProperties = ['testString', 'pattern'];
16
- const operatorAliases = ['regex', 'patternMatch', 'regexp', 'matchPattern'];
17
- const propertyAliases = {
51
+ var _operatorUtils_1 = require("./_operatorUtils");
52
+ var helpers_1 = require("../helpers");
53
+ var requiredProperties = ['testString', 'pattern'];
54
+ var operatorAliases = ['regex', 'patternMatch', 'regexp', 'matchPattern'];
55
+ var propertyAliases = {
18
56
  string: 'testString',
19
57
  value: 'testString',
20
58
  regex: 'pattern',
@@ -22,25 +60,33 @@ const propertyAliases = {
22
60
  regExp: 'pattern',
23
61
  re: 'pattern',
24
62
  };
25
- const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
26
- const [testString, pattern] = (yield (0, _operatorUtils_1.evaluateArray)([expression.testString, expression.pattern], config));
27
- config.typeChecker({ name: 'testString', value: testString, expectedType: 'string' }, { name: 'pattern', value: pattern, expectedType: 'string' });
28
- try {
29
- const re = new RegExp(pattern);
30
- return re.test(testString);
31
- }
32
- catch (err) {
33
- throw new Error('Regex error:' + (0, helpers_1.errorMessage)(err));
34
- }
35
- });
36
- const parseChildren = (expression) => {
37
- const [testString, pattern] = expression.children;
38
- return Object.assign(Object.assign({}, expression), { testString, pattern });
63
+ var evaluate = function (expression, config) { return __awaiter(void 0, void 0, void 0, function () {
64
+ var _a, testString, pattern, re;
65
+ return __generator(this, function (_b) {
66
+ switch (_b.label) {
67
+ case 0: return [4, (0, _operatorUtils_1.evaluateArray)([expression.testString, expression.pattern], config)];
68
+ case 1:
69
+ _a = (_b.sent()), testString = _a[0], pattern = _a[1];
70
+ config.typeChecker({ name: 'testString', value: testString, expectedType: 'string' }, { name: 'pattern', value: pattern, expectedType: 'string' });
71
+ try {
72
+ re = new RegExp(pattern);
73
+ return [2, re.test(testString)];
74
+ }
75
+ catch (err) {
76
+ throw new Error('Regex error:' + (0, helpers_1.errorMessage)(err));
77
+ }
78
+ return [2];
79
+ }
80
+ });
81
+ }); };
82
+ var parseChildren = function (expression) {
83
+ var _a = expression.children, testString = _a[0], pattern = _a[1];
84
+ return __assign(__assign({}, expression), { testString: testString, pattern: pattern });
39
85
  };
40
86
  exports.REGEX = {
41
- requiredProperties,
42
- operatorAliases,
43
- propertyAliases,
44
- evaluate,
45
- parseChildren,
87
+ requiredProperties: requiredProperties,
88
+ operatorAliases: operatorAliases,
89
+ propertyAliases: propertyAliases,
90
+ evaluate: evaluate,
91
+ parseChildren: parseChildren,
46
92
  };
@@ -1,4 +1,15 @@
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
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,12 +19,39 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
19
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
20
  });
10
21
  };
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
+ };
11
49
  Object.defineProperty(exports, "__esModule", { value: true });
12
50
  exports.SPLIT = void 0;
13
- const _operatorUtils_1 = require("./_operatorUtils");
14
- const requiredProperties = ['value'];
15
- const operatorAliases = ['split', 'arraySplit'];
16
- const propertyAliases = {
51
+ var _operatorUtils_1 = require("./_operatorUtils");
52
+ var requiredProperties = ['value'];
53
+ var operatorAliases = ['split', 'arraySplit'];
54
+ var propertyAliases = {
17
55
  string: 'value',
18
56
  separator: 'delimiter',
19
57
  trim: 'trimWhiteSpace',
@@ -21,31 +59,38 @@ const propertyAliases = {
21
59
  removeTrailing: 'excludeTrailing',
22
60
  excludeTrailingDelimiter: 'excludeTrailing',
23
61
  };
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 });
62
+ var DEFAULT_DELIMITER = ' ';
63
+ var evaluate = function (expression, config) { return __awaiter(void 0, void 0, void 0, function () {
64
+ var _a, value, delimiter, trimWhiteSpace, excludeTrailing, splitValues;
65
+ var _b, _c, _d;
66
+ return __generator(this, function (_e) {
67
+ switch (_e.label) {
68
+ case 0: return [4, (0, _operatorUtils_1.evaluateArray)([
69
+ expression.value,
70
+ (_b = expression.delimiter) !== null && _b !== void 0 ? _b : DEFAULT_DELIMITER,
71
+ (_c = expression.trimWhiteSpace) !== null && _c !== void 0 ? _c : true,
72
+ (_d = expression.excludeTrailing) !== null && _d !== void 0 ? _d : true,
73
+ ], config)];
74
+ case 1:
75
+ _a = (_e.sent()), value = _a[0], delimiter = _a[1], trimWhiteSpace = _a[2], excludeTrailing = _a[3];
76
+ 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' });
77
+ splitValues = value.split(delimiter);
78
+ if (trimWhiteSpace)
79
+ splitValues = splitValues.map(function (val) { return val.trim(); });
80
+ if (excludeTrailing && splitValues[splitValues.length - 1] === '')
81
+ splitValues.pop();
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 });
44
89
  };
45
90
  exports.SPLIT = {
46
- requiredProperties,
47
- operatorAliases,
48
- propertyAliases,
49
- evaluate,
50
- parseChildren,
91
+ requiredProperties: requiredProperties,
92
+ operatorAliases: operatorAliases,
93
+ propertyAliases: propertyAliases,
94
+ evaluate: evaluate,
95
+ parseChildren: parseChildren,
51
96
  };
@@ -1,4 +1,15 @@
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
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,33 +19,76 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
19
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
20
  });
10
21
  };
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
+ };
11
58
  Object.defineProperty(exports, "__esModule", { value: true });
12
59
  exports.STRING_SUBSTITUTION = void 0;
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 });
60
+ var _operatorUtils_1 = require("./_operatorUtils");
61
+ var requiredProperties = ['string', 'substitutions'];
62
+ var operatorAliases = ['stringSubstitution', 'substitute', 'stringSub', 'replace'];
63
+ var propertyAliases = { replacements: 'substitutions' };
64
+ var evaluate = function (expression, config) { return __awaiter(void 0, void 0, void 0, function () {
65
+ var _a, string, substitutions, regex, parameters, uniqueParameters, replacementsObj;
66
+ return __generator(this, function (_b) {
67
+ switch (_b.label) {
68
+ case 0: return [4, (0, _operatorUtils_1.evaluateArray)(__spreadArray([expression.string], expression.substitutions, true), config)];
69
+ case 1:
70
+ _a = (_b.sent()), string = _a[0], substitutions = _a.slice(1);
71
+ config.typeChecker({ name: 'string', value: string, expectedType: 'string' });
72
+ config.typeChecker({ name: 'substitutions', value: substitutions, expectedType: 'array' });
73
+ regex = /(%[\d]+)/g;
74
+ parameters = (string.match(regex) || []).sort(function (a, b) { return Number(a.slice(1)) - Number(b.slice(1)); });
75
+ uniqueParameters = new Set(parameters);
76
+ replacementsObj = (0, _operatorUtils_1.zipArraysToObject)(Array.from(uniqueParameters), substitutions);
77
+ return [2, string
78
+ .split(regex)
79
+ .map(function (fragment) { return (fragment in replacementsObj ? replacementsObj[fragment] : fragment); })
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 });
33
87
  };
34
88
  exports.STRING_SUBSTITUTION = {
35
- requiredProperties,
36
- operatorAliases,
37
- propertyAliases,
38
- evaluate,
39
- parseChildren,
89
+ requiredProperties: requiredProperties,
90
+ operatorAliases: operatorAliases,
91
+ propertyAliases: propertyAliases,
92
+ evaluate: evaluate,
93
+ parseChildren: parseChildren,
40
94
  };
@@ -8,25 +8,59 @@ 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
+ };
11
38
  Object.defineProperty(exports, "__esModule", { value: true });
12
39
  exports.SUBTRACT = void 0;
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* () {
40
+ var logicalAnd_1 = require("./logicalAnd");
41
+ var _operatorUtils_1 = require("./_operatorUtils");
42
+ var requiredProperties = [];
43
+ var operatorAliases = ['-', 'subtract', 'minus', 'takeaway'];
44
+ var propertyAliases = { subtractFrom: 'from' };
45
+ var evaluate = function (expression, config) { return __awaiter(void 0, void 0, void 0, function () {
46
+ var values;
19
47
  var _a;
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
- });
48
+ return __generator(this, function (_b) {
49
+ switch (_b.label) {
50
+ case 0: return [4, (0, _operatorUtils_1.evaluateArray)((_a = expression.values) !== null && _a !== void 0 ? _a : [expression.from, expression.subtract], config)];
51
+ case 1:
52
+ values = (_b.sent());
53
+ config.typeChecker({ name: 'values', value: values, expectedType: 'array' });
54
+ if (values.length < 2)
55
+ throw new Error('- Not enough values provided');
56
+ return [2, values[0] - values[1]];
57
+ }
58
+ });
59
+ }); };
26
60
  exports.SUBTRACT = {
27
- requiredProperties,
28
- operatorAliases,
29
- propertyAliases,
30
- evaluate,
61
+ requiredProperties: requiredProperties,
62
+ operatorAliases: operatorAliases,
63
+ propertyAliases: propertyAliases,
64
+ evaluate: evaluate,
31
65
  parseChildren: logicalAnd_1.parseChildren,
32
66
  };
@@ -1,48 +1,53 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.typeCheck = void 0;
4
- const helpers_1 = require("./helpers");
5
- const typeCheckItem = ({ value, name, not = false, expectedType, }) => {
6
- let result;
4
+ var helpers_1 = require("./helpers");
5
+ var typeCheckItem = function (_a) {
6
+ var value = _a.value, name = _a.name, _b = _a.not, not = _b === void 0 ? false : _b, expectedType = _a.expectedType;
7
+ var result;
7
8
  if (Array.isArray(expectedType)) {
8
- result = expectedType.some((type) => typeCheckItem({ value, name, expectedType: type }) === true);
9
+ result = expectedType.some(function (type) { return typeCheckItem({ value: value, name: name, expectedType: type }) === true; });
9
10
  if (not)
10
11
  result = !result;
11
12
  return result ? true : makeErrorString(name, value, expectedType.join('|'), not);
12
13
  }
13
14
  else {
14
- const checker = typeCheckMap[expectedType];
15
+ var checker = typeCheckMap[expectedType];
15
16
  result = checker(value);
16
17
  if (not)
17
18
  result = !result;
18
19
  return result ? true : makeErrorString(name, value, expectedType, not);
19
20
  }
20
21
  };
21
- const typeCheck = (...args) => {
22
- const errorStrings = [];
23
- args.forEach((item) => {
24
- const result = typeCheckItem(item);
22
+ var typeCheck = function () {
23
+ var args = [];
24
+ for (var _i = 0; _i < arguments.length; _i++) {
25
+ args[_i] = arguments[_i];
26
+ }
27
+ var errorStrings = [];
28
+ args.forEach(function (item) {
29
+ var result = typeCheckItem(item);
25
30
  if (result !== true)
26
31
  errorStrings.push(result);
27
32
  });
28
33
  return errorStrings.length > 0 ? errorStrings.join('\n') : true;
29
34
  };
30
35
  exports.typeCheck = typeCheck;
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,
36
+ var typeCheckMap = {
37
+ string: function (value) { return typeof value === 'string'; },
38
+ number: function (value) { return typeof value === 'number'; },
39
+ boolean: function (value) { return typeof value === 'boolean'; },
40
+ array: function (value) { return Array.isArray(value); },
41
+ undefined: function (value) { return value === undefined; },
42
+ null: function (value) { return value === null; },
43
+ object: function (value) { return typeof value === 'object' && !Array.isArray(value) && value !== null; },
39
44
  };
40
- const makeErrorString = (name, value, type, not) => {
45
+ var makeErrorString = function (name, value, type, not) {
41
46
  if (name !== undefined)
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}`;
47
+ return "- Property \"".concat(name, "\" (value: ").concat(stringifyValue(value), ") is not of type: ").concat(not ? "!(".concat(type, ")") : type);
48
+ return "- ".concat(stringifyValue(value), " is not of type: ").concat(not ? "!(".concat(type, ")") : type);
44
49
  };
45
- const stringifyValue = (value) => {
46
- const stringValue = value === undefined || Number.isNaN(value) ? String(value) : JSON.stringify(value);
50
+ var stringifyValue = function (value) {
51
+ var stringValue = value === undefined || Number.isNaN(value) ? String(value) : JSON.stringify(value);
47
52
  return (0, helpers_1.truncateString)(stringValue, 50);
48
53
  };
package/build/types.d.ts CHANGED
@@ -20,6 +20,7 @@ export interface FigTreeOptions {
20
20
  nullEqualsUndefined?: boolean;
21
21
  allowJSONStringInput?: boolean;
22
22
  skipRuntimeTypeCheck?: boolean;
23
+ evaluateFullObject?: boolean;
23
24
  }
24
25
  export interface FigTreeConfig {
25
26
  options: FigTreeOptions;