@math.gl/expressions 4.2.0-alpha.5

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 (42) hide show
  1. package/LICENSE +140 -0
  2. package/README.md +12 -0
  3. package/dist/dggs.cjs +54 -0
  4. package/dist/dggs.cjs.map +6 -0
  5. package/dist/dggs.d.ts +18 -0
  6. package/dist/dggs.d.ts.map +1 -0
  7. package/dist/dggs.js +42 -0
  8. package/dist/dggs.js.map +1 -0
  9. package/dist/expression-eval.d.ts +103 -0
  10. package/dist/expression-eval.d.ts.map +1 -0
  11. package/dist/expression-eval.js +298 -0
  12. package/dist/expression-eval.js.map +1 -0
  13. package/dist/function-libraries.d.ts +75 -0
  14. package/dist/function-libraries.d.ts.map +1 -0
  15. package/dist/function-libraries.js +98 -0
  16. package/dist/function-libraries.js.map +1 -0
  17. package/dist/function-registry.d.ts +93 -0
  18. package/dist/function-registry.d.ts.map +1 -0
  19. package/dist/function-registry.js +131 -0
  20. package/dist/function-registry.js.map +1 -0
  21. package/dist/get.d.ts +9 -0
  22. package/dist/get.d.ts.map +1 -0
  23. package/dist/get.js +32 -0
  24. package/dist/get.js.map +1 -0
  25. package/dist/index.cjs +473 -0
  26. package/dist/index.cjs.map +6 -0
  27. package/dist/index.d.ts +7 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +8 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/parse-expression-string.d.ts +21 -0
  32. package/dist/parse-expression-string.d.ts.map +1 -0
  33. package/dist/parse-expression-string.js +61 -0
  34. package/dist/parse-expression-string.js.map +1 -0
  35. package/package.json +50 -0
  36. package/src/dggs.ts +62 -0
  37. package/src/expression-eval.ts +426 -0
  38. package/src/function-libraries.ts +168 -0
  39. package/src/function-registry.ts +163 -0
  40. package/src/get.ts +37 -0
  41. package/src/index.ts +26 -0
  42. package/src/parse-expression-string.ts +80 -0
package/LICENSE ADDED
@@ -0,0 +1,140 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Uber Technologies, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
23
+ ---
24
+
25
+ Some primitive tessellation approaches were originally inspired by the TDL WebGL samples under
26
+ the New BSD License:
27
+
28
+ Copyright (c) 2011, Google Inc. All rights reserved.
29
+
30
+ Redistribution and use in source and binary forms, with or without modification, are permitted
31
+ provided that the following conditions are met:
32
+
33
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions
34
+ and the following disclaimer.
35
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of
36
+ conditions and the following disclaimer in the documentation and/or other materials provided
37
+ with the distribution.
38
+ 3. Neither the name of Google Inc. nor the names of its contributors may be used to endorse or
39
+ promote products derived from this software without specific prior written permission.
40
+
41
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
42
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
43
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
44
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
46
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
47
+ IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
48
+ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49
+
50
+ ---
51
+
52
+ math.gl builds on docs and code from "gl-matrix", which is MIT licensed as follows:
53
+
54
+ Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.
55
+
56
+ Permission is hereby granted, free of charge, to any person obtaining a copy
57
+ of this software and associated documentation files (the "Software"), to deal
58
+ in the Software without restriction, including without limitation the rights
59
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
60
+ copies of the Software, and to permit persons to whom the Software is
61
+ furnished to do so, subject to the following conditions:
62
+
63
+ The above copyright notice and this permission notice shall be included in
64
+ all copies or substantial portions of the Software.
65
+
66
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
67
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
68
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
69
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
70
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
71
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
72
+ THE SOFTWARE.
73
+
74
+ --
75
+
76
+ math.gl builds on docs and code from THREE.js, which is MIT licensed as follows:
77
+
78
+ The MIT License
79
+
80
+ Copyright © 2010-2017 three.js authors
81
+
82
+ Permission is hereby granted, free of charge, to any person obtaining a copy
83
+ of this software and associated documentation files (the "Software"), to deal
84
+ in the Software without restriction, including without limitation the rights
85
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
86
+ copies of the Software, and to permit persons to whom the Software is
87
+ furnished to do so, subject to the following conditions:
88
+
89
+ The above copyright notice and this permission notice shall be included in
90
+ all copies or substantial portions of the Software.
91
+
92
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
93
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
94
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
95
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
96
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
97
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
98
+ THE SOFTWARE.
99
+
100
+ ---
101
+
102
+ math.gl includes certain files from Cesium (https://github.com/AnalyticalGraphicsInc/cesium) under the Apache 2 License:
103
+
104
+ Copyright 2011-2018 CesiumJS Contributors
105
+
106
+ Licensed under the Apache License, Version 2.0 (the "License");
107
+ you may not use this file except in compliance with the License.
108
+ You may obtain a copy of the License at
109
+ http://www.apache.org/licenses/LICENSE-2.0
110
+
111
+ Unless required by applicable law or agreed to in writing, software
112
+ distributed under the License is distributed on an "AS IS" BASIS,
113
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
114
+ See the License for the specific language governing permissions and limitations under the License.
115
+
116
+ Cesium-derived code can be found in the submodule: modules/3d-tiles
117
+
118
+ ---
119
+
120
+ The @math.gl/geometry primitive tessellators are adapted from luma.gl under the MIT License:
121
+
122
+ Copyright (c) 2020 vis.gl contributors
123
+
124
+ Permission is hereby granted, free of charge, to any person obtaining a copy
125
+ of this software and associated documentation files (the "Software"), to deal
126
+ in the Software without restriction, including without limitation the rights
127
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
128
+ copies of the Software, and to permit persons to whom the Software is
129
+ furnished to do so, subject to the following conditions:
130
+
131
+ The above copyright notice and this permission notice shall be included in
132
+ all copies or substantial portions of the Software.
133
+
134
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
135
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
136
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
137
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
138
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
139
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
140
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # @math.gl/expressions
2
+
3
+ [![From v4.2](https://img.shields.io/badge/From-v4.2-blue.svg?style=flat-square)](https://math.gl/docs)
4
+ [![Experimental](https://img.shields.io/badge/Status-Experimental-orange.svg?style=flat-square)](https://math.gl/docs)
5
+
6
+ [math.gl](https://math.gl/docs) expression parsing and evaluation helpers.
7
+
8
+ This experimental module, available from math.gl v4.2, contains a small expression parser and accessor compiler.
9
+
10
+ It includes an instance-scoped function registry and built-in basic math and WGS84 function tables. Optional GeoHash, Quadkey, and S2 tables are exported from `@math.gl/expressions/dggs`.
11
+
12
+ For documentation please visit the [website](https://math.gl).
package/dist/dggs.cjs ADDED
@@ -0,0 +1,54 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // dist/dggs.js
20
+ var dggs_exports = {};
21
+ __export(dggs_exports, {
22
+ DGGS_FUNCTION_LIBRARY: () => DGGS_FUNCTION_LIBRARY,
23
+ GEOHASH_FUNCTION_LIBRARY: () => GEOHASH_FUNCTION_LIBRARY,
24
+ QUADKEY_FUNCTION_LIBRARY: () => QUADKEY_FUNCTION_LIBRARY,
25
+ S2_FUNCTION_LIBRARY: () => S2_FUNCTION_LIBRARY
26
+ });
27
+ module.exports = __toCommonJS(dggs_exports);
28
+ var import_dggs_geohash = require("@math.gl/dggs-geohash");
29
+ var import_dggs_quadkey = require("@math.gl/dggs-quadkey");
30
+ var import_dggs_s2 = require("@math.gl/dggs-s2");
31
+ var GEOHASH_FUNCTION_LIBRARY = {
32
+ getGeohashBoundary: import_dggs_geohash.getGeohashBoundary,
33
+ getGeohashBoundaryFlat: import_dggs_geohash.getGeohashBoundaryFlat,
34
+ getGeohashBounds: import_dggs_geohash.getGeohashBounds,
35
+ getGeohashLngLat: import_dggs_geohash.getGeohashLngLat
36
+ };
37
+ var QUADKEY_FUNCTION_LIBRARY = {
38
+ getQuadkeyBoundary: import_dggs_quadkey.getQuadkeyBoundary,
39
+ getQuadkeyBoundaryFlat: import_dggs_quadkey.getQuadkeyBoundaryFlat,
40
+ getQuadkeyLngLat: import_dggs_quadkey.getQuadkeyLngLat,
41
+ quadkeyToWorldBounds: import_dggs_quadkey.quadkeyToWorldBounds
42
+ };
43
+ var S2_FUNCTION_LIBRARY = {
44
+ getS2BoundaryFlat: import_dggs_s2.getS2BoundaryFlat,
45
+ getS2ChildIndex: import_dggs_s2.getS2ChildIndex,
46
+ getS2IndexFromToken: import_dggs_s2.getS2IndexFromToken,
47
+ getS2TokenFromIndex: import_dggs_s2.getS2TokenFromIndex
48
+ };
49
+ var DGGS_FUNCTION_LIBRARY = {
50
+ ...GEOHASH_FUNCTION_LIBRARY,
51
+ ...QUADKEY_FUNCTION_LIBRARY,
52
+ ...S2_FUNCTION_LIBRARY
53
+ };
54
+ //# sourceMappingURL=dggs.cjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/dggs.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;AAIA,0BAKO;AACP,0BAKO;AACP,qBAKO;AAMA,IAAM,2BAAsD;EACjE;EACA;EACA;EACA;;AAMK,IAAM,2BAAsD;EACjE;EACA;EACA;EACA;;AAMK,IAAM,sBAAiD;EAC5D;EACA;EACA;EACA;;AAMK,IAAM,wBAAmD;EAC9D,GAAG;EACH,GAAG;EACH,GAAG;;",
5
+ "names": []
6
+ }
package/dist/dggs.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { ExpressionFunctionLibrary } from "./function-libraries.js";
2
+ /**
3
+ * GeoHash functions ready to register with an expression evaluator.
4
+ */
5
+ export declare const GEOHASH_FUNCTION_LIBRARY: ExpressionFunctionLibrary;
6
+ /**
7
+ * Quadkey functions ready to register with an expression evaluator.
8
+ */
9
+ export declare const QUADKEY_FUNCTION_LIBRARY: ExpressionFunctionLibrary;
10
+ /**
11
+ * S2 functions ready to register with an expression evaluator.
12
+ */
13
+ export declare const S2_FUNCTION_LIBRARY: ExpressionFunctionLibrary;
14
+ /**
15
+ * Combined GeoHash, Quadkey, and S2 function table.
16
+ */
17
+ export declare const DGGS_FUNCTION_LIBRARY: ExpressionFunctionLibrary;
18
+ //# sourceMappingURL=dggs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dggs.d.ts","sourceRoot":"","sources":["../src/dggs.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAC,yBAAyB,EAAC,gCAA6B;AAEpE;;GAEG;AACH,eAAO,MAAM,wBAAwB,EAAE,yBAKtC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,EAAE,yBAKtC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,yBAKjC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,yBAInC,CAAC"}
package/dist/dggs.js ADDED
@@ -0,0 +1,42 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { getGeohashBoundary, getGeohashBoundaryFlat, getGeohashBounds, getGeohashLngLat } from '@math.gl/dggs-geohash';
5
+ import { getQuadkeyBoundary, getQuadkeyBoundaryFlat, getQuadkeyLngLat, quadkeyToWorldBounds } from '@math.gl/dggs-quadkey';
6
+ import { getS2BoundaryFlat, getS2ChildIndex, getS2IndexFromToken, getS2TokenFromIndex } from '@math.gl/dggs-s2';
7
+ /**
8
+ * GeoHash functions ready to register with an expression evaluator.
9
+ */
10
+ export const GEOHASH_FUNCTION_LIBRARY = {
11
+ getGeohashBoundary,
12
+ getGeohashBoundaryFlat,
13
+ getGeohashBounds,
14
+ getGeohashLngLat
15
+ };
16
+ /**
17
+ * Quadkey functions ready to register with an expression evaluator.
18
+ */
19
+ export const QUADKEY_FUNCTION_LIBRARY = {
20
+ getQuadkeyBoundary,
21
+ getQuadkeyBoundaryFlat,
22
+ getQuadkeyLngLat,
23
+ quadkeyToWorldBounds
24
+ };
25
+ /**
26
+ * S2 functions ready to register with an expression evaluator.
27
+ */
28
+ export const S2_FUNCTION_LIBRARY = {
29
+ getS2BoundaryFlat,
30
+ getS2ChildIndex,
31
+ getS2IndexFromToken,
32
+ getS2TokenFromIndex
33
+ };
34
+ /**
35
+ * Combined GeoHash, Quadkey, and S2 function table.
36
+ */
37
+ export const DGGS_FUNCTION_LIBRARY = {
38
+ ...GEOHASH_FUNCTION_LIBRARY,
39
+ ...QUADKEY_FUNCTION_LIBRARY,
40
+ ...S2_FUNCTION_LIBRARY
41
+ };
42
+ //# sourceMappingURL=dggs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dggs.js","sourceRoot":"","sources":["../src/dggs.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;AAG1B;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAA8B;IACjE,kBAAkB;IAClB,sBAAsB;IACtB,gBAAgB;IAChB,gBAAgB;CACjB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAA8B;IACjE,kBAAkB;IAClB,sBAAsB;IACtB,gBAAgB;IAChB,oBAAoB;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAA8B;IAC5D,iBAAiB;IACjB,eAAe;IACf,mBAAmB;IACnB,mBAAmB;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAA8B;IAC9D,GAAG,wBAAwB;IAC3B,GAAG,wBAAwB;IAC3B,GAAG,mBAAmB;CACvB,CAAC"}
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Sources:
3
+ * - Copyright (c) 2013 Stephen Oney, http://jsep.from.so/, MIT License
4
+ * - Copyright (c) 2023 Don McCurdy, https://github.com/donmccurdy/expression-eval, MIT License
5
+ */
6
+ import jsep from 'jsep';
7
+ import { type ExpressionEvaluationOptions } from "./function-libraries.js";
8
+ /**
9
+ * Named values and functions available while evaluating an expression.
10
+ */
11
+ export type ExpressionContext = Record<string, unknown>;
12
+ /**
13
+ * A JSEP abstract syntax tree node supported by the evaluator.
14
+ */
15
+ export type Expression = jsep.ArrayExpression | jsep.BinaryExpression | jsep.CallExpression | jsep.ConditionalExpression | jsep.Identifier | jsep.Literal | jsep.MemberExpression | jsep.ThisExpression | jsep.UnaryExpression;
16
+ /**
17
+ * Evaluator implementation for a custom unary operator.
18
+ *
19
+ * @param operand - Value produced by the operator's operand expression.
20
+ * @returns The operator result.
21
+ */
22
+ export type UnaryOperator = (operand: any) => any;
23
+ /**
24
+ * Evaluator implementation for a custom binary operator.
25
+ *
26
+ * @param left - Value produced by the left operand expression.
27
+ * @param right - Value produced by the right operand expression.
28
+ * @returns The operator result.
29
+ */
30
+ export type BinaryOperator = (left: any, right: any) => any;
31
+ /** Evaluates one expression node synchronously. */
32
+ declare function evaluateExpression(node: jsep.Expression, context: ExpressionContext, options?: ExpressionEvaluationOptions): unknown;
33
+ /**
34
+ * Evaluates a parsed expression asynchronously.
35
+ *
36
+ * @param node - Expression AST to evaluate.
37
+ * @param context - Named values and functions available to the expression.
38
+ * @param options - Function libraries to add to the context.
39
+ * @returns The resolved expression value.
40
+ *
41
+ * @remarks
42
+ * Function calls are awaited, including calls nested inside arrays, member
43
+ * expressions, conditionals, unary expressions, and binary expressions.
44
+ */
45
+ export declare function evalAsync(node: jsep.Expression, context: ExpressionContext, options?: ExpressionEvaluationOptions): Promise<unknown>;
46
+ /**
47
+ * Compiles an expression into a reusable synchronous evaluator.
48
+ *
49
+ * @param expression - Expression source or a previously parsed AST.
50
+ * @param options - Function libraries to add to each evaluation context.
51
+ * @returns A function that evaluates the expression against a context.
52
+ */
53
+ export declare function compile(expression: string | jsep.Expression, options?: ExpressionEvaluationOptions): (context: ExpressionContext) => unknown;
54
+ /**
55
+ * Compiles an expression into a reusable asynchronous evaluator.
56
+ *
57
+ * @param expression - Expression source or a previously parsed AST.
58
+ * @param options - Function libraries to add to each evaluation context.
59
+ * @returns A function that asynchronously evaluates the expression.
60
+ */
61
+ export declare function compileAsync(expression: string | jsep.Expression, options?: ExpressionEvaluationOptions): (context: ExpressionContext) => Promise<unknown>;
62
+ /**
63
+ * Registers a custom unary operator with the parser and evaluator.
64
+ *
65
+ * @param operator - Operator token to register.
66
+ * @param fn - Evaluator implementation for the operator.
67
+ *
68
+ * @remarks
69
+ * Registration changes module-global parser state and affects subsequent
70
+ * calls to {@link parse}.
71
+ */
72
+ export declare function addUnaryOp(operator: string, fn: UnaryOperator): void;
73
+ /**
74
+ * Registers a custom binary operator with the parser and evaluator.
75
+ *
76
+ * @param operator - Operator token to register.
77
+ * @param precedenceOrFn - Parser precedence, or the evaluator implementation
78
+ * when using the default precedence for a built-in operator.
79
+ * @param fn - Evaluator implementation when an explicit precedence is given.
80
+ *
81
+ * @remarks
82
+ * Registration changes module-global parser state and affects subsequent
83
+ * calls to {@link parse}. New operators should provide explicit precedence.
84
+ */
85
+ export declare function addBinaryOp(operator: string, precedenceOrFn: number | BinaryOperator, fn?: BinaryOperator): void;
86
+ /**
87
+ * Parses expression source into a JSEP abstract syntax tree.
88
+ *
89
+ * @param expression - Expression source or an existing AST.
90
+ * @returns A parsed AST, or the supplied AST unchanged.
91
+ * @throws If the expression string is not valid JSEP syntax.
92
+ */
93
+ export declare function parse(expression: string | jsep.Expression): jsep.Expression;
94
+ /**
95
+ * Evaluates a parsed expression synchronously.
96
+ *
97
+ * @param node - Expression AST to evaluate.
98
+ * @param context - Named values and functions available to the expression.
99
+ * @param options - Function libraries to add to the context.
100
+ * @returns The expression value.
101
+ */
102
+ export { evaluateExpression as eval };
103
+ //# sourceMappingURL=expression-eval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expression-eval.d.ts","sourceRoot":"","sources":["../src/expression-eval.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AAGH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAyB,KAAK,2BAA2B,EAAC,gCAA6B;AAE9F;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAExD;;GAEG;AACH,MAAM,MAAM,UAAU,GAClB,IAAI,CAAC,eAAe,GACpB,IAAI,CAAC,gBAAgB,GACrB,IAAI,CAAC,cAAc,GACnB,IAAI,CAAC,qBAAqB,GAC1B,IAAI,CAAC,UAAU,GACf,IAAI,CAAC,OAAO,GACZ,IAAI,CAAC,gBAAgB,GACrB,IAAI,CAAC,cAAc,GACnB,IAAI,CAAC,eAAe,CAAC;AAEzB;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,GAAG,KAAK,GAAG,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;AAqH5D,mDAAmD;AAEnD,iBAAS,kBAAkB,CACzB,IAAI,EAAE,IAAI,CAAC,UAAU,EACrB,OAAO,EAAE,iBAAiB,EAC1B,OAAO,CAAC,EAAE,2BAA2B,GACpC,OAAO,CAkET;AAOD;;;;;;;;;;;GAWG;AAEH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,IAAI,CAAC,UAAU,EACrB,OAAO,EAAE,iBAAiB,EAC1B,OAAO,CAAC,EAAE,2BAA2B,GACpC,OAAO,CAAC,OAAO,CAAC,CAuElB;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CACrB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC,UAAU,EACpC,OAAO,CAAC,EAAE,2BAA2B,GACpC,CAAC,OAAO,EAAE,iBAAiB,KAAK,OAAO,CAGzC;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC,UAAU,EACpC,OAAO,CAAC,EAAE,2BAA2B,GACpC,CAAC,OAAO,EAAE,iBAAiB,KAAK,OAAO,CAAC,OAAO,CAAC,CAGlD;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,aAAa,GAAG,IAAI,CAGpE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,GAAG,cAAc,EACvC,EAAE,CAAC,EAAE,cAAc,GAClB,IAAI,CASN;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAE3E;AAED;;;;;;;GAOG;AACH,OAAO,EAAC,kBAAkB,IAAI,IAAI,EAAC,CAAC"}