fig-tree-evaluator 1.9.0 → 1.9.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 +14 -7
- package/build/helpers.js +7 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ A typical use case would be for evaluating **configuration** files, where you ne
|
|
|
6
6
|
|
|
7
7
|
A range of built-in operators are available, from simple logic, arithmetic and string manipulation, to data fetching from local sources or remote APIs.
|
|
8
8
|
|
|
9
|
-
[**Demo/Playground**](
|
|
9
|
+
[**Demo/Playground**](https://carlosnz.github.io/fig-tree-evaluator/)
|
|
10
10
|
|
|
11
11
|
## Contents <!-- omit in toc -->
|
|
12
12
|
<!-- TOC -->
|
|
@@ -97,7 +97,7 @@ Which would be represented diagramatically with the following expression tree:
|
|
|
97
97
|
|
|
98
98
|

|
|
99
99
|
|
|
100
|
-
A playground for building and testing expressions is available [here](
|
|
100
|
+
A playground for building and testing expressions is available [here](https://carlosnz.github.io/fig-tree-evaluator/)
|
|
101
101
|
|
|
102
102
|
## Install
|
|
103
103
|
|
|
@@ -108,7 +108,7 @@ or\
|
|
|
108
108
|
## Usage
|
|
109
109
|
|
|
110
110
|
```js
|
|
111
|
-
import FigTreeEvaluator from 'fig-tree'
|
|
111
|
+
import FigTreeEvaluator from 'fig-tree-evaluator'
|
|
112
112
|
|
|
113
113
|
// New evaluator instance
|
|
114
114
|
const exp = new FigTreeEvaluator([ options ]) // See available options below
|
|
@@ -145,8 +145,15 @@ You can also retrieve the current options state at any time with:
|
|
|
145
145
|
|
|
146
146
|
`exp.getOptions()`
|
|
147
147
|
|
|
148
|
-
|
|
148
|
+
It's also possible to run one-off evaluations by importing the evaluation method directly rather than using the constructor:
|
|
149
149
|
|
|
150
|
+
```js
|
|
151
|
+
import { evaluateExpression } from 'fig-tree-evaluator'
|
|
152
|
+
|
|
153
|
+
evaluateExpression(expression, [options]).then((result) => {
|
|
154
|
+
// Do something with result
|
|
155
|
+
}
|
|
156
|
+
```
|
|
150
157
|
|
|
151
158
|
## Operator nodes
|
|
152
159
|
|
|
@@ -1206,11 +1213,11 @@ e.g.
|
|
|
1206
1213
|
|
|
1207
1214
|
## More examples
|
|
1208
1215
|
|
|
1209
|
-
More examples, included large, complex expressions can be found within the test suites in the [repository](https://github.com/CarlosNZ/fig-tree).
|
|
1216
|
+
More examples, included large, complex expressions can be found within the test suites in the [repository](https://github.com/CarlosNZ/fig-tree-evaluator).
|
|
1210
1217
|
|
|
1211
1218
|
## Development environment
|
|
1212
1219
|
|
|
1213
|
-
Github repo: https://github.com/CarlosNZ/fig-tree
|
|
1220
|
+
Github repo: https://github.com/CarlosNZ/fig-tree-evaluator
|
|
1214
1221
|
|
|
1215
1222
|
After cloning:
|
|
1216
1223
|
|
|
@@ -1230,4 +1237,4 @@ Individual tests can be run by string matching the argument to the test filename
|
|
|
1230
1237
|
|
|
1231
1238
|
## Help, Feedback, Suggestions
|
|
1232
1239
|
|
|
1233
|
-
Please open an issue: https://github.com/CarlosNZ/fig-tree/issues
|
|
1240
|
+
Please open an issue: https://github.com/CarlosNZ/fig-tree-evaluator/issues
|
package/build/helpers.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.errorMessage = exports.convertOutputMethods = exports.checkRequiredNodes = exports.mapPropertyAliases = exports.fallbackOrError = exports.truncateString = exports.getOperatorName = exports.isOperatorNode = exports.parseIfJson = void 0;
|
|
4
|
-
const
|
|
7
|
+
const mapKeys_1 = __importDefault(require("lodash/mapKeys"));
|
|
8
|
+
const camelCase_1 = __importDefault(require("lodash/camelCase"));
|
|
5
9
|
const parseIfJson = (input) => {
|
|
6
10
|
if (typeof input !== 'string')
|
|
7
11
|
return input;
|
|
@@ -17,7 +21,7 @@ exports.parseIfJson = parseIfJson;
|
|
|
17
21
|
const isOperatorNode = (input) => input instanceof Object && 'operator' in input;
|
|
18
22
|
exports.isOperatorNode = isOperatorNode;
|
|
19
23
|
const standardiseOperatorName = (name) => {
|
|
20
|
-
const camelCaseName = (0,
|
|
24
|
+
const camelCaseName = (0, camelCase_1.default)(name);
|
|
21
25
|
return camelCaseName ? camelCaseName : name;
|
|
22
26
|
};
|
|
23
27
|
const getOperatorName = (operator, operatorAliases) => operatorAliases[standardiseOperatorName(operator)];
|
|
@@ -33,7 +37,7 @@ const fallbackOrError = (fallback, errorMessage, returnErrorAsString = false) =>
|
|
|
33
37
|
throw new Error((0, exports.truncateString)(errorMessage));
|
|
34
38
|
};
|
|
35
39
|
exports.fallbackOrError = fallbackOrError;
|
|
36
|
-
const mapPropertyAliases = (propertyAliases, expression) => (0,
|
|
40
|
+
const mapPropertyAliases = (propertyAliases, expression) => (0, mapKeys_1.default)(expression, (_, key) => key in propertyAliases ? propertyAliases[key] : key);
|
|
37
41
|
exports.mapPropertyAliases = mapPropertyAliases;
|
|
38
42
|
const checkRequiredNodes = (requiredProps, expression) => {
|
|
39
43
|
const missingProps = requiredProps.filter((prop) => !(prop in expression));
|