amis-formula 2.9.0 → 3.1.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.js +3 -2
- package/esm/evalutorForAsync.js +33 -37
- package/esm/filter.js +1 -1
- package/esm/function.d.ts +3 -1
- package/esm/function.js +11 -2
- package/esm/index.d.ts +2 -2
- package/esm/index.js +2 -2
- package/esm/lexer.js +1 -1
- package/esm/parser.js +1 -1
- package/esm/types.d.ts +9 -0
- package/lib/doc.js +1 -1
- package/lib/error.d.ts +6 -0
- package/lib/error.js +25 -0
- package/lib/evalutor.js +3 -2
- package/lib/evalutorForAsync.js +33 -37
- package/lib/filter.js +1 -1
- package/lib/function.d.ts +3 -1
- package/lib/function.js +12 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +3 -1
- package/lib/lexer.js +1 -1
- package/lib/parser.js +1 -1
- package/lib/types.d.ts +9 -0
- 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.1.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.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-formula
|
|
2
|
+
* amis-formula v3.1.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
|
// 逻辑函数特殊处理,因为有时候有些运算是可以跳过的。
|
package/esm/evalutorForAsync.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-formula
|
|
2
|
+
* amis-formula v3.1.0
|
|
3
3
|
* Copyright 2021-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { __extends, __awaiter, __generator } from 'tslib';
|
|
7
7
|
import { stripNumber, createObject, Evaluator } from './evalutor.js';
|
|
8
|
+
import { FormulaEvalError } from './error.js';
|
|
8
9
|
|
|
9
10
|
function runSequence(arr, fn) {
|
|
10
11
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -72,7 +73,7 @@ var AsyncEvaluator = /** @class */ (function (_super) {
|
|
|
72
73
|
};
|
|
73
74
|
AsyncEvaluator.prototype.filter = function (ast) {
|
|
74
75
|
return __awaiter(this, void 0, void 0, function () {
|
|
75
|
-
var input, filters, context,
|
|
76
|
+
var input, filters, context, filter, fn, argsRes;
|
|
76
77
|
var _this = this;
|
|
77
78
|
return __generator(this, function (_a) {
|
|
78
79
|
switch (_a.label) {
|
|
@@ -85,47 +86,42 @@ var AsyncEvaluator = /** @class */ (function (_super) {
|
|
|
85
86
|
data: this.context,
|
|
86
87
|
restFilters: filters
|
|
87
88
|
};
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
_a.label = 2;
|
|
90
|
+
case 2:
|
|
91
|
+
if (!filters.length) return [3 /*break*/, 4];
|
|
92
|
+
filter = filters.shift();
|
|
93
|
+
fn = this.filters[filter.name];
|
|
94
|
+
if (!fn) {
|
|
95
|
+
throw new Error("filter `".concat(filter.name, "` not exists."));
|
|
96
|
+
}
|
|
97
|
+
context.filter = filter;
|
|
98
|
+
return [4 /*yield*/, runSequence(filter.args, function (item) { return __awaiter(_this, void 0, void 0, function () {
|
|
99
|
+
var res;
|
|
90
100
|
var _this = this;
|
|
91
101
|
return __generator(this, function (_a) {
|
|
92
102
|
switch (_a.label) {
|
|
93
|
-
case 0:
|
|
103
|
+
case 0:
|
|
104
|
+
if (!((item === null || item === void 0 ? void 0 : item.type) === 'mixed')) return [3 /*break*/, 2];
|
|
105
|
+
return [4 /*yield*/, runSequence(item.body, function (item) {
|
|
106
|
+
return typeof item === 'string' ? item : _this.evalute(item);
|
|
107
|
+
})];
|
|
94
108
|
case 1:
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (!fn) {
|
|
98
|
-
throw new Error("filter `".concat(filter.name, "` not exists."));
|
|
99
|
-
}
|
|
100
|
-
context.filter = filter;
|
|
101
|
-
return [4 /*yield*/, filter.args.reduce(function (promise, item) { return __awaiter(_this, void 0, void 0, function () {
|
|
102
|
-
var _this = this;
|
|
103
|
-
return __generator(this, function (_a) {
|
|
104
|
-
switch (_a.label) {
|
|
105
|
-
case 0: return [4 /*yield*/, promise];
|
|
106
|
-
case 1:
|
|
107
|
-
_a.sent();
|
|
108
|
-
if ((item === null || item === void 0 ? void 0 : item.type) === 'mixed') {
|
|
109
|
-
return [2 /*return*/, runSequence(item.body, function (item) {
|
|
110
|
-
return typeof item === 'string' ? item : _this.evalute(item);
|
|
111
|
-
})];
|
|
112
|
-
}
|
|
113
|
-
else if (item.type) {
|
|
114
|
-
return [2 /*return*/, this.evalute(item)];
|
|
115
|
-
}
|
|
116
|
-
return [2 /*return*/, item];
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}); }, Promise.resolve([]))];
|
|
109
|
+
res = _a.sent();
|
|
110
|
+
return [2 /*return*/, res.join('')];
|
|
120
111
|
case 2:
|
|
121
|
-
|
|
122
|
-
|
|
112
|
+
if (item.type) {
|
|
113
|
+
return [2 /*return*/, this.evalute(item)];
|
|
114
|
+
}
|
|
115
|
+
_a.label = 3;
|
|
116
|
+
case 3: return [2 /*return*/, item];
|
|
123
117
|
}
|
|
124
118
|
});
|
|
125
|
-
}); }
|
|
126
|
-
case
|
|
127
|
-
|
|
128
|
-
|
|
119
|
+
}); })];
|
|
120
|
+
case 3:
|
|
121
|
+
argsRes = _a.sent();
|
|
122
|
+
input = fn.apply(context, [input].concat(argsRes));
|
|
123
|
+
return [3 /*break*/, 2];
|
|
124
|
+
case 4: return [2 /*return*/, input];
|
|
129
125
|
}
|
|
130
126
|
});
|
|
131
127
|
});
|
|
@@ -573,7 +569,7 @@ var AsyncEvaluator = /** @class */ (function (_super) {
|
|
|
573
569
|
(this.filters.hasOwnProperty(ast.identifier) &&
|
|
574
570
|
this.filters[ast.identifier]);
|
|
575
571
|
if (!fn) {
|
|
576
|
-
throw new
|
|
572
|
+
throw new FormulaEvalError("".concat(ast.identifier, "\u51FD\u6570\u6CA1\u6709\u5B9A\u4E49"));
|
|
577
573
|
}
|
|
578
574
|
args = ast.args;
|
|
579
575
|
if (!~['IF', 'AND', 'OR', 'XOR', 'IFS'].indexOf(ast.identifier)) return [3 /*break*/, 1];
|
package/esm/filter.js
CHANGED
package/esm/function.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import { FunctionMap } from './types';
|
|
1
|
+
import { FunctionMap, FunctionDocMap, FunctionDocItem } from './types';
|
|
2
2
|
export declare const functions: FunctionMap;
|
|
3
3
|
export declare function registerFunction(name: string, fn: (input: any, ...args: any[]) => any): void;
|
|
4
|
+
export declare let functionDocs: FunctionDocMap;
|
|
5
|
+
export declare function registerFunctionDoc(groupName: string, item: FunctionDocItem): void;
|
package/esm/function.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-formula
|
|
2
|
+
* amis-formula v3.1.0
|
|
3
3
|
* Copyright 2021-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -10,5 +10,14 @@ function registerFunction(name, fn) {
|
|
|
10
10
|
functions["fn".concat(name)] = fn;
|
|
11
11
|
Evaluator.setDefaultFunctions(functions);
|
|
12
12
|
}
|
|
13
|
+
var functionDocs = {};
|
|
14
|
+
function registerFunctionDoc(groupName, item) {
|
|
15
|
+
if (functionDocs[groupName]) {
|
|
16
|
+
functionDocs[groupName].push(item);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
functionDocs[groupName] = [item];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
13
22
|
|
|
14
|
-
export { functions, registerFunction };
|
|
23
|
+
export { functionDocs, functions, registerFunction, registerFunctionDoc };
|
package/esm/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { AsyncEvaluator } from './evalutorForAsync';
|
|
|
3
3
|
import { parse } from './parser';
|
|
4
4
|
import { lexer } from './lexer';
|
|
5
5
|
import { registerFilter, filters, getFilters, extendsFilters } from './filter';
|
|
6
|
-
import { registerFunction } from './function';
|
|
6
|
+
import { registerFunction, registerFunctionDoc, functionDocs } from './function';
|
|
7
7
|
import type { FilterContext, ASTNode, ParserOptions, EvaluatorOptions } from './types';
|
|
8
|
-
export { parse, lexer, Evaluator, AsyncEvaluator, FilterContext, filters, getFilters, registerFilter, registerFunction, extendsFilters };
|
|
8
|
+
export { parse, lexer, Evaluator, AsyncEvaluator, FilterContext, filters, getFilters, registerFilter, registerFunction, registerFunctionDoc, functionDocs, extendsFilters };
|
|
9
9
|
export declare function evaluate(astOrString: string | ASTNode, data: any, options?: ParserOptions & EvaluatorOptions): any;
|
|
10
10
|
export declare function evaluateForAsync(astOrString: string | ASTNode, data: any, options?: ParserOptions & EvaluatorOptions): Promise<any>;
|
package/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-formula
|
|
2
|
+
* amis-formula v3.1.0
|
|
3
3
|
* Copyright 2021-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -13,7 +13,7 @@ export { parse } from './parser.js';
|
|
|
13
13
|
export { lexer } from './lexer.js';
|
|
14
14
|
import { getFilters } from './filter.js';
|
|
15
15
|
export { extendsFilters, filters, getFilters, registerFilter } from './filter.js';
|
|
16
|
-
export { registerFunction } from './function.js';
|
|
16
|
+
export { functionDocs, registerFunction, registerFunctionDoc } from './function.js';
|
|
17
17
|
|
|
18
18
|
function evaluate(astOrString, data, options) {
|
|
19
19
|
var ast = astOrString;
|
package/esm/lexer.js
CHANGED
package/esm/parser.js
CHANGED
package/esm/types.d.ts
CHANGED
|
@@ -5,6 +5,15 @@ export interface FilterMap {
|
|
|
5
5
|
export interface FunctionMap {
|
|
6
6
|
[propName: string]: (this: Evaluator, ast: Object, data: any) => any;
|
|
7
7
|
}
|
|
8
|
+
export interface FunctionDocItem {
|
|
9
|
+
name: string;
|
|
10
|
+
example?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
[propName: string]: any;
|
|
13
|
+
}
|
|
14
|
+
export interface FunctionDocMap {
|
|
15
|
+
[propName: string]: FunctionDocItem[];
|
|
16
|
+
}
|
|
8
17
|
export interface FilterContext {
|
|
9
18
|
data: Object;
|
|
10
19
|
filter?: {
|
package/lib/doc.js
CHANGED
package/lib/error.d.ts
ADDED
package/lib/error.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* amis-formula v3.1.0
|
|
3
|
+
* Copyright 2021-2023 fex
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
|
+
|
|
10
|
+
var tslib = require('tslib');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 表达式解析错误
|
|
14
|
+
*/
|
|
15
|
+
var FormulaEvalError = /** @class */ (function (_super) {
|
|
16
|
+
tslib.__extends(FormulaEvalError, _super);
|
|
17
|
+
function FormulaEvalError(message) {
|
|
18
|
+
var _this = _super.call(this, message) || this;
|
|
19
|
+
_this.name = 'FormulaEvalError';
|
|
20
|
+
return _this;
|
|
21
|
+
}
|
|
22
|
+
return FormulaEvalError;
|
|
23
|
+
}(Error));
|
|
24
|
+
|
|
25
|
+
exports.FormulaEvalError = FormulaEvalError;
|
package/lib/evalutor.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-formula
|
|
2
|
+
* amis-formula v3.1.0
|
|
3
3
|
* Copyright 2021-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -19,6 +19,7 @@ var uniqBy = require('lodash/uniqBy');
|
|
|
19
19
|
var isEqual = require('lodash/isEqual');
|
|
20
20
|
var isPlainObject = require('lodash/isPlainObject');
|
|
21
21
|
var get = require('lodash/get');
|
|
22
|
+
var error = require('./error.js');
|
|
22
23
|
|
|
23
24
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
24
25
|
|
|
@@ -384,7 +385,7 @@ var Evaluator = /** @class */ (function () {
|
|
|
384
385
|
(this.filters.hasOwnProperty(ast.identifier) &&
|
|
385
386
|
this.filters[ast.identifier]);
|
|
386
387
|
if (!fn) {
|
|
387
|
-
throw new
|
|
388
|
+
throw new error.FormulaEvalError("".concat(ast.identifier, "\u51FD\u6570\u6CA1\u6709\u5B9A\u4E49"));
|
|
388
389
|
}
|
|
389
390
|
var args = ast.args;
|
|
390
391
|
// 逻辑函数特殊处理,因为有时候有些运算是可以跳过的。
|
package/lib/evalutorForAsync.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-formula
|
|
2
|
+
* amis-formula v3.1.0
|
|
3
3
|
* Copyright 2021-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -9,6 +9,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
9
9
|
|
|
10
10
|
var tslib = require('tslib');
|
|
11
11
|
var evalutor = require('./evalutor.js');
|
|
12
|
+
var error = require('./error.js');
|
|
12
13
|
|
|
13
14
|
function runSequence(arr, fn) {
|
|
14
15
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
@@ -76,7 +77,7 @@ var AsyncEvaluator = /** @class */ (function (_super) {
|
|
|
76
77
|
};
|
|
77
78
|
AsyncEvaluator.prototype.filter = function (ast) {
|
|
78
79
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
79
|
-
var input, filters, context,
|
|
80
|
+
var input, filters, context, filter, fn, argsRes;
|
|
80
81
|
var _this = this;
|
|
81
82
|
return tslib.__generator(this, function (_a) {
|
|
82
83
|
switch (_a.label) {
|
|
@@ -89,47 +90,42 @@ var AsyncEvaluator = /** @class */ (function (_super) {
|
|
|
89
90
|
data: this.context,
|
|
90
91
|
restFilters: filters
|
|
91
92
|
};
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
_a.label = 2;
|
|
94
|
+
case 2:
|
|
95
|
+
if (!filters.length) return [3 /*break*/, 4];
|
|
96
|
+
filter = filters.shift();
|
|
97
|
+
fn = this.filters[filter.name];
|
|
98
|
+
if (!fn) {
|
|
99
|
+
throw new Error("filter `".concat(filter.name, "` not exists."));
|
|
100
|
+
}
|
|
101
|
+
context.filter = filter;
|
|
102
|
+
return [4 /*yield*/, runSequence(filter.args, function (item) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
103
|
+
var res;
|
|
94
104
|
var _this = this;
|
|
95
105
|
return tslib.__generator(this, function (_a) {
|
|
96
106
|
switch (_a.label) {
|
|
97
|
-
case 0:
|
|
107
|
+
case 0:
|
|
108
|
+
if (!((item === null || item === void 0 ? void 0 : item.type) === 'mixed')) return [3 /*break*/, 2];
|
|
109
|
+
return [4 /*yield*/, runSequence(item.body, function (item) {
|
|
110
|
+
return typeof item === 'string' ? item : _this.evalute(item);
|
|
111
|
+
})];
|
|
98
112
|
case 1:
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (!fn) {
|
|
102
|
-
throw new Error("filter `".concat(filter.name, "` not exists."));
|
|
103
|
-
}
|
|
104
|
-
context.filter = filter;
|
|
105
|
-
return [4 /*yield*/, filter.args.reduce(function (promise, item) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
106
|
-
var _this = this;
|
|
107
|
-
return tslib.__generator(this, function (_a) {
|
|
108
|
-
switch (_a.label) {
|
|
109
|
-
case 0: return [4 /*yield*/, promise];
|
|
110
|
-
case 1:
|
|
111
|
-
_a.sent();
|
|
112
|
-
if ((item === null || item === void 0 ? void 0 : item.type) === 'mixed') {
|
|
113
|
-
return [2 /*return*/, runSequence(item.body, function (item) {
|
|
114
|
-
return typeof item === 'string' ? item : _this.evalute(item);
|
|
115
|
-
})];
|
|
116
|
-
}
|
|
117
|
-
else if (item.type) {
|
|
118
|
-
return [2 /*return*/, this.evalute(item)];
|
|
119
|
-
}
|
|
120
|
-
return [2 /*return*/, item];
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
}); }, Promise.resolve([]))];
|
|
113
|
+
res = _a.sent();
|
|
114
|
+
return [2 /*return*/, res.join('')];
|
|
124
115
|
case 2:
|
|
125
|
-
|
|
126
|
-
|
|
116
|
+
if (item.type) {
|
|
117
|
+
return [2 /*return*/, this.evalute(item)];
|
|
118
|
+
}
|
|
119
|
+
_a.label = 3;
|
|
120
|
+
case 3: return [2 /*return*/, item];
|
|
127
121
|
}
|
|
128
122
|
});
|
|
129
|
-
}); }
|
|
130
|
-
case
|
|
131
|
-
|
|
132
|
-
|
|
123
|
+
}); })];
|
|
124
|
+
case 3:
|
|
125
|
+
argsRes = _a.sent();
|
|
126
|
+
input = fn.apply(context, [input].concat(argsRes));
|
|
127
|
+
return [3 /*break*/, 2];
|
|
128
|
+
case 4: return [2 /*return*/, input];
|
|
133
129
|
}
|
|
134
130
|
});
|
|
135
131
|
});
|
|
@@ -577,7 +573,7 @@ var AsyncEvaluator = /** @class */ (function (_super) {
|
|
|
577
573
|
(this.filters.hasOwnProperty(ast.identifier) &&
|
|
578
574
|
this.filters[ast.identifier]);
|
|
579
575
|
if (!fn) {
|
|
580
|
-
throw new
|
|
576
|
+
throw new error.FormulaEvalError("".concat(ast.identifier, "\u51FD\u6570\u6CA1\u6709\u5B9A\u4E49"));
|
|
581
577
|
}
|
|
582
578
|
args = ast.args;
|
|
583
579
|
if (!~['IF', 'AND', 'OR', 'XOR', 'IFS'].indexOf(ast.identifier)) return [3 /*break*/, 1];
|
package/lib/filter.js
CHANGED
package/lib/function.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import { FunctionMap } from './types';
|
|
1
|
+
import { FunctionMap, FunctionDocMap, FunctionDocItem } from './types';
|
|
2
2
|
export declare const functions: FunctionMap;
|
|
3
3
|
export declare function registerFunction(name: string, fn: (input: any, ...args: any[]) => any): void;
|
|
4
|
+
export declare let functionDocs: FunctionDocMap;
|
|
5
|
+
export declare function registerFunctionDoc(groupName: string, item: FunctionDocItem): void;
|
package/lib/function.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-formula
|
|
2
|
+
* amis-formula v3.1.0
|
|
3
3
|
* Copyright 2021-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -14,6 +14,17 @@ function registerFunction(name, fn) {
|
|
|
14
14
|
functions["fn".concat(name)] = fn;
|
|
15
15
|
evalutor.Evaluator.setDefaultFunctions(functions);
|
|
16
16
|
}
|
|
17
|
+
var functionDocs = {};
|
|
18
|
+
function registerFunctionDoc(groupName, item) {
|
|
19
|
+
if (functionDocs[groupName]) {
|
|
20
|
+
functionDocs[groupName].push(item);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
functionDocs[groupName] = [item];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
17
26
|
|
|
27
|
+
exports.functionDocs = functionDocs;
|
|
18
28
|
exports.functions = functions;
|
|
19
29
|
exports.registerFunction = registerFunction;
|
|
30
|
+
exports.registerFunctionDoc = registerFunctionDoc;
|
package/lib/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { AsyncEvaluator } from './evalutorForAsync';
|
|
|
3
3
|
import { parse } from './parser';
|
|
4
4
|
import { lexer } from './lexer';
|
|
5
5
|
import { registerFilter, filters, getFilters, extendsFilters } from './filter';
|
|
6
|
-
import { registerFunction } from './function';
|
|
6
|
+
import { registerFunction, registerFunctionDoc, functionDocs } from './function';
|
|
7
7
|
import type { FilterContext, ASTNode, ParserOptions, EvaluatorOptions } from './types';
|
|
8
|
-
export { parse, lexer, Evaluator, AsyncEvaluator, FilterContext, filters, getFilters, registerFilter, registerFunction, extendsFilters };
|
|
8
|
+
export { parse, lexer, Evaluator, AsyncEvaluator, FilterContext, filters, getFilters, registerFilter, registerFunction, registerFunctionDoc, functionDocs, extendsFilters };
|
|
9
9
|
export declare function evaluate(astOrString: string | ASTNode, data: any, options?: ParserOptions & EvaluatorOptions): any;
|
|
10
10
|
export declare function evaluateForAsync(astOrString: string | ASTNode, data: any, options?: ParserOptions & EvaluatorOptions): Promise<any>;
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-formula
|
|
2
|
+
* amis-formula v3.1.0
|
|
3
3
|
* Copyright 2021-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -45,6 +45,8 @@ exports.extendsFilters = filter.extendsFilters;
|
|
|
45
45
|
exports.filters = filter.filters;
|
|
46
46
|
exports.getFilters = filter.getFilters;
|
|
47
47
|
exports.registerFilter = filter.registerFilter;
|
|
48
|
+
exports.functionDocs = _function.functionDocs;
|
|
48
49
|
exports.registerFunction = _function.registerFunction;
|
|
50
|
+
exports.registerFunctionDoc = _function.registerFunctionDoc;
|
|
49
51
|
exports.evaluate = evaluate;
|
|
50
52
|
exports.evaluateForAsync = evaluateForAsync;
|
package/lib/lexer.js
CHANGED
package/lib/parser.js
CHANGED
package/lib/types.d.ts
CHANGED
|
@@ -5,6 +5,15 @@ export interface FilterMap {
|
|
|
5
5
|
export interface FunctionMap {
|
|
6
6
|
[propName: string]: (this: Evaluator, ast: Object, data: any) => any;
|
|
7
7
|
}
|
|
8
|
+
export interface FunctionDocItem {
|
|
9
|
+
name: string;
|
|
10
|
+
example?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
[propName: string]: any;
|
|
13
|
+
}
|
|
14
|
+
export interface FunctionDocMap {
|
|
15
|
+
[propName: string]: FunctionDocItem[];
|
|
16
|
+
}
|
|
8
17
|
export interface FilterContext {
|
|
9
18
|
data: Object;
|
|
10
19
|
filter?: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "amis-formula",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "负责 amis 里面的表达式实现,内置公式,编辑器等",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -113,5 +113,5 @@
|
|
|
113
113
|
"printBasicPrototype": false
|
|
114
114
|
}
|
|
115
115
|
},
|
|
116
|
-
"gitHead": "
|
|
116
|
+
"gitHead": "020b12d0be43215664e0c0e53cd33486c43fde86"
|
|
117
117
|
}
|