fig-tree-evaluator 2.0.1 → 2.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/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](LINK) to see the outcome of applying different `outputType` values to various results.
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
 
@@ -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 instanceOptions = Object.assign(Object.assign({}, this.options), options);
58
+ const currentOptions = (0, helpers_1.mergeOptions)(this.options, options);
58
59
  return yield (0, evaluate_1.evaluatorFunction)(expression, {
59
- options: instanceOptions,
60
+ options: currentOptions,
60
61
  operators: this.operators,
61
62
  operatorAliases: this.operatorAliases,
62
- typeChecker: instanceOptions.skipRuntimeTypeCheck ? () => { } : this.typeChecker,
63
+ typeChecker: currentOptions.skipRuntimeTypeCheck ? () => { } : this.typeChecker,
63
64
  });
64
65
  });
65
66
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fig-tree-evaluator",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "Module to evaluate JSON-structured expression trees",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",