fig-tree-evaluator
Advanced tools
Comparing version 2.0.1 to 2.0.3
@@ -1,2 +0,2 @@ | ||
import { OutputType, EvaluatorNode, CombinedOperatorNode, Operator, EvaluatorOutput } from './types'; | ||
import { OutputType, EvaluatorNode, CombinedOperatorNode, Operator, EvaluatorOutput, FigTreeOptions } from './types'; | ||
export declare const parseIfJson: (input: EvaluatorNode) => any; | ||
@@ -13,2 +13,3 @@ export declare const isOperatorNode: (input: EvaluatorNode) => boolean; | ||
export declare const checkRequiredNodes: (requiredProps: readonly string[], expression: CombinedOperatorNode) => string | false; | ||
export declare const mergeOptions: (origOptions: FigTreeOptions, newOptions: FigTreeOptions) => FigTreeOptions; | ||
export declare const convertOutputMethods: { | ||
@@ -15,0 +16,0 @@ [key in OutputType]: <T>(value: T) => EvaluatorOutput | T[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.errorMessage = exports.convertOutputMethods = exports.checkRequiredNodes = exports.mapPropertyAliases = exports.fallbackOrError = exports.truncateString = exports.getOperatorName = exports.isOperatorNode = exports.parseIfJson = void 0; | ||
exports.errorMessage = exports.convertOutputMethods = exports.mergeOptions = exports.checkRequiredNodes = exports.mapPropertyAliases = exports.fallbackOrError = exports.truncateString = exports.getOperatorName = exports.isOperatorNode = exports.parseIfJson = void 0; | ||
const change_case_1 = require("change-case"); | ||
@@ -52,2 +52,13 @@ const parseIfJson = (input) => { | ||
exports.checkRequiredNodes = checkRequiredNodes; | ||
const mergeOptions = (origOptions, newOptions) => { | ||
const combinedOptions = Object.assign(Object.assign({}, origOptions), newOptions); | ||
if (origOptions.objects || newOptions.objects) | ||
combinedOptions.objects = Object.assign(Object.assign({}, origOptions.objects), newOptions.objects); | ||
if (origOptions.functions || newOptions.functions) | ||
combinedOptions.functions = Object.assign(Object.assign({}, origOptions.functions), newOptions.functions); | ||
if (origOptions.headers || newOptions.headers) | ||
combinedOptions.headers = Object.assign(Object.assign({}, origOptions.headers), newOptions.headers); | ||
return combinedOptions; | ||
}; | ||
exports.mergeOptions = mergeOptions; | ||
exports.convertOutputMethods = { | ||
@@ -54,0 +65,0 @@ number: (value) => extractNumber(value), |
@@ -43,2 +43,3 @@ "use strict"; | ||
const operators = __importStar(require("./operators")); | ||
const helpers_1 = require("./helpers"); | ||
class FigTreeEvaluator { | ||
@@ -58,8 +59,8 @@ constructor(options = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const instanceOptions = Object.assign(Object.assign({}, this.options), options); | ||
const currentOptions = (0, helpers_1.mergeOptions)(this.options, options); | ||
return yield (0, evaluate_1.evaluatorFunction)(expression, { | ||
options: instanceOptions, | ||
options: currentOptions, | ||
operators: this.operators, | ||
operatorAliases: this.operatorAliases, | ||
typeChecker: instanceOptions.skipRuntimeTypeCheck ? () => { } : this.typeChecker, | ||
typeChecker: currentOptions.skipRuntimeTypeCheck ? () => { } : this.typeChecker, | ||
}); | ||
@@ -66,0 +67,0 @@ }); |
{ | ||
"name": "fig-tree-evaluator", | ||
"version": "2.0.1", | ||
"version": "2.0.3", | ||
"description": "Module to evaluate JSON-structured expression trees", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -204,3 +204,3 @@ # fig-tree-evaluator | ||
- `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. | ||
- `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. | ||
- `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. | ||
@@ -207,0 +207,0 @@ Remember that *all* operator node properties can themselves be operator nodes, *including* the `fallback` and `outputType` properties. |
141753
1975