amis-formula 2.8.0 → 3.0.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/esm/doc.js +1 -1
- package/esm/error.d.ts +6 -0
- package/esm/error.js +21 -0
- package/esm/evalutor.d.ts +4 -0
- package/esm/evalutor.js +4 -3
- package/esm/evalutorForAsync.d.ts +281 -0
- package/esm/evalutorForAsync.js +1070 -0
- package/esm/filter.js +1 -1
- package/esm/function.js +1 -1
- package/esm/index.d.ts +3 -1
- package/esm/index.js +18 -2
- package/esm/lexer.js +1 -1
- package/esm/parser.js +1 -1
- package/lib/doc.js +1 -1
- package/lib/error.d.ts +6 -0
- package/lib/error.js +25 -0
- package/lib/evalutor.d.ts +4 -0
- package/lib/evalutor.js +7 -2
- package/lib/evalutorForAsync.d.ts +281 -0
- package/lib/evalutorForAsync.js +1075 -0
- package/lib/filter.js +1 -1
- package/lib/function.js +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.js +18 -1
- package/lib/lexer.js +1 -1
- package/lib/parser.js +1 -1
- package/package.json +2 -2
package/esm/doc.js
CHANGED
package/esm/error.d.ts
ADDED
package/esm/error.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* amis-formula v3.0.0
|
|
3
|
+
* Copyright 2021-2023 fex
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { __extends } from 'tslib';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 表达式解析错误
|
|
10
|
+
*/
|
|
11
|
+
var FormulaEvalError = /** @class */ (function (_super) {
|
|
12
|
+
__extends(FormulaEvalError, _super);
|
|
13
|
+
function FormulaEvalError(message) {
|
|
14
|
+
var _this = _super.call(this, message) || this;
|
|
15
|
+
_this.name = 'FormulaEvalError';
|
|
16
|
+
return _this;
|
|
17
|
+
}
|
|
18
|
+
return FormulaEvalError;
|
|
19
|
+
}(Error));
|
|
20
|
+
|
|
21
|
+
export { FormulaEvalError };
|
package/esm/evalutor.d.ts
CHANGED
|
@@ -1282,6 +1282,10 @@ export declare class Evaluator {
|
|
|
1282
1282
|
*/
|
|
1283
1283
|
fnISTYPE(target: any, type: 'string' | 'number' | 'array' | 'date' | 'plain-object' | 'nil'): boolean;
|
|
1284
1284
|
}
|
|
1285
|
+
export declare function getCookie(name: string): string | undefined;
|
|
1286
|
+
export declare function parseJson(str: string, defaultValue?: any): any;
|
|
1287
|
+
export declare function stripNumber(number: number): number;
|
|
1288
|
+
export declare function normalizeArgs(args: Array<any>): any[];
|
|
1285
1289
|
export declare function createObject(superProps?: {
|
|
1286
1290
|
[propName: string]: any;
|
|
1287
1291
|
}, props?: {
|
package/esm/evalutor.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-formula
|
|
2
|
+
* amis-formula v3.0.0
|
|
3
3
|
* Copyright 2021-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -15,6 +15,7 @@ import uniqBy from 'lodash/uniqBy';
|
|
|
15
15
|
import isEqual from 'lodash/isEqual';
|
|
16
16
|
import isPlainObject from 'lodash/isPlainObject';
|
|
17
17
|
import get from 'lodash/get';
|
|
18
|
+
import { FormulaEvalError } from './error.js';
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* @file 公式内置函数
|
|
@@ -366,7 +367,7 @@ var Evaluator = /** @class */ (function () {
|
|
|
366
367
|
(this.filters.hasOwnProperty(ast.identifier) &&
|
|
367
368
|
this.filters[ast.identifier]);
|
|
368
369
|
if (!fn) {
|
|
369
|
-
throw new
|
|
370
|
+
throw new FormulaEvalError("".concat(ast.identifier, "\u51FD\u6570\u6CA1\u6709\u5B9A\u4E49"));
|
|
370
371
|
}
|
|
371
372
|
var args = ast.args;
|
|
372
373
|
// 逻辑函数特殊处理,因为有时候有些运算是可以跳过的。
|
|
@@ -2166,4 +2167,4 @@ function createObject(superProps, props, properties) {
|
|
|
2166
2167
|
return obj;
|
|
2167
2168
|
}
|
|
2168
2169
|
|
|
2169
|
-
export { Evaluator, createObject };
|
|
2170
|
+
export { Evaluator, createObject, getCookie, normalizeArgs, parseJson, stripNumber };
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
export declare function runSequence<T, U>(arr: Array<T>, fn: (item: T, index: number) => Promise<U>): Promise<U[]>;
|
|
2
|
+
declare const AsyncEvaluator_base: any;
|
|
3
|
+
export declare class AsyncEvaluator extends AsyncEvaluator_base {
|
|
4
|
+
constructor(data: any, options?: any);
|
|
5
|
+
document(ast: {
|
|
6
|
+
type: 'document';
|
|
7
|
+
body: Array<any>;
|
|
8
|
+
}): Promise<any>;
|
|
9
|
+
filter(ast: {
|
|
10
|
+
type: 'filter';
|
|
11
|
+
input: any;
|
|
12
|
+
filters: Array<{
|
|
13
|
+
name: string;
|
|
14
|
+
args: Array<any>;
|
|
15
|
+
}>;
|
|
16
|
+
}): Promise<any>;
|
|
17
|
+
template(ast: {
|
|
18
|
+
type: 'template';
|
|
19
|
+
body: Array<any>;
|
|
20
|
+
}): Promise<string>;
|
|
21
|
+
getter(ast: {
|
|
22
|
+
host: any;
|
|
23
|
+
key: any;
|
|
24
|
+
}): Promise<any>;
|
|
25
|
+
unary(ast: {
|
|
26
|
+
op: '+' | '-' | '~' | '!';
|
|
27
|
+
value: any;
|
|
28
|
+
}): Promise<number | boolean>;
|
|
29
|
+
power(ast: {
|
|
30
|
+
left: any;
|
|
31
|
+
right: any;
|
|
32
|
+
}): Promise<number>;
|
|
33
|
+
multiply(ast: {
|
|
34
|
+
left: any;
|
|
35
|
+
right: any;
|
|
36
|
+
}): Promise<number>;
|
|
37
|
+
divide(ast: {
|
|
38
|
+
left: any;
|
|
39
|
+
right: any;
|
|
40
|
+
}): Promise<number>;
|
|
41
|
+
remainder(ast: {
|
|
42
|
+
left: any;
|
|
43
|
+
right: any;
|
|
44
|
+
}): Promise<number>;
|
|
45
|
+
add(ast: {
|
|
46
|
+
left: any;
|
|
47
|
+
right: any;
|
|
48
|
+
}): Promise<any>;
|
|
49
|
+
minus(ast: {
|
|
50
|
+
left: any;
|
|
51
|
+
right: any;
|
|
52
|
+
}): Promise<number>;
|
|
53
|
+
shift(ast: {
|
|
54
|
+
op: '<<' | '>>' | '>>>';
|
|
55
|
+
left: any;
|
|
56
|
+
right: any;
|
|
57
|
+
}): Promise<number>;
|
|
58
|
+
lt(ast: {
|
|
59
|
+
left: any;
|
|
60
|
+
right: any;
|
|
61
|
+
}): Promise<boolean>;
|
|
62
|
+
gt(ast: {
|
|
63
|
+
left: any;
|
|
64
|
+
right: any;
|
|
65
|
+
}): Promise<boolean>;
|
|
66
|
+
le(ast: {
|
|
67
|
+
left: any;
|
|
68
|
+
right: any;
|
|
69
|
+
}): Promise<boolean>;
|
|
70
|
+
ge(ast: {
|
|
71
|
+
left: any;
|
|
72
|
+
right: any;
|
|
73
|
+
}): Promise<boolean>;
|
|
74
|
+
eq(ast: {
|
|
75
|
+
left: any;
|
|
76
|
+
right: any;
|
|
77
|
+
}): Promise<boolean>;
|
|
78
|
+
ne(ast: {
|
|
79
|
+
left: any;
|
|
80
|
+
right: any;
|
|
81
|
+
}): Promise<boolean>;
|
|
82
|
+
streq(ast: {
|
|
83
|
+
left: any;
|
|
84
|
+
right: any;
|
|
85
|
+
}): Promise<boolean>;
|
|
86
|
+
strneq(ast: {
|
|
87
|
+
left: any;
|
|
88
|
+
right: any;
|
|
89
|
+
}): Promise<boolean>;
|
|
90
|
+
binary(ast: {
|
|
91
|
+
op: '&' | '^' | '|';
|
|
92
|
+
left: any;
|
|
93
|
+
right: any;
|
|
94
|
+
}): Promise<number>;
|
|
95
|
+
and(ast: {
|
|
96
|
+
left: any;
|
|
97
|
+
right: any;
|
|
98
|
+
}): Promise<any>;
|
|
99
|
+
or(ast: {
|
|
100
|
+
left: any;
|
|
101
|
+
right: any;
|
|
102
|
+
}): Promise<any>;
|
|
103
|
+
array(ast: {
|
|
104
|
+
type: 'array';
|
|
105
|
+
members: Array<any>;
|
|
106
|
+
}): Promise<unknown[]>;
|
|
107
|
+
object(ast: {
|
|
108
|
+
members: Array<{
|
|
109
|
+
key: string;
|
|
110
|
+
value: any;
|
|
111
|
+
}>;
|
|
112
|
+
}): Promise<any>;
|
|
113
|
+
conditional(ast: {
|
|
114
|
+
type: 'conditional';
|
|
115
|
+
test: any;
|
|
116
|
+
consequent: any;
|
|
117
|
+
alternate: any;
|
|
118
|
+
}): Promise<any>;
|
|
119
|
+
funcCall(this: any, ast: {
|
|
120
|
+
identifier: string;
|
|
121
|
+
args: Array<any>;
|
|
122
|
+
}): Promise<any>;
|
|
123
|
+
callAnonymousFunction(ast: {
|
|
124
|
+
args: any[];
|
|
125
|
+
return: any;
|
|
126
|
+
}, args: Array<any>): Promise<any>;
|
|
127
|
+
/**
|
|
128
|
+
* 示例:IF(A, B, C)
|
|
129
|
+
*
|
|
130
|
+
* 如果满足条件A,则返回B,否则返回C,支持多层嵌套IF函数。
|
|
131
|
+
*
|
|
132
|
+
* 也可以用表达式如:A ? B : C
|
|
133
|
+
*
|
|
134
|
+
* @example IF(condition, consequent, alternate)
|
|
135
|
+
* @param {expression} condition - 条件表达式.
|
|
136
|
+
* @param {any} consequent 条件判断通过的返回结果
|
|
137
|
+
* @param {any} alternate 条件判断不通过的返回结果
|
|
138
|
+
* @namespace 逻辑函数
|
|
139
|
+
*
|
|
140
|
+
* @returns {any} 根据条件返回不同的结果
|
|
141
|
+
*/
|
|
142
|
+
fnIF(condition: () => any, trueValue: () => any, falseValue: () => any): Promise<any>;
|
|
143
|
+
/**
|
|
144
|
+
* 条件全部符合,返回 true,否则返回 false
|
|
145
|
+
*
|
|
146
|
+
* 示例:AND(语文成绩>80, 数学成绩>80)
|
|
147
|
+
*
|
|
148
|
+
* 语文成绩和数学成绩都大于 80,则返回 true,否则返回 false
|
|
149
|
+
*
|
|
150
|
+
* 也可以直接用表达式如:语文成绩>80 && 数学成绩>80
|
|
151
|
+
*
|
|
152
|
+
* @example AND(expression1, expression2, ...expressionN)
|
|
153
|
+
* @param {...expression} conditions - 条件表达式.
|
|
154
|
+
* @namespace 逻辑函数
|
|
155
|
+
*
|
|
156
|
+
* @returns {boolean}
|
|
157
|
+
*/
|
|
158
|
+
fnAND(...condtions: Array<() => any>): Promise<any>;
|
|
159
|
+
/**
|
|
160
|
+
* 条件任意一个满足条件,返回 true,否则返回 false
|
|
161
|
+
*
|
|
162
|
+
* 示例:OR(语文成绩>80, 数学成绩>80)
|
|
163
|
+
*
|
|
164
|
+
* 语文成绩和数学成绩任意一个大于 80,则返回 true,否则返回 false
|
|
165
|
+
*
|
|
166
|
+
* 也可以直接用表达式如:语文成绩>80 || 数学成绩>80
|
|
167
|
+
*
|
|
168
|
+
* @example OR(expression1, expression2, ...expressionN)
|
|
169
|
+
* @param {...expression} conditions - 条件表达式.
|
|
170
|
+
* @namespace 逻辑函数
|
|
171
|
+
*
|
|
172
|
+
* @returns {boolean}
|
|
173
|
+
*/
|
|
174
|
+
fnOR(...condtions: Array<() => any>): Promise<any>;
|
|
175
|
+
/**
|
|
176
|
+
* 异或处理,多个表达式组中存在奇数个真时认为真。
|
|
177
|
+
*
|
|
178
|
+
* @example XOR(condition1, condition2)
|
|
179
|
+
* @param {expression} condition1 - 条件表达式1
|
|
180
|
+
* @param {expression} condition2 - 条件表达式2
|
|
181
|
+
* @namespace 逻辑函数
|
|
182
|
+
*
|
|
183
|
+
* @returns {boolean}
|
|
184
|
+
*/
|
|
185
|
+
fnXOR(...condtions: Array<() => any>): Promise<boolean>;
|
|
186
|
+
/**
|
|
187
|
+
* 判断函数集合,相当于多个 else if 合并成一个。
|
|
188
|
+
*
|
|
189
|
+
* 示例:IFS(语文成绩 > 80, "优秀", 语文成绩 > 60, "良", "继续努力")
|
|
190
|
+
*
|
|
191
|
+
* 如果语文成绩大于 80,则返回优秀,否则判断大于 60 分,则返回良,否则返回继续努力。
|
|
192
|
+
*
|
|
193
|
+
* @example IFS(condition1, result1, condition2, result2,...conditionN, resultN)
|
|
194
|
+
* @param {...any} args - 条件,返回值集合
|
|
195
|
+
* @namespace 逻辑函数
|
|
196
|
+
* @returns {any} 第一个满足条件的结果,没有命中的返回 false。
|
|
197
|
+
*/
|
|
198
|
+
fnIFS(...args: Array<() => any>): Promise<any>;
|
|
199
|
+
/**
|
|
200
|
+
* 数组做数据转换,需要搭配箭头函数一起使用,注意箭头函数只支持单表达式用法。
|
|
201
|
+
*
|
|
202
|
+
* @param {Array<any>} arr 数组
|
|
203
|
+
* @param {Function<any>} iterator 箭头函数
|
|
204
|
+
* @namespace 数组
|
|
205
|
+
* @example ARRAYMAP(arr, item => item)
|
|
206
|
+
* @returns {boolean} 结果
|
|
207
|
+
*/
|
|
208
|
+
fnARRAYMAP(value: any, iterator: any): any;
|
|
209
|
+
/**
|
|
210
|
+
* 数据做数据过滤,需要搭配箭头函数一起使用,注意箭头函数只支持单表达式用法。
|
|
211
|
+
* 将第二个箭头函数返回为 false 的成员过滤掉。
|
|
212
|
+
*
|
|
213
|
+
* @param {Array<any>} arr 数组
|
|
214
|
+
* @param {Function<any>} iterator 箭头函数
|
|
215
|
+
* @namespace 数组
|
|
216
|
+
* @example ARRAYFILTER(arr, item => item)
|
|
217
|
+
* @returns {boolean} 结果
|
|
218
|
+
*/
|
|
219
|
+
fnARRAYFILTER(value: any, iterator: any): Promise<any>;
|
|
220
|
+
/**
|
|
221
|
+
* 数据做数据查找,需要搭配箭头函数一起使用,注意箭头函数只支持单表达式用法。
|
|
222
|
+
* 找出第二个箭头函数返回为 true 的成员的索引。
|
|
223
|
+
*
|
|
224
|
+
* 示例:
|
|
225
|
+
*
|
|
226
|
+
* ARRAYFINDINDEX([0, 2, false], item => item === 2) 得到 1
|
|
227
|
+
*
|
|
228
|
+
* @param {Array<any>} arr 数组
|
|
229
|
+
* @param {Function<any>} iterator 箭头函数
|
|
230
|
+
* @namespace 数组
|
|
231
|
+
* @example ARRAYFINDINDEX(arr, item => item === 2)
|
|
232
|
+
* @returns {number} 结果
|
|
233
|
+
*/
|
|
234
|
+
fnARRAYFINDINDEX(arr: any[], iterator: any): Promise<number>;
|
|
235
|
+
/**
|
|
236
|
+
* 数据做数据查找,需要搭配箭头函数一起使用,注意箭头函数只支持单表达式用法。
|
|
237
|
+
* 找出第二个箭头函数返回为 true 的成员。
|
|
238
|
+
*
|
|
239
|
+
* 示例:
|
|
240
|
+
*
|
|
241
|
+
* ARRAYFIND([0, 2, false], item => item === 2) 得到 2
|
|
242
|
+
*
|
|
243
|
+
* @param {Array<any>} arr 数组
|
|
244
|
+
* @param {Function<any>} iterator 箭头函数
|
|
245
|
+
* @namespace 数组
|
|
246
|
+
* @example ARRAYFIND(arr, item => item === 2)
|
|
247
|
+
* @returns {any} 结果
|
|
248
|
+
*/
|
|
249
|
+
fnARRAYFIND(arr: any[], iterator: any): Promise<undefined>;
|
|
250
|
+
/**
|
|
251
|
+
* 数据做数据遍历判断,需要搭配箭头函数一起使用,注意箭头函数只支持单表达式用法。
|
|
252
|
+
* 判断第二个箭头函数是否存在返回为 true 的成员。
|
|
253
|
+
*
|
|
254
|
+
* 示例:
|
|
255
|
+
*
|
|
256
|
+
* ARRAYSOME([0, 2, false], item => item === 2) 得到 true
|
|
257
|
+
*
|
|
258
|
+
* @param {Array<any>} arr 数组
|
|
259
|
+
* @param {Function<any>} iterator 箭头函数
|
|
260
|
+
* @namespace 数组
|
|
261
|
+
* @example ARRAYSOME(arr, item => item === 2)
|
|
262
|
+
* @returns {boolean} 结果
|
|
263
|
+
*/
|
|
264
|
+
fnARRAYSOME(arr: any[], iterator: any): Promise<any>;
|
|
265
|
+
/**
|
|
266
|
+
* 数据做数据遍历判断,需要搭配箭头函数一起使用,注意箭头函数只支持单表达式用法。
|
|
267
|
+
* 判断第二个箭头函数返回是否都为 true。
|
|
268
|
+
*
|
|
269
|
+
* 示例:
|
|
270
|
+
*
|
|
271
|
+
* ARRAYEVERY([0, 2, false], item => item === 2) 得到 false
|
|
272
|
+
*
|
|
273
|
+
* @param {Array<any>} arr 数组
|
|
274
|
+
* @param {Function<any>} iterator 箭头函数
|
|
275
|
+
* @namespace 数组
|
|
276
|
+
* @example ARRAYEVERY(arr, item => item === 2)
|
|
277
|
+
* @returns {boolean} 结果
|
|
278
|
+
*/
|
|
279
|
+
fnARRAYEVERY(arr: any[], iterator: any): Promise<any>;
|
|
280
|
+
}
|
|
281
|
+
export {};
|