amis-formula 2.0.0 → 2.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/lib/doc.js CHANGED
@@ -974,7 +974,7 @@ exports.doc = [
974
974
  {
975
975
  name: "TIMESTAMP",
976
976
  description: "返回时间的时间戳",
977
- example: "TIMESTAMP(date[, format = \"X\"])",
977
+ example: "TIMESTAMP(date, 'x')",
978
978
  params: [
979
979
  {
980
980
  type: "date",
@@ -1018,7 +1018,7 @@ exports.doc = [
1018
1018
  {
1019
1019
  name: "DATETOSTR",
1020
1020
  description: "将日期转成日期字符串",
1021
- example: "DATETOSTR(date[, format=\"YYYY-MM-DD HH:mm:ss\"])",
1021
+ example: "DATETOSTR(date, 'YYYY-MM-DD')",
1022
1022
  params: [
1023
1023
  {
1024
1024
  type: "date",
package/lib/doc.md CHANGED
@@ -591,7 +591,7 @@
591
591
 
592
592
  ### TIMESTAMP
593
593
 
594
- 用法:`TIMESTAMP(date[, format = "X"])`
594
+ 用法:`TIMESTAMP(date, 'x')`
595
595
 
596
596
  * `date:date` 日期对象
597
597
  * `format:string` 时间戳格式,带毫秒传入 'x'。默认为 'X' 不带毫秒的。
@@ -614,7 +614,7 @@
614
614
 
615
615
  ### DATETOSTR
616
616
 
617
- 用法:`DATETOSTR(date[, format="YYYY-MM-DD HH:mm:ss"])`
617
+ 用法:`DATETOSTR(date, 'YYYY-MM-DD')`
618
618
 
619
619
  * `date:date` 日期对象
620
620
  * `format:string` 日期格式,默认为 "YYYY-MM-DD HH:mm:ss"
package/lib/evalutor.d.ts CHANGED
@@ -775,6 +775,7 @@ export declare class Evaluator {
775
775
  * 返回时间的时间戳
776
776
  *
777
777
  * @example TIMESTAMP(date[, format = "X"])
778
+ * @example TIMESTAMP(date, 'x')
778
779
  * @namespace 日期函数
779
780
  * @param {date} date 日期对象
780
781
  * @param {string} format 时间戳格式,带毫秒传入 'x'。默认为 'X' 不带毫秒的。
@@ -804,6 +805,7 @@ export declare class Evaluator {
804
805
  * 将日期转成日期字符串
805
806
  *
806
807
  * @example DATETOSTR(date[, format="YYYY-MM-DD HH:mm:ss"])
808
+ * @example DATETOSTR(date, 'YYYY-MM-DD')
807
809
  * @namespace 日期函数
808
810
  * @param {date} date 日期对象
809
811
  * @param {string} format 日期格式,默认为 "YYYY-MM-DD HH:mm:ss"
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-formula v2.0.0
2
+ * amis-formula v2.1.0
3
3
  * Copyright 2021-2022 fex
4
4
  */
5
5
 
@@ -532,10 +532,7 @@ var Evaluator = /** @class */ (function () {
532
532
  for (var _i = 0; _i < arguments.length; _i++) {
533
533
  args[_i] = arguments[_i];
534
534
  }
535
- var arr = args;
536
- if (args.length === 1 && Array.isArray(args[0])) {
537
- arr = args[0];
538
- }
535
+ var arr = normalizeArgs(args);
539
536
  return Math.max.apply(Math, arr.map(function (item) { return _this.formatNumber(item); }));
540
537
  };
541
538
  /**
@@ -553,10 +550,7 @@ var Evaluator = /** @class */ (function () {
553
550
  for (var _i = 0; _i < arguments.length; _i++) {
554
551
  args[_i] = arguments[_i];
555
552
  }
556
- var arr = args;
557
- if (args.length === 1 && Array.isArray(args[0])) {
558
- arr = args[0];
559
- }
553
+ var arr = normalizeArgs(args);
560
554
  return Math.min.apply(Math, arr.map(function (item) { return _this.formatNumber(item); }));
561
555
  };
562
556
  /**
@@ -574,10 +568,7 @@ var Evaluator = /** @class */ (function () {
574
568
  for (var _i = 0; _i < arguments.length; _i++) {
575
569
  args[_i] = arguments[_i];
576
570
  }
577
- var arr = args;
578
- if (args.length === 1 && Array.isArray(args[0])) {
579
- arr = args[0];
580
- }
571
+ var arr = normalizeArgs(args);
581
572
  return arr.reduce(function (sum, a) { return sum + _this.formatNumber(a) || 0; }, 0);
582
573
  };
583
574
  /**
@@ -703,10 +694,7 @@ var Evaluator = /** @class */ (function () {
703
694
  for (var _i = 0; _i < arguments.length; _i++) {
704
695
  args[_i] = arguments[_i];
705
696
  }
706
- var arr = args;
707
- if (args.length === 1 && Array.isArray(args[0])) {
708
- arr = args[0];
709
- }
697
+ var arr = normalizeArgs(args);
710
698
  return (this.fnSUM.apply(this, arr.map(function (item) { return _this.formatNumber(item); })) / arr.length);
711
699
  };
712
700
  /**
@@ -727,10 +715,7 @@ var Evaluator = /** @class */ (function () {
727
715
  if (args.length === 0) {
728
716
  return null;
729
717
  }
730
- var arr = args;
731
- if (args.length === 1 && Array.isArray(args[0])) {
732
- arr = args[0];
733
- }
718
+ var arr = normalizeArgs(args);
734
719
  var nums = arr.map(function (item) { return _this.formatNumber(item); });
735
720
  var sum = nums.reduce(function (sum, a) { return sum + a || 0; }, 0);
736
721
  var mean = sum / nums.length;
@@ -1342,6 +1327,7 @@ var Evaluator = /** @class */ (function () {
1342
1327
  * 返回时间的时间戳
1343
1328
  *
1344
1329
  * @example TIMESTAMP(date[, format = "X"])
1330
+ * @example TIMESTAMP(date, 'x')
1345
1331
  * @namespace 日期函数
1346
1332
  * @param {date} date 日期对象
1347
1333
  * @param {string} format 时间戳格式,带毫秒传入 'x'。默认为 'X' 不带毫秒的。
@@ -1377,6 +1363,7 @@ var Evaluator = /** @class */ (function () {
1377
1363
  * 将日期转成日期字符串
1378
1364
  *
1379
1365
  * @example DATETOSTR(date[, format="YYYY-MM-DD HH:mm:ss"])
1366
+ * @example DATETOSTR(date, 'YYYY-MM-DD')
1380
1367
  * @namespace 日期函数
1381
1368
  * @param {date} date 日期对象
1382
1369
  * @param {string} format 日期格式,默认为 "YYYY-MM-DD HH:mm:ss"
@@ -1793,6 +1780,14 @@ function stripNumber(number) {
1793
1780
  return number;
1794
1781
  }
1795
1782
  }
1783
+ // 如果只有一个成员,同时第一个成员为 args
1784
+ // 则把它展开,当成是多个参数,毕竟公式里面还不支持 ...args 语法,
1785
+ function normalizeArgs(args) {
1786
+ if (args.length === 1 && Array.isArray(args[0])) {
1787
+ args = args[0];
1788
+ }
1789
+ return args;
1790
+ }
1796
1791
  function createObject(superProps, props, properties) {
1797
1792
  var obj = superProps
1798
1793
  ? Object.create(superProps, tslib.__assign(tslib.__assign({}, properties), { __super: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amis-formula",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "负责 amis 里面的表达式实现,内置公式,编辑器等",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -35,7 +35,7 @@
35
35
  "homepage": "https://github.com/aisuda/amis-tpl#readme",
36
36
  "dependencies": {
37
37
  "lodash": "^4.17.15",
38
- "moment": "^2.29.1",
38
+ "moment": "^2.29.4",
39
39
  "tslib": "^2.3.1"
40
40
  },
41
41
  "devDependencies": {
@@ -56,7 +56,7 @@
56
56
  "rollup": "^2.60.2",
57
57
  "rollup-plugin-license": "^2.6.0",
58
58
  "rollup-plugin-terser": "^7.0.2",
59
- "sass": "^1.36.0",
59
+ "sass": "^1.54.0",
60
60
  "sass-loader": "^12.1.0",
61
61
  "style-loader": "^3.2.1",
62
62
  "stylelint": "^13.0.0",
@@ -96,5 +96,5 @@
96
96
  }
97
97
  }
98
98
  },
99
- "gitHead": "32dc0167ca8637559ac487006c0e78b627573759"
99
+ "gitHead": "0c57e9936e83d55b75fb162667e15c84c09fc4ff"
100
100
  }