amis-formula 2.3.1 → 2.4.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/lib/doc.js CHANGED
@@ -664,7 +664,7 @@ exports.doc = [
664
664
  },
665
665
  {
666
666
  name: "ESCAPE",
667
- description: "对文本进行 HTML 转义\n\n示例 `ESCAPE(\"star\")`\n\n返回 `Star`",
667
+ description: "对文本进行 HTML 转义\n\n示例 `ESCAPE(\"<star>&\")`\n\n返回 `&lt;start&gt;&amp;`",
668
668
  example: "ESCAPE(text)",
669
669
  params: [
670
670
  {
@@ -1467,6 +1467,28 @@ exports.doc = [
1467
1467
  },
1468
1468
  namespace: "数组"
1469
1469
  },
1470
+ {
1471
+ name: "ARRAYFILTER",
1472
+ description: "数据做数据过滤,需要搭配箭头函数一起使用,注意箭头函数只支持单表达式用法。\n将第二个箭头函数返回为 false 的成员过滤掉。",
1473
+ example: "ARRAYFILTER(arr, item => item)",
1474
+ params: [
1475
+ {
1476
+ type: "Array<any>",
1477
+ name: "arr",
1478
+ description: "数组"
1479
+ },
1480
+ {
1481
+ type: "Array<any>",
1482
+ name: "iterator",
1483
+ description: "箭头函数"
1484
+ }
1485
+ ],
1486
+ returns: {
1487
+ type: "boolean",
1488
+ description: "结果"
1489
+ },
1490
+ namespace: "数组"
1491
+ },
1470
1492
  {
1471
1493
  name: "COMPACT",
1472
1494
  description: "数组过滤掉 false、null、0 和 \"\"\n\n示例:\n\nCOMPACT([0, 1, false, 2, '', 3]) 得到 [1, 2, 3]",
@@ -1544,5 +1566,22 @@ exports.doc = [
1544
1566
  description: "结果"
1545
1567
  },
1546
1568
  namespace: "数组"
1569
+ },
1570
+ {
1571
+ name: "ISTYPE",
1572
+ description: "判断是否为类型支持:string, number, array, date, plain-object。",
1573
+ example: "ISTYPE([{a: '1'}, {b: '2'}, {a: '1'}], 'array')",
1574
+ params: [
1575
+ {
1576
+ type: "string",
1577
+ name: "判断对象",
1578
+ description: null
1579
+ }
1580
+ ],
1581
+ returns: {
1582
+ type: "boolean",
1583
+ description: "结果结果"
1584
+ },
1585
+ namespace: "其他"
1547
1586
  }
1548
1587
  ]
package/lib/doc.md CHANGED
@@ -412,9 +412,9 @@
412
412
 
413
413
  对文本进行 HTML 转义
414
414
 
415
- 示例 `ESCAPE("star")`
415
+ 示例 `ESCAPE("<star>&")`
416
416
 
417
- 返回 `Star`
417
+ 返回 `&lt;start&gt;&amp;`
418
418
 
419
419
  ### TRUNCATE
420
420
 
@@ -851,6 +851,18 @@ DATEMODIFY(A, -2, 'month')
851
851
 
852
852
  数组做数据转换,需要搭配箭头函数一起使用,注意箭头函数只支持单表达式用法。
853
853
 
854
+ ### ARRAYFILTER
855
+
856
+ 用法:`ARRAYFILTER(arr, item => item)`
857
+
858
+ * `arr:Array<any>` 数组
859
+ * `iterator:Array<any>` 箭头函数
860
+
861
+ 返回:`boolean` 结果
862
+
863
+ 数据做数据过滤,需要搭配箭头函数一起使用,注意箭头函数只支持单表达式用法。
864
+ 将第二个箭头函数返回为 false 的成员过滤掉。
865
+
854
866
  ### COMPACT
855
867
 
856
868
  用法:`COMPACT(arr)`
@@ -909,3 +921,15 @@ CONCAT(['a', 'b', 'c'], ['1'], ['3']) 得到 ['a', 'b', 'c', '1', '3']
909
921
 
910
922
  UNIQ([{a: '1'}, {b: '2'}, {a: '1'}], 'id')
911
923
 
924
+ ## 其他
925
+
926
+ ### ISTYPE
927
+
928
+ 用法:`ISTYPE([{a: '1'}, {b: '2'}, {a: '1'}], 'array')`
929
+
930
+ * `判断对象:string` null
931
+
932
+ 返回:`boolean` 结果结果
933
+
934
+ 判断是否为类型支持:string, number, array, date, plain-object。
935
+
package/lib/evalutor.d.ts CHANGED
@@ -585,9 +585,9 @@ export declare class Evaluator {
585
585
  /**
586
586
  * 对文本进行 HTML 转义
587
587
  *
588
- * 示例 `ESCAPE("star")`
588
+ * 示例 `ESCAPE("<star>&")`
589
589
  *
590
- * 返回 `Star`
590
+ * 返回 `&lt;start&gt;&amp;`
591
591
  *
592
592
  * @example ESCAPE(text)
593
593
  * @param {string} text - 文本
@@ -1010,6 +1010,17 @@ export declare class Evaluator {
1010
1010
  * @returns {boolean} 结果
1011
1011
  */
1012
1012
  fnARRAYMAP(value: any, iterator: any): any[];
1013
+ /**
1014
+ * 数据做数据过滤,需要搭配箭头函数一起使用,注意箭头函数只支持单表达式用法。
1015
+ * 将第二个箭头函数返回为 false 的成员过滤掉。
1016
+ *
1017
+ * @param {Array<any>} arr 数组
1018
+ * @param {Function<any>} iterator 箭头函数
1019
+ * @namespace 数组
1020
+ * @example ARRAYFILTER(arr, item => item)
1021
+ * @returns {boolean} 结果
1022
+ */
1023
+ fnARRAYFILTER(value: any, iterator: any): any[];
1013
1024
  /**
1014
1025
  * 数组过滤掉 false、null、0 和 ""
1015
1026
  *
@@ -1065,6 +1076,15 @@ export declare class Evaluator {
1065
1076
  * @returns {Array<any>} 结果
1066
1077
  */
1067
1078
  fnUNIQ(arr: any[], field?: string): any[];
1079
+ /**
1080
+ * 判断是否为类型支持:string, number, array, date, plain-object。
1081
+ *
1082
+ * @param {string} 判断对象
1083
+ * @namespace 其他
1084
+ * @example ISTYPE([{a: '1'}, {b: '2'}, {a: '1'}], 'array')
1085
+ * @returns {boolean} 结果结果
1086
+ */
1087
+ fnISTYPE(target: any, type: 'string' | 'number' | 'array' | 'date' | 'plain-object' | 'nil'): boolean;
1068
1088
  }
1069
1089
  export declare function createObject(superProps?: {
1070
1090
  [propName: string]: any;
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-formula v2.3.1
2
+ * amis-formula v2.4.0
3
3
  * Copyright 2021-2022 fex
4
4
  */
5
5
 
@@ -17,6 +17,7 @@ var truncate = require('lodash/truncate');
17
17
  var uniqWith = require('lodash/uniqWith');
18
18
  var uniqBy = require('lodash/uniqBy');
19
19
  var isEqual = require('lodash/isEqual');
20
+ var isPlainObject = require('lodash/isPlainObject');
20
21
 
21
22
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
22
23
 
@@ -29,6 +30,7 @@ var truncate__default = /*#__PURE__*/_interopDefaultLegacy(truncate);
29
30
  var uniqWith__default = /*#__PURE__*/_interopDefaultLegacy(uniqWith);
30
31
  var uniqBy__default = /*#__PURE__*/_interopDefaultLegacy(uniqBy);
31
32
  var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
33
+ var isPlainObject__default = /*#__PURE__*/_interopDefaultLegacy(isPlainObject);
32
34
 
33
35
  /**
34
36
  * @file 公式内置函数
@@ -1077,9 +1079,9 @@ var Evaluator = /** @class */ (function () {
1077
1079
  /**
1078
1080
  * 对文本进行 HTML 转义
1079
1081
  *
1080
- * 示例 `ESCAPE("star")`
1082
+ * 示例 `ESCAPE("<star>&")`
1081
1083
  *
1082
- * 返回 `Star`
1084
+ * 返回 `&lt;start&gt;&amp;`
1083
1085
  *
1084
1086
  * @example ESCAPE(text)
1085
1087
  * @param {string} text - 文本
@@ -1676,8 +1678,27 @@ var Evaluator = /** @class */ (function () {
1676
1678
  if (!iterator || iterator.type !== 'anonymous_function') {
1677
1679
  throw new Error('expected an anonymous function get ' + iterator);
1678
1680
  }
1679
- return (Array.isArray(value) ? value : []).map(function (item, index) {
1680
- return _this.callAnonymousFunction(iterator, [item, index]);
1681
+ return (Array.isArray(value) ? value : []).map(function (item, index, arr) {
1682
+ return _this.callAnonymousFunction(iterator, [item, index, arr]);
1683
+ });
1684
+ };
1685
+ /**
1686
+ * 数据做数据过滤,需要搭配箭头函数一起使用,注意箭头函数只支持单表达式用法。
1687
+ * 将第二个箭头函数返回为 false 的成员过滤掉。
1688
+ *
1689
+ * @param {Array<any>} arr 数组
1690
+ * @param {Function<any>} iterator 箭头函数
1691
+ * @namespace 数组
1692
+ * @example ARRAYFILTER(arr, item => item)
1693
+ * @returns {boolean} 结果
1694
+ */
1695
+ Evaluator.prototype.fnARRAYFILTER = function (value, iterator) {
1696
+ var _this = this;
1697
+ if (!iterator || iterator.type !== 'anonymous_function') {
1698
+ throw new Error('expected an anonymous function get ' + iterator);
1699
+ }
1700
+ return (Array.isArray(value) ? value : []).filter(function (item, index, arr) {
1701
+ return _this.callAnonymousFunction(iterator, [item, index, arr]);
1681
1702
  });
1682
1703
  };
1683
1704
  /**
@@ -1769,6 +1790,31 @@ var Evaluator = /** @class */ (function () {
1769
1790
  Evaluator.prototype.fnUNIQ = function (arr, field) {
1770
1791
  return field ? uniqBy__default["default"](arr, field) : uniqWith__default["default"](arr, isEqual__default["default"]);
1771
1792
  };
1793
+ /**
1794
+ * 判断是否为类型支持:string, number, array, date, plain-object。
1795
+ *
1796
+ * @param {string} 判断对象
1797
+ * @namespace 其他
1798
+ * @example ISTYPE([{a: '1'}, {b: '2'}, {a: '1'}], 'array')
1799
+ * @returns {boolean} 结果结果
1800
+ */
1801
+ Evaluator.prototype.fnISTYPE = function (target, type) {
1802
+ switch (type) {
1803
+ case 'string':
1804
+ return typeof target === 'string';
1805
+ case 'number':
1806
+ return typeof target === 'number';
1807
+ case 'array':
1808
+ return Array.isArray(target);
1809
+ case 'date':
1810
+ return !!(target && target instanceof Date);
1811
+ case 'plain-object':
1812
+ return isPlainObject__default["default"](target);
1813
+ case 'nil':
1814
+ return !target;
1815
+ }
1816
+ return false;
1817
+ };
1772
1818
  Evaluator.defaultFilters = {};
1773
1819
  return Evaluator;
1774
1820
  }());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amis-formula",
3
- "version": "2.3.1",
3
+ "version": "2.4.0",
4
4
  "description": "负责 amis 里面的表达式实现,内置公式,编辑器等",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -100,5 +100,5 @@
100
100
  "printBasicPrototype": false
101
101
  }
102
102
  },
103
- "gitHead": "af69249562f9de5efbd47fd5553bcdb73b2eab4f"
103
+ "gitHead": "cc2918e84d2a42f2ea459680891bc5543911aa65"
104
104
  }