fig-tree-evaluator 2.0.1 → 2.0.4
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 +2 -7
- package/build/helpers.d.ts +2 -1
- package/build/helpers.js +12 -1
- package/build/index.js +4 -3
- package/build/operators/customFunctions.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -201,7 +201,7 @@ Most of the time named properties is preferable; however there are situations wh
|
|
|
201
201
|
In each operator node, as well as the operator-specific properties, the following two optional properties can be provided:
|
|
202
202
|
|
|
203
203
|
- `fallback`: if the operation throws an error, the `fallback` value will be returned instead. The `fallback` property can be provided at any level of the expression tree and bubbled up from where errors are caught to parent nodes.
|
|
204
|
-
- `outputType` (or `type`): will convert the result of the current node to the specified `outputType`. Valid values are `string`, `number`, `boolean` (or `bool`), and `array`. You can experiment in the [demo app](
|
|
204
|
+
- `outputType` (or `type`): will convert the result of the current node to the specified `outputType`. Valid values are `string`, `number`, `boolean` (or `bool`), and `array`. You can experiment in the [demo app](https://carlosnz.github.io/fig-tree-evaluator/) to see the outcome of applying different `outputType` values to various results.
|
|
205
205
|
|
|
206
206
|
Remember that *all* operator node properties can themselves be operator nodes, *including* the `fallback` and `outputType` properties.
|
|
207
207
|
|
|
@@ -846,11 +846,6 @@ e.g.
|
|
|
846
846
|
`children` array: `[value, delimiter]`
|
|
847
847
|
(`trimWhiteSpace` and `excludeTrailing` not available, since array can only support one optional parameter)
|
|
848
848
|
|
|
849
|
-
- `urlObject`: either a url string, or an object structured as `{url: <string>, headers: <object>}` (if additional headers are required)
|
|
850
|
-
- `parameterKeys`: an array of strings representing the keys of any query parameters
|
|
851
|
-
- `...values`: one value for each key specified in `parameterKeys`
|
|
852
|
-
- `returnProperty` (optional): as above
|
|
853
|
-
|
|
854
849
|
---
|
|
855
850
|
### GET
|
|
856
851
|
|
|
@@ -1250,7 +1245,7 @@ Please open an issue: https://github.com/CarlosNZ/fig-tree-evaluator/issues
|
|
|
1250
1245
|
|
|
1251
1246
|
## Changelog
|
|
1252
1247
|
|
|
1253
|
-
|
|
1248
|
+
- **v2.0.4**: Backwards compatibility for customFunctions (#53)
|
|
1254
1249
|
- **v2.0.1**: Add deep equality comparison for objects/arrayr in =/!= operators
|
|
1255
1250
|
- **v2.0.0**: Re-write as stand-alone package. Major improvements include:
|
|
1256
1251
|
- more [operators](#operator-reference)
|
package/build/helpers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OutputType, EvaluatorNode, CombinedOperatorNode, Operator, EvaluatorOutput } from './types';
|
|
1
|
+
import { OutputType, EvaluatorNode, CombinedOperatorNode, Operator, EvaluatorOutput, FigTreeOptions } from './types';
|
|
2
2
|
export declare const parseIfJson: (input: EvaluatorNode) => any;
|
|
3
3
|
export declare const isOperatorNode: (input: EvaluatorNode) => boolean;
|
|
4
4
|
export declare const getOperatorName: (operator: string, operatorAliases: {
|
|
@@ -10,6 +10,7 @@ export declare const mapPropertyAliases: (propertyAliases: {
|
|
|
10
10
|
[key: string]: string;
|
|
11
11
|
}, expression: CombinedOperatorNode) => CombinedOperatorNode;
|
|
12
12
|
export declare const checkRequiredNodes: (requiredProps: readonly string[], expression: CombinedOperatorNode) => string | false;
|
|
13
|
+
export declare const mergeOptions: (origOptions: FigTreeOptions, newOptions: FigTreeOptions) => FigTreeOptions;
|
|
13
14
|
export declare const convertOutputMethods: {
|
|
14
15
|
[key in OutputType]: <T>(value: T) => EvaluatorOutput | T[];
|
|
15
16
|
};
|
package/build/helpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.errorMessage = exports.convertOutputMethods = exports.checkRequiredNodes = exports.mapPropertyAliases = exports.fallbackOrError = exports.truncateString = exports.getOperatorName = exports.isOperatorNode = exports.parseIfJson = void 0;
|
|
3
|
+
exports.errorMessage = exports.convertOutputMethods = exports.mergeOptions = exports.checkRequiredNodes = exports.mapPropertyAliases = exports.fallbackOrError = exports.truncateString = exports.getOperatorName = exports.isOperatorNode = exports.parseIfJson = void 0;
|
|
4
4
|
const change_case_1 = require("change-case");
|
|
5
5
|
const parseIfJson = (input) => {
|
|
6
6
|
if (typeof input !== 'string')
|
|
@@ -49,6 +49,17 @@ const checkRequiredNodes = (requiredProps, expression) => {
|
|
|
49
49
|
return false;
|
|
50
50
|
};
|
|
51
51
|
exports.checkRequiredNodes = checkRequiredNodes;
|
|
52
|
+
const mergeOptions = (origOptions, newOptions) => {
|
|
53
|
+
const combinedOptions = Object.assign(Object.assign({}, origOptions), newOptions);
|
|
54
|
+
if (origOptions.objects || newOptions.objects)
|
|
55
|
+
combinedOptions.objects = Object.assign(Object.assign({}, origOptions.objects), newOptions.objects);
|
|
56
|
+
if (origOptions.functions || newOptions.functions)
|
|
57
|
+
combinedOptions.functions = Object.assign(Object.assign({}, origOptions.functions), newOptions.functions);
|
|
58
|
+
if (origOptions.headers || newOptions.headers)
|
|
59
|
+
combinedOptions.headers = Object.assign(Object.assign({}, origOptions.headers), newOptions.headers);
|
|
60
|
+
return combinedOptions;
|
|
61
|
+
};
|
|
62
|
+
exports.mergeOptions = mergeOptions;
|
|
52
63
|
exports.convertOutputMethods = {
|
|
53
64
|
number: (value) => extractNumber(value),
|
|
54
65
|
string: (value) => String(value),
|
package/build/index.js
CHANGED
|
@@ -40,6 +40,7 @@ const evaluate_1 = require("./evaluate");
|
|
|
40
40
|
const typeCheck_1 = require("./typeCheck");
|
|
41
41
|
const _operatorAliases_json_1 = __importDefault(require("./operators/_operatorAliases.json"));
|
|
42
42
|
const operators = __importStar(require("./operators"));
|
|
43
|
+
const helpers_1 = require("./helpers");
|
|
43
44
|
class FigTreeEvaluator {
|
|
44
45
|
constructor(options = {}) {
|
|
45
46
|
this.typeChecker = (...args) => {
|
|
@@ -54,12 +55,12 @@ class FigTreeEvaluator {
|
|
|
54
55
|
}
|
|
55
56
|
evaluate(expression, options = {}) {
|
|
56
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
const
|
|
58
|
+
const currentOptions = (0, helpers_1.mergeOptions)(this.options, options);
|
|
58
59
|
return yield (0, evaluate_1.evaluatorFunction)(expression, {
|
|
59
|
-
options:
|
|
60
|
+
options: currentOptions,
|
|
60
61
|
operators: this.operators,
|
|
61
62
|
operatorAliases: this.operatorAliases,
|
|
62
|
-
typeChecker:
|
|
63
|
+
typeChecker: currentOptions.skipRuntimeTypeCheck ? () => { } : this.typeChecker,
|
|
63
64
|
});
|
|
64
65
|
});
|
|
65
66
|
}
|
|
@@ -33,11 +33,11 @@ const propertyAliases = {
|
|
|
33
33
|
variables: 'args',
|
|
34
34
|
};
|
|
35
35
|
const evaluate = (expression, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
-
var _a;
|
|
36
|
+
var _a, _b;
|
|
37
37
|
const [functionPath, ...args] = (yield (0, _operatorUtils_1.evaluateArray)([expression.functionPath, ...(expression.args || [])], config));
|
|
38
38
|
config.typeChecker({ name: 'functionPath', value: functionPath, expectedType: 'string' });
|
|
39
39
|
const { objects, functions } = config.options;
|
|
40
|
-
const func = ((_a = (0, object_property_extractor_1.default)(functions, functionPath, null)) !== null && _a !== void 0 ? _a : (0, object_property_extractor_1.default)(objects, functionPath));
|
|
40
|
+
const func = ((_b = (_a = (0, object_property_extractor_1.default)(functions, functionPath, null)) !== null && _a !== void 0 ? _a : (0, object_property_extractor_1.default)(objects, functionPath, null)) !== null && _b !== void 0 ? _b : (0, object_property_extractor_1.default)(config.options, functionPath));
|
|
41
41
|
return yield func(...args);
|
|
42
42
|
});
|
|
43
43
|
const parseChildren = (expression) => {
|