survey-expression 0.0.0-stage → 4.5.0

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2020-present Jimmy Chen
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,105 @@
1
- # Temporary Holding Version
1
+ # survey-expression
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![Apache-2.0 licensed][badge-license]][url-license]
4
+ [![NPM version][badge-npm-version]][url-npm]
5
+ [![NPM downloads][badge-npm-downloads]][url-npm]
6
+ [![NPM Unpacked Size (with version)][badge-npm-unpacked-size]][url-npm]
7
+
8
+ It parses and evaluates the survey's expression language: the conditions that show, enable or require a question, the calculated values and the validators, written over a survey's answers. It depends on no SurveyJS, and it is checked against SurveyJS's recorded answers, with every deliberate difference listed.
9
+
10
+ Design notes live in [the specs](https://github.com/Esposter/Esposter/tree/main/openspec/specs/resource/survey-expression).
11
+
12
+ ## Table of Contents
13
+
14
+ - 🚀 [Getting Started](#getting-started)
15
+ - 🧩 [Key Exports](#key-exports)
16
+ - 🧮 [Functions](#functions)
17
+ - ⚖️ [License](#license)
18
+
19
+ ---
20
+
21
+ ## <a name="getting-started">🚀 Getting Started</a>
22
+
23
+ ```bash
24
+ pnpm i survey-expression
25
+ ```
26
+
27
+ ```ts
28
+ import { runSurveyExpression } from "survey-expression";
29
+
30
+ const result = runSurveyExpression("{age} >= 18 and {country} = 'NZ'", {
31
+ now: new Date(),
32
+ scopes: {},
33
+ values: { age: 21, country: "NZ" },
34
+ });
35
+
36
+ result.match(
37
+ (value) => console.log(value), // true
38
+ (error) => console.error(error.message),
39
+ );
40
+ ```
41
+
42
+ - `runSurveyExpression` returns a neverthrow `Result`. A fault in the expression is an error value, never a throw.
43
+ - Answers read from storage pass through `toSurveyLogicAnswers` first, so a stored null reads as unanswered.
44
+
45
+ ## <a name="key-exports">🧩 Key Exports</a>
46
+
47
+ | Export | Kind | Purpose |
48
+ | :-------------------------------------------------------------------------------------------- | :------- | :--------------------------------------------------------------------------------------------------------------------------------------------------- |
49
+ | `checkSurveyExpression` | function | Refuses an expression that does not parse, calls a function the package lacks, or calls an array function's filter form, naming the first such fault |
50
+ | `MAX_SURVEY_EXPRESSION_LENGTH` | constant | The most characters an expression source may hold; a longer source is refused at its first character past the limit, and nothing throws |
51
+ | `parseSurveyExpression` | function | Parses an expression's source into its tree, or into the first fault with the character position it starts at |
52
+ | `runSurveyExpression` | function | Parses a source and evaluates it over a context already read as answers, or returns the parse's fault |
53
+ | `SurveyExpressionNode` | type | A parsed expression, each node told apart by its `type` |
54
+ | `SurveyExpressionNodeType`, `SurveyExpressionBinaryOperator`, `SurveyExpressionUnaryOperator` | enum | The node types and the operators a tree holds |
55
+ | `SurveyLogicContext` | type | What an expression reads: the answers and calculated values, the scopes the caller passes, and the clock the caller passes |
56
+ | `SurveyLogicError` | type | The message and the character position a parse is refused for |
57
+ | `SurveyLogicStoredValue` | type | A value as storage holds it, where a null may appear and reads as unanswered |
58
+ | `SurveyLogicValue` | type | The values an expression reads and computes, where `undefined` is an empty answer |
59
+ | `tokenizeSurveyExpression` | function | Reads an expression's source into its tokens, or returns the first fault |
60
+ | `toSurveyLogicAnswer` | function | Reads one stored value as an answer at every depth, with a stored null read as unanswered |
61
+ | `toSurveyLogicAnswers` | function | Reads a record of stored answers as answers, each at every depth: the one boundary where a stored null reads as unanswered |
62
+
63
+ ## <a name="functions">🧮 Functions</a>
64
+
65
+ Each function is called by its name, written in any case. A call to a name no function has is refused when the expression is checked.
66
+
67
+ | Function | Returns |
68
+ | :------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
69
+ | `age` | The whole years from a birthdate to the clock, or the whole count of the interval it names; undefined for a birthdate after the clock |
70
+ | `avg` | The average of the values passed, arrays flattened |
71
+ | `avgInArray` | The average of a field over the items of an array value |
72
+ | `count` | How many values are passed, arrays flattened |
73
+ | `countInArray` | How many items of an array value hold a value in a field |
74
+ | `dateAdd` | A date moved by an amount of an interval, in days by default; a date moved outside years zero to 9999 has no result |
75
+ | `dateDiff` | The amount of an interval between two dates: calendar days, months or years, or hours, minutes and seconds on the clock |
76
+ | `day` | The day of the month of a date, or of the clock's day when the date is empty |
77
+ | `iif` | The second value when the condition is `true`, otherwise the third |
78
+ | `max` | The largest of the values passed, arrays flattened |
79
+ | `maxInArray` | The largest value of a field over an array's items, or another field of that item |
80
+ | `min` | The smallest of the values passed, arrays flattened |
81
+ | `minInArray` | The smallest value of a field over an array's items, or another field of that item |
82
+ | `month` | The month of a date, from one for January, or of the clock's day when the date is empty |
83
+ | `round` | The number rounded to a number of decimal places, or to a whole number when the precision is empty or absent. A value that reads as no number has no result, and so does a precision that is not a whole number from zero to 100 |
84
+ | `substring` | The part of a text from a start index up to an end index. A start, or a present end, that reads as no number has no result, and an empty or absent end runs to the end of the text |
85
+ | `sum` | The sum of the values passed, arrays flattened |
86
+ | `sumInArray` | The sum of a field over the items of an array value |
87
+ | `today` | The clock's day at midnight, moved by a number of days when one is given |
88
+ | `trunc` | The number cut to a number of decimal places, or to its whole part when the precision is empty or absent. A value that reads as no number has no result, and so does a precision that is not a whole number from zero to 100 |
89
+ | `weekday` | The day of the week of a date, from zero for Sunday |
90
+ | `year` | The year of a date, or of the clock's day when the date is empty |
91
+
92
+ The `...InArray` functions take a field and, optionally, another field of the item to return. A filter, a condition over each item's fields as a last argument, is not supported: `checkSurveyExpression` refuses the call, and `runSurveyExpression` answers empty for it.
93
+
94
+ The functions that read the live survey object, "displayValue", "isContainerReady", "isDisplayMode" and "propertyValue", are deliberately not implemented, since the package has no survey object to read. A call to one is refused by `checkSurveyExpression` as an unknown function, and `runSurveyExpression` answers empty for it.
95
+
96
+ ## <a name="license">⚖️ License</a>
97
+
98
+ Licensed under [Apache-2.0][url-license].
99
+
100
+ [badge-license]: https://img.shields.io/github/license/Esposter/Esposter.svg?color=blue
101
+ [url-license]: https://github.com/Esposter/Esposter/blob/main/LICENSE
102
+ [badge-npm-version]: https://img.shields.io/npm/v/survey-expression/latest?color=brightgreen
103
+ [url-npm]: https://www.npmjs.com/package/survey-expression/v/latest
104
+ [badge-npm-unpacked-size]: https://img.shields.io/npm/unpacked-size/survey-expression/latest?label=npm
105
+ [badge-npm-downloads]: https://img.shields.io/npm/dm/survey-expression.svg
@@ -0,0 +1,259 @@
1
+ import { Result } from "neverthrow";
2
+ export declare enum SurveyExpressionBinaryOperator {
3
+ Add = "add",
4
+ AllOf = "allOf",
5
+ And = "and",
6
+ AnyOf = "anyOf",
7
+ Contains = "contains",
8
+ Divide = "divide",
9
+ Equal = "equal",
10
+ Greater = "greater",
11
+ GreaterOrEqual = "greaterOrEqual",
12
+ Less = "less",
13
+ LessOrEqual = "lessOrEqual",
14
+ Modulo = "modulo",
15
+ Multiply = "multiply",
16
+ NotContains = "notContains",
17
+ NotEqual = "notEqual",
18
+ Or = "or",
19
+ Power = "power",
20
+ Subtract = "subtract"
21
+ }
22
+ export declare enum SurveyExpressionNodeType {
23
+ Binary = "binary",
24
+ Call = "call",
25
+ List = "list",
26
+ Literal = "literal",
27
+ Reference = "reference",
28
+ Unary = "unary"
29
+ }
30
+ export interface SurveyExpressionCallNode {
31
+ args: SurveyExpressionNode[];
32
+ name: string;
33
+ position: number;
34
+ type: SurveyExpressionNodeType.Call;
35
+ }
36
+ export interface SurveyExpressionListNode {
37
+ items: SurveyExpressionNode[];
38
+ position: number;
39
+ type: SurveyExpressionNodeType.List;
40
+ }
41
+ export interface SurveyExpressionLiteralNode {
42
+ position: number;
43
+ type: SurveyExpressionNodeType.Literal;
44
+ value: boolean | number | string;
45
+ }
46
+ export interface SurveyExpressionReferenceNode {
47
+ name: string;
48
+ position: number;
49
+ type: SurveyExpressionNodeType.Reference;
50
+ }
51
+ export declare enum SurveyExpressionUnaryOperator {
52
+ Empty = "empty",
53
+ Negate = "negate",
54
+ Not = "not",
55
+ NotEmpty = "notEmpty"
56
+ }
57
+ export interface SurveyExpressionUnaryNode {
58
+ operand: SurveyExpressionNode;
59
+ operator: SurveyExpressionUnaryOperator;
60
+ position: number;
61
+ type: SurveyExpressionNodeType.Unary;
62
+ }
63
+ export type SurveyExpressionNode = SurveyExpressionBinaryNode | SurveyExpressionCallNode | SurveyExpressionListNode | SurveyExpressionLiteralNode | SurveyExpressionReferenceNode | SurveyExpressionUnaryNode;
64
+ export interface SurveyExpressionBinaryNode {
65
+ left: SurveyExpressionNode;
66
+ operator: SurveyExpressionBinaryOperator;
67
+ position: number;
68
+ right: SurveyExpressionNode;
69
+ type: SurveyExpressionNodeType.Binary;
70
+ }
71
+ export interface SurveyExpressionBinaryOperatorDefinition {
72
+ operator: SurveyExpressionBinaryOperator;
73
+ power: number;
74
+ rightAssociative?: true;
75
+ }
76
+ export interface SurveyLogicRecord extends Record<string, SurveyLogicValue> {}
77
+ export type SurveyLogicValue = boolean | number | string | SurveyLogicRecord | SurveyLogicValue[] | undefined;
78
+ export interface SurveyLogicContext {
79
+ now: Date;
80
+ scopes: Record<string, Record<string, SurveyLogicValue>>;
81
+ values: Record<string, SurveyLogicValue>;
82
+ }
83
+ export type SurveyExpressionEvaluate = (node: SurveyExpressionNode, context: SurveyLogicContext) => SurveyLogicValue;
84
+ export declare enum SurveyExpressionTokenType {
85
+ Boolean = "boolean",
86
+ End = "end",
87
+ Identifier = "identifier",
88
+ Number = "number",
89
+ Operator = "operator",
90
+ Punctuation = "punctuation",
91
+ Reference = "reference",
92
+ String = "string"
93
+ }
94
+ export interface SurveyExpressionToken {
95
+ position: number;
96
+ text: string;
97
+ type: SurveyExpressionTokenType;
98
+ }
99
+ export interface SurveyExpressionParserState {
100
+ index: number;
101
+ tokens: SurveyExpressionToken[];
102
+ }
103
+ export interface SurveyLogicError {
104
+ message: string;
105
+ position: number;
106
+ }
107
+ export type SurveyExpressionParse = (state: SurveyExpressionParserState, minimumPower: number) => Result<SurveyExpressionNode, SurveyLogicError>;
108
+ export interface SurveyExpressionTokenizerState {
109
+ error?: SurveyLogicError;
110
+ index: number;
111
+ source: string;
112
+ tokens: SurveyExpressionToken[];
113
+ }
114
+ export interface SurveyExpressionUnaryOperatorDefinition {
115
+ operator: SurveyExpressionUnaryOperator;
116
+ power: number;
117
+ }
118
+ export interface SurveyLogicArrayRow {
119
+ field: number;
120
+ item: SurveyLogicRecord;
121
+ }
122
+ export interface SurveyLogicArrayParams {
123
+ returnField?: string;
124
+ rows: SurveyLogicArrayRow[];
125
+ }
126
+ export type SurveyLogicFunction = (args: SurveyLogicValue[], context: SurveyLogicContext) => SurveyLogicValue;
127
+ export type SurveyLogicPathMemo = Map<SurveyLogicValue, Map<string, SurveyLogicValue>>;
128
+ export type SurveyLogicStoredValue = boolean | null | number | string | SurveyLogicStoredValue[] | undefined | {
129
+ [name: string]: SurveyLogicStoredValue;
130
+ };
131
+ export declare const checkSurveyExpression: (source: string) => SurveyLogicError | undefined;
132
+ export declare const LOWEST_POWER = 0;
133
+ export declare const MAX_DECIMAL_PLACES = 100;
134
+ export declare const MAX_SURVEY_EXPRESSION_LENGTH = 2e3;
135
+ export declare const PUNCTUATION_CHARACTERS: readonly string[];
136
+ export declare const STRING_QUOTES: readonly string[];
137
+ export declare const SYMBOL_OPERATOR_TEXTS: string[];
138
+ export declare const evaluateSurveyExpression: (node: SurveyExpressionNode, context: SurveyLogicContext) => SurveyLogicValue;
139
+ export declare const evaluateBinary: (node: SurveyExpressionBinaryNode, context: SurveyLogicContext, evaluate: SurveyExpressionEvaluate) => SurveyLogicValue;
140
+ export declare const evaluateCall: (node: SurveyExpressionCallNode, context: SurveyLogicContext, evaluate: SurveyExpressionEvaluate) => SurveyLogicValue;
141
+ export declare const evaluateList: (node: SurveyExpressionListNode, context: SurveyLogicContext, evaluate: SurveyExpressionEvaluate) => SurveyLogicValue[];
142
+ export declare const evaluateReference: (node: SurveyExpressionReferenceNode, context: SurveyLogicContext) => SurveyLogicValue;
143
+ export declare const evaluateUnary: (node: SurveyExpressionUnaryNode, context: SurveyLogicContext, evaluate: SurveyExpressionEvaluate) => SurveyLogicValue;
144
+ export declare const evaluateArithmeticOperator: (operator: SurveyExpressionBinaryOperator.Add | SurveyExpressionBinaryOperator.Divide | SurveyExpressionBinaryOperator.Modulo | SurveyExpressionBinaryOperator.Multiply | SurveyExpressionBinaryOperator.Power | SurveyExpressionBinaryOperator.Subtract, left: SurveyLogicValue, right: SurveyLogicValue) => SurveyLogicValue;
145
+ export declare const evaluateComparisonOperator: (operator: SurveyExpressionBinaryOperator.Equal | SurveyExpressionBinaryOperator.Greater | SurveyExpressionBinaryOperator.GreaterOrEqual | SurveyExpressionBinaryOperator.Less | SurveyExpressionBinaryOperator.LessOrEqual | SurveyExpressionBinaryOperator.NotEqual, left: SurveyLogicValue, right: SurveyLogicValue) => boolean;
146
+ export declare const evaluateLogicOperator: (operator: SurveyExpressionBinaryOperator.And | SurveyExpressionBinaryOperator.Or, left: SurveyLogicValue, right: SurveyLogicValue) => boolean;
147
+ export declare const evaluateMembershipOperator: (operator: SurveyExpressionBinaryOperator.AllOf | SurveyExpressionBinaryOperator.AnyOf | SurveyExpressionBinaryOperator.Contains | SurveyExpressionBinaryOperator.NotContains, left: SurveyLogicValue, right: SurveyLogicValue) => boolean;
148
+ export declare const readMemoizedSurveyLogicPath: (container: SurveyLogicValue, name: string, memo: SurveyLogicPathMemo) => SurveyLogicValue;
149
+ export declare const readSurveyLogicKey: (container: SurveyLogicValue, key: string) => SurveyLogicValue;
150
+ export declare const readSurveyLogicLength: (value: SurveyLogicValue) => number;
151
+ export declare const readSurveyLogicPart: (container: SurveyLogicValue, part: string) => SurveyLogicValue;
152
+ export declare const readSurveyLogicPath: (container: SurveyLogicValue, name: string) => SurveyLogicValue;
153
+ export declare const readSurveyLogicPathUncached: (container: SurveyLogicValue, name: string, readTail: (head: SurveyLogicValue, tail: string) => SurveyLogicValue) => SurveyLogicValue;
154
+ export declare const readSurveyLogicReference: (name: string, context: SurveyLogicContext) => SurveyLogicValue;
155
+ export declare const findSurveyExpressionRefusal: (node: SurveyExpressionNode) => SurveyLogicError | undefined;
156
+ export declare const ageFunction: SurveyLogicFunction;
157
+ export declare const ArrayFunctionMap: Record<string, SurveyLogicFunction>;
158
+ export declare const avgFunction: SurveyLogicFunction;
159
+ export declare const avgInArrayFunction: SurveyLogicFunction;
160
+ export declare const countFunction: SurveyLogicFunction;
161
+ export declare const countInArrayFunction: SurveyLogicFunction;
162
+ export declare const dateAddFunction: SurveyLogicFunction;
163
+ export declare const dateDiffFunction: SurveyLogicFunction;
164
+ export declare const DateFunctionMap: Record<string, SurveyLogicFunction>;
165
+ export declare const dayFunction: SurveyLogicFunction;
166
+ export declare const GeneralFunctionMap: Record<string, SurveyLogicFunction>;
167
+ export declare const iifFunction: SurveyLogicFunction;
168
+ export declare const maxFunction: SurveyLogicFunction;
169
+ export declare const maxInArrayFunction: SurveyLogicFunction;
170
+ export declare const minFunction: SurveyLogicFunction;
171
+ export declare const minInArrayFunction: SurveyLogicFunction;
172
+ export declare const monthFunction: SurveyLogicFunction;
173
+ export declare const roundFunction: SurveyLogicFunction;
174
+ export declare const substringFunction: SurveyLogicFunction;
175
+ export declare const sumFunction: SurveyLogicFunction;
176
+ export declare const sumInArrayFunction: SurveyLogicFunction;
177
+ export declare const SurveyLogicFunctionMap: Record<string, SurveyLogicFunction>;
178
+ export declare const todayFunction: SurveyLogicFunction;
179
+ export declare const truncFunction: SurveyLogicFunction;
180
+ export declare const weekdayFunction: SurveyLogicFunction;
181
+ export declare const yearFunction: SurveyLogicFunction;
182
+ export declare const getCallRefusal: (node: SurveyExpressionCallNode) => string | undefined;
183
+ export declare const getSurveyExpressionChildren: (node: SurveyExpressionNode) => SurveyExpressionNode[];
184
+ export declare const checkIsPunctuation: (token: SurveyExpressionToken, text: string) => boolean;
185
+ export declare const parseBinary: SurveyExpressionParse;
186
+ export declare const parseBinaryOperators: (state: SurveyExpressionParserState, left: SurveyExpressionNode, minimumPower: number, parse: SurveyExpressionParse) => Result<SurveyExpressionNode, SurveyLogicError>;
187
+ export declare const parseCall: (state: SurveyExpressionParserState, parse: SurveyExpressionParse) => Result<SurveyExpressionNode, SurveyLogicError>;
188
+ export declare const parseGroup: (state: SurveyExpressionParserState, parse: SurveyExpressionParse) => Result<SurveyExpressionNode, SurveyLogicError>;
189
+ export declare const parseList: (state: SurveyExpressionParserState, parse: SurveyExpressionParse) => Result<SurveyExpressionNode, SurveyLogicError>;
190
+ export declare const parseOperand: (state: SurveyExpressionParserState, parse: SurveyExpressionParse) => Result<SurveyExpressionNode, SurveyLogicError>;
191
+ export declare const parsePrefixOperator: (state: SurveyExpressionParserState, parse: SurveyExpressionParse) => Result<SurveyExpressionNode, SurveyLogicError>;
192
+ export declare const parseSequence: (state: SurveyExpressionParserState, closing: string, message: string, parse: SurveyExpressionParse) => Result<SurveyExpressionNode[], SurveyLogicError>;
193
+ export declare const parseSequenceItems: (state: SurveyExpressionParserState, closing: string, message: string, parse: SurveyExpressionParse, items: SurveyExpressionNode[]) => Result<SurveyExpressionNode[], SurveyLogicError>;
194
+ export declare const parseSurveyExpression: (source: string) => Result<SurveyExpressionNode, SurveyLogicError>;
195
+ export declare const runSurveyExpression: (source: string, context: SurveyLogicContext) => Result<SurveyLogicValue, SurveyLogicError>;
196
+ export declare const addSurveyLogicMonths: (wallClock: Date, months: number) => void;
197
+ export declare const averageSurveyNumbers: (numbers: number[]) => number | undefined;
198
+ export declare const checkIsCalendarDay: (year: number, month: number, day: number) => boolean;
199
+ export declare const checkIsSurveyFieldName: (text: string) => boolean;
200
+ export declare const checkIsSurveyLogicAllOf: (left: SurveyLogicValue, right: SurveyLogicValue) => boolean;
201
+ export declare const checkIsSurveyLogicAnyOf: (left: SurveyLogicValue, right: SurveyLogicValue) => boolean;
202
+ export declare const checkIsSurveyLogicContaining: (left: SurveyLogicValue, right: SurveyLogicValue) => boolean;
203
+ export declare const checkIsSurveyLogicItemHeld: (haystack: SurveyLogicValue, item: SurveyLogicValue) => boolean;
204
+ export declare const checkIsSurveyLogicLess: (left: SurveyLogicValue, right: SurveyLogicValue) => boolean;
205
+ export declare const checkIsSurveyLogicPrimitiveEqual: (left: SurveyLogicValue, right: SurveyLogicValue) => boolean;
206
+ export declare const checkIsSurveyLogicValueEmpty: (value: SurveyLogicValue) => boolean;
207
+ export declare const checkIsSurveyLogicValueEqual: (left: SurveyLogicValue, right: SurveyLogicValue) => boolean;
208
+ export declare const checkIsSurveyReturnField: (value: unknown) => value is string;
209
+ export declare const compareSurveyLogicTexts: (first: string, second: string) => number;
210
+ export declare const countSurveyLogicDecimals: (number: number) => number;
211
+ export declare const createSurveyLogicWallClock: (year: number, monthIndex: number, day: number, { hour, millisecond, minute, second }?: {
212
+ hour?: number;
213
+ millisecond?: number;
214
+ minute?: number;
215
+ second?: number;
216
+ }) => Date;
217
+ export declare const flattenSurveyNumbers: (values: SurveyLogicValue[]) => number[];
218
+ export declare const getDateDifference: (first: Date, second: Date, unit: string) => number | undefined;
219
+ export declare const getDateOrNow: (value: SurveyLogicValue, now: Date) => Date | undefined;
220
+ export declare const getOwnValue: <T>(record: Readonly<Record<string, T>>, key: string) => T | undefined;
221
+ export declare const getSurveyArrayExtreme: (params: SurveyLogicArrayParams, checkReplaces: (best: number, candidate: number) => boolean) => SurveyLogicValue;
222
+ export declare const getSurveyArrayItems: (data: SurveyLogicValue) => SurveyLogicValue[];
223
+ export declare const getSurveyArrayParams: (args: SurveyLogicValue[]) => SurveyLogicArrayParams | undefined;
224
+ export declare const getSurveyDateUnit: (value: SurveyLogicValue, defaultUnit: string) => string | undefined;
225
+ export declare const getSurveyExtreme: <T>(candidates: T[], checkReplaces: (best: T, candidate: T) => boolean) => T | undefined;
226
+ export declare const getSurveyLogicDayNumber: (wallClock: Date) => number;
227
+ export declare const getSurveyNumberWithPrecision: (args: SurveyLogicValue[]) => [number, number] | undefined;
228
+ export declare const getSurveyOptionalArgument: <T>(value: SurveyLogicValue, defaultValue: T, readArgument: (value: SurveyLogicValue) => T | undefined) => T | undefined;
229
+ export declare const getSurveyTextIndex: (index: number, length: number) => number;
230
+ export declare const mapSurveyLogicValues: <T, U>(record: Record<string, T>, mapValue: (value: T) => U) => Record<string, U>;
231
+ export declare const parseSurveyLogicDate: (value: SurveyLogicValue) => Date | undefined;
232
+ export declare const roundSurveyLogicProduct: (left: number, right: number, product: number) => number;
233
+ export declare const roundSurveyLogicResult: (result: number, digits: number) => number;
234
+ export declare const roundSurveyLogicSum: (left: number, right: number, sum: number) => number;
235
+ export declare const sumSurveyNumbers: (numbers: number[]) => number | undefined;
236
+ export declare const toSurveyLogicAnswer: (value: SurveyLogicStoredValue) => SurveyLogicValue;
237
+ export declare const toSurveyLogicAnswers: (record: Record<string, SurveyLogicStoredValue>) => SurveyLogicRecord;
238
+ export declare const toSurveyLogicDate: (wallClock: Date) => string | undefined;
239
+ export declare const toSurveyLogicNumber: (value: SurveyLogicValue) => number | undefined;
240
+ export declare const toSurveyLogicPrimitive: (value: SurveyLogicValue) => SurveyLogicValue;
241
+ export declare const toSurveyLogicResult: (result: number) => number | undefined;
242
+ export declare const toSurveyLogicText: (value: SurveyLogicValue) => string;
243
+ export declare const toSurveyLogicWallClock: (instant: Date) => Date;
244
+ export declare const SurveyExpressionBinaryOperatorMap: Readonly<Record<string, SurveyExpressionBinaryOperatorDefinition>>;
245
+ export declare const SurveyExpressionPostfixOperatorMap: Readonly<Record<string, SurveyExpressionUnaryOperatorDefinition>>;
246
+ export declare const SurveyExpressionPrefixOperatorMap: Readonly<Record<string, SurveyExpressionUnaryOperatorDefinition>>;
247
+ export declare const advanceSurveyExpressionWhile: (state: SurveyExpressionTokenizerState, checkCharacter: (character: string) => boolean) => void;
248
+ export declare const checkIsSurveyExpressionDigit: (character: string) => boolean;
249
+ export declare const checkIsSurveyExpressionKeyword: (lowercasedWord: string) => boolean;
250
+ export declare const checkIsSurveyExpressionWhitespace: (character: string) => boolean;
251
+ export declare const checkIsSurveyExpressionWordCharacter: (character: string) => boolean;
252
+ export declare const checkIsSurveyExpressionWordStart: (character: string) => boolean;
253
+ export declare const readSurveyExpressionNumber: (state: SurveyExpressionTokenizerState) => void;
254
+ export declare const readSurveyExpressionReference: (state: SurveyExpressionTokenizerState) => void;
255
+ export declare const readSurveyExpressionString: (state: SurveyExpressionTokenizerState) => void;
256
+ export declare const readSurveyExpressionSymbol: (state: SurveyExpressionTokenizerState) => void;
257
+ export declare const readSurveyExpressionToken: (state: SurveyExpressionTokenizerState) => void;
258
+ export declare const readSurveyExpressionWord: (state: SurveyExpressionTokenizerState) => void;
259
+ export declare const tokenizeSurveyExpression: (source: string) => Result<SurveyExpressionToken[], SurveyLogicError>;