feat: formula 扩充公式 ARRAYFILTER 用来做数组过滤 (#5554)

* publish beta

* feat: formula 扩充公式 ARRAYFILTER 用来做数组过滤
This commit is contained in:
liaoxuezhi 2022-10-13 16:33:43 +08:00 committed by GitHub
parent 67f839d18b
commit 19ee3ab674
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 46 additions and 12 deletions

View File

@ -2,5 +2,5 @@
"packages": [ "packages": [
"packages/*" "packages/*"
], ],
"version": "2.3.1" "version": "2.3.2-beta.1"
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "amis-core", "name": "amis-core",
"version": "2.3.1", "version": "2.3.2-beta.1",
"description": "amis-core", "description": "amis-core",
"main": "lib/index.js", "main": "lib/index.js",
"module": "esm/index.js", "module": "esm/index.js",
@ -43,7 +43,7 @@
"esm" "esm"
], ],
"dependencies": { "dependencies": {
"amis-formula": "^2.3.1", "amis-formula": "^2.3.2-beta.1",
"classnames": "2.3.1", "classnames": "2.3.1",
"file-saver": "^2.0.2", "file-saver": "^2.0.2",
"hoist-non-react-statics": "^3.3.2", "hoist-non-react-statics": "^3.3.2",

View File

@ -459,4 +459,11 @@ test('evalute:array:func', () => {
{id: 1.1}, {id: 1.1},
{id: 2.2} {id: 2.2}
]); ]);
expect(evaluate('${ARRAYFILTER(arr1, item => item)}', data)).toMatchObject([
1, 2, 3
]);
expect(
evaluate('${ARRAYFILTER(arr1, item => item && item >=2)}', data)
).toMatchObject([2, 3]);
}); });

View File

@ -1,6 +1,6 @@
{ {
"name": "amis-formula", "name": "amis-formula",
"version": "2.3.1", "version": "2.3.2-beta.1",
"description": "负责 amis 里面的表达式实现,内置公式,编辑器等", "description": "负责 amis 里面的表达式实现,内置公式,编辑器等",
"main": "lib/index.js", "main": "lib/index.js",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",

View File

@ -1805,8 +1805,28 @@ export class Evaluator {
throw new Error('expected an anonymous function get ' + iterator); throw new Error('expected an anonymous function get ' + iterator);
} }
return (Array.isArray(value) ? value : []).map((item, index) => return (Array.isArray(value) ? value : []).map((item, index, arr) =>
this.callAnonymousFunction(iterator, [item, index]) this.callAnonymousFunction(iterator, [item, index, arr])
);
}
/**
* 使
* false
*
* @param {Array<any>} arr
* @param {Function<any>} iterator
* @namespace
* @example ARRAYFILTER(arr, item => item)
* @returns {boolean}
*/
fnARRAYFILTER(value: any, iterator: any) {
if (!iterator || iterator.type !== 'anonymous_function') {
throw new Error('expected an anonymous function get ' + iterator);
}
return (Array.isArray(value) ? value : []).filter((item, index, arr) =>
this.callAnonymousFunction(iterator, [item, index, arr])
); );
} }

View File

@ -3,7 +3,7 @@
"main": "lib/index.js", "main": "lib/index.js",
"module": "esm/index.js", "module": "esm/index.js",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",
"version": "2.3.1", "version": "2.3.2-beta.1",
"description": "", "description": "",
"scripts": { "scripts": {
"build": "npm run clean-dist && NODE_ENV=production rollup -c ", "build": "npm run clean-dist && NODE_ENV=production rollup -c ",
@ -33,8 +33,8 @@
} }
}, },
"dependencies": { "dependencies": {
"amis-core": "^2.3.1", "amis-core": "^2.3.2-beta.1",
"amis-formula": "^2.3.1", "amis-formula": "^2.3.2-beta.1",
"classnames": "2.3.1", "classnames": "2.3.1",
"codemirror": "^5.63.0", "codemirror": "^5.63.0",
"downshift": "6.1.12", "downshift": "6.1.12",

View File

@ -1,6 +1,6 @@
{ {
"name": "amis", "name": "amis",
"version": "2.3.1", "version": "2.3.2-beta.1",
"description": "一种MIS页面生成工具", "description": "一种MIS页面生成工具",
"main": "lib/index.js", "main": "lib/index.js",
"module": "esm/index.js", "module": "esm/index.js",
@ -40,8 +40,8 @@
] ]
}, },
"dependencies": { "dependencies": {
"amis-core": "^2.3.1", "amis-core": "^2.3.2-beta.1",
"amis-ui": "^2.3.1", "amis-ui": "^2.3.2-beta.1",
"attr-accept": "2.2.2", "attr-accept": "2.2.2",
"blueimp-canvastoblob": "2.1.0", "blueimp-canvastoblob": "2.1.0",
"classnames": "2.3.1", "classnames": "2.3.1",

7
revision.json Normal file
View File

@ -0,0 +1,7 @@
{
"branch": "master",
"SHA1": "67f839d18",
"message": "docs: 处理移动端HTML报错 (#5536)",
"author": "RUNZE LU",
"date": "2022-10-13 11:34:28"
}