amis-formula 2.7.2 → 2.8.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/evalutor.d.ts CHANGED
@@ -804,17 +804,75 @@ export declare class Evaluator {
804
804
  */
805
805
  fnNOW(): Date;
806
806
  /**
807
- * 将日期转成日期字符串
807
+ * 获取日期的星期几,
808
+ *
809
+ * 示例:
810
+ *
811
+ * WEEKDAY('2023-02-27') 得到 1
812
+ *
813
+ * @example WEEKDAY(date)
814
+ * @namespace 日期函数
815
+ * @param {any} date 日期
816
+ * @param {number} type 星期定义类型,默认为1,1表示0至6代表星期一到星期日,2表示1至7代表星期一到星期日
817
+ *
818
+ * @returns {number} 星期几的数字标识
819
+ */
820
+ fnWEEKDAY(date: Date | string | number, type?: number): number;
821
+ /**
822
+ * 获取年份的星期,即第几周
823
+ *
824
+ * 示例:
825
+ *
826
+ * WEEK('2023-03-05') 得到 10
827
+ *
828
+ * @example WEEK(date)
829
+ * @namespace 日期函数
830
+ * @param {any} date 日期
831
+ * @param {boolean} isISO 是否ISO星期
832
+ *
833
+ * @returns {number} 星期几的数字标识
834
+ */
835
+ fnWEEK(date: Date | string | number, isISO?: boolean): number;
836
+ /**
837
+ * 对日期、日期字符串、时间戳进行格式化
838
+ *
839
+ * 示例:
840
+ *
841
+ * DATETOSTR('12/25/2022', 'YYYY-MM-DD') 得到 '2022.12.25'
842
+ * DATETOSTR(1676563200, 'YYYY.MM.DD') 得到 '2023.02.17'
843
+ * DATETOSTR(1676563200000, 'YYYY.MM.DD hh:mm:ss') 得到 '2023.02.17 12:00:00'
844
+ * DATETOSTR(DATE('2021-12-21'), 'YYYY.MM.DD hh:mm:ss') 得到 '2021.12.21 08:00:00'
808
845
  *
809
- * @example DATETOSTR(date[, format="YYYY-MM-DD HH:mm:ss"])
810
846
  * @example DATETOSTR(date, 'YYYY-MM-DD')
811
847
  * @namespace 日期函数
812
- * @param {date} date 日期对象
848
+ * @param {any} date 日期对象、日期字符串、时间戳
813
849
  * @param {string} format 日期格式,默认为 "YYYY-MM-DD HH:mm:ss"
814
850
  *
815
- * @returns {number} 日期字符串
851
+ * @returns {string} 日期字符串
816
852
  */
817
- fnDATETOSTR(date: Date, format?: string): string;
853
+ fnDATETOSTR(date: Date | string | number, format?: string): string;
854
+ /**
855
+ * 获取日期范围字符串中的开始时间、结束时间
856
+ *
857
+ * 示例:
858
+ *
859
+ * DATERANGESPLIT('1676563200, 1676735999') 得到 [1676563200, 1676735999]
860
+ * DATERANGESPLIT('1676563200, 1676735999', undefined , 'YYYY.MM.DD hh:mm:ss') 得到 [2023.02.17 12:00:00, 2023.02.18 11:59:59]
861
+ * DATERANGESPLIT('1676563200, 1676735999', 0 , 'YYYY.MM.DD hh:mm:ss') 得到 '2023.02.17 12:00:00'
862
+ * DATERANGESPLIT('1676563200, 1676735999', 'start' , 'YYYY.MM.DD hh:mm:ss') 得到 '2023.02.17 12:00:00'
863
+ * DATERANGESPLIT('1676563200, 1676735999', 1 , 'YYYY.MM.DD hh:mm:ss') 得到 '2023.02.18 11:59:59'
864
+ * DATERANGESPLIT('1676563200, 1676735999', 'end' , 'YYYY.MM.DD hh:mm:ss') 得到 '2023.02.18 11:59:59'
865
+ *
866
+ * @example DATERANGESPLIT(date, 'YYYY-MM-DD')
867
+ * @namespace 日期函数
868
+ * @param {string} date 日期范围字符串
869
+ * @param {string} key 取值标识,0或'start'表示获取开始时间,1或'end'表示获取结束时间
870
+ * @param {string} format 日期格式,可选
871
+ * @param {string} delimiter 分隔符,可选,默认为','
872
+ *
873
+ * @returns {string} 日期字符串
874
+ */
875
+ fnDATERANGESPLIT(daterange: string, key?: string, format?: string, delimiter?: string): string | string[];
818
876
  /**
819
877
  * 返回日期的指定范围的开端
820
878
  *
@@ -822,19 +880,22 @@ export declare class Evaluator {
822
880
  * @example STARTOF(date[unit = "day"])
823
881
  * @param {date} date 日期对象
824
882
  * @param {string} unit 比如可以传入 'day'、'month'、'year' 或者 `week` 等等
883
+ * @param {string} format 日期格式,可选
825
884
  * @returns {date} 新的日期对象
826
885
  */
827
- fnSTARTOF(date: Date, unit?: any): Date;
886
+ fnSTARTOF(date: Date, unit?: any, format?: string): string | Date;
828
887
  /**
829
888
  * 返回日期的指定范围的末尾
830
889
  * @namespace 日期函数
831
890
  * @example ENDOF(date[unit = "day"])
832
891
  * @param {date} date 日期对象
833
892
  * @param {string} unit 比如可以传入 'day'、'month'、'year' 或者 `week` 等等
893
+ * @param {string} format 日期格式,可选
834
894
  * @returns {date} 新的日期对象
835
895
  */
836
- fnENDOF(date: Date, unit?: any): Date;
896
+ fnENDOF(date: Date, unit?: any, format?: string): string | Date;
837
897
  normalizeDate(raw: any): Date;
898
+ normalizeDateRange(raw: string | Date[]): Date[];
838
899
  /**
839
900
  * 返回日期的年份
840
901
  * @namespace 日期函数
@@ -971,6 +1032,20 @@ export declare class Evaluator {
971
1032
  * @returns {boolean} 判断结果
972
1033
  */
973
1034
  fnISAFTER(a: Date, b: Date, unit?: any): boolean;
1035
+ /**
1036
+ * 判断日期是否在指定范围内
1037
+ *
1038
+ * 示例:BETWEENRANGE('2021/12/6', ['2021/12/5','2021/12/7'])
1039
+ *
1040
+ * @param {any} date 第一个日期
1041
+ * @param {any[]} daterange 日期范围
1042
+ * @param {string} unit 单位,默认是 'day', 即之比较到天
1043
+ * @param {string} inclusivity 包容性规则,默认为'[]'。[ 表示包含、( 表示排除,如果使用包容性参数,则必须传入两个指示符,如'()'表示左右范围都排除
1044
+ * @namespace 日期函数
1045
+ * @example BETWEENRANGE(date, [start, end])
1046
+ * @returns {boolean} 判断结果
1047
+ */
1048
+ fnBETWEENRANGE(date: Date, daterange: Date[], unit?: any, inclusivity?: '[]' | '()' | '(]' | '[)'): boolean;
974
1049
  /**
975
1050
  * 判断两个日期,是否第一个日期在第二个日期的前面或者相等
976
1051
  *
@@ -1023,6 +1098,80 @@ export declare class Evaluator {
1023
1098
  * @returns {boolean} 结果
1024
1099
  */
1025
1100
  fnARRAYFILTER(value: any, iterator: any): any[];
1101
+ /**
1102
+ * 数据做数据查找,需要搭配箭头函数一起使用,注意箭头函数只支持单表达式用法。
1103
+ * 找出第二个箭头函数返回为 true 的成员的索引。
1104
+ *
1105
+ * 示例:
1106
+ *
1107
+ * ARRAYFINDINDEX([0, 2, false], item => item === 2) 得到 1
1108
+ *
1109
+ * @param {Array<any>} arr 数组
1110
+ * @param {Function<any>} iterator 箭头函数
1111
+ * @namespace 数组
1112
+ * @example ARRAYFINDINDEX(arr, item => item === 2)
1113
+ * @returns {number} 结果
1114
+ */
1115
+ fnARRAYFINDINDEX(arr: any[], iterator: any): number;
1116
+ /**
1117
+ * 数据做数据查找,需要搭配箭头函数一起使用,注意箭头函数只支持单表达式用法。
1118
+ * 找出第二个箭头函数返回为 true 的成员。
1119
+ *
1120
+ * 示例:
1121
+ *
1122
+ * ARRAYFIND([0, 2, false], item => item === 2) 得到 2
1123
+ *
1124
+ * @param {Array<any>} arr 数组
1125
+ * @param {Function<any>} iterator 箭头函数
1126
+ * @namespace 数组
1127
+ * @example ARRAYFIND(arr, item => item === 2)
1128
+ * @returns {any} 结果
1129
+ */
1130
+ fnARRAYFIND(arr: any[], iterator: any): any;
1131
+ /**
1132
+ * 数据做数据遍历判断,需要搭配箭头函数一起使用,注意箭头函数只支持单表达式用法。
1133
+ * 判断第二个箭头函数是否存在返回为 true 的成员。
1134
+ *
1135
+ * 示例:
1136
+ *
1137
+ * ARRAYSOME([0, 2, false], item => item === 2) 得到 true
1138
+ *
1139
+ * @param {Array<any>} arr 数组
1140
+ * @param {Function<any>} iterator 箭头函数
1141
+ * @namespace 数组
1142
+ * @example ARRAYSOME(arr, item => item === 2)
1143
+ * @returns {boolean} 结果
1144
+ */
1145
+ fnARRAYSOME(arr: any[], iterator: any): boolean;
1146
+ /**
1147
+ * 数据做数据遍历判断,需要搭配箭头函数一起使用,注意箭头函数只支持单表达式用法。
1148
+ * 判断第二个箭头函数返回是否都为 true。
1149
+ *
1150
+ * 示例:
1151
+ *
1152
+ * ARRAYEVERY([0, 2, false], item => item === 2) 得到 false
1153
+ *
1154
+ * @param {Array<any>} arr 数组
1155
+ * @param {Function<any>} iterator 箭头函数
1156
+ * @namespace 数组
1157
+ * @example ARRAYEVERY(arr, item => item === 2)
1158
+ * @returns {boolean} 结果
1159
+ */
1160
+ fnARRAYEVERY(arr: any[], iterator: any): boolean;
1161
+ /**
1162
+ * 判断数据中是否存在指定元素
1163
+ *
1164
+ * 示例:
1165
+ *
1166
+ * ARRAYINCLUDES([0, 2, false], 2) 得到 true
1167
+ *
1168
+ * @param {Array<any>} arr 数组
1169
+ * @param {any} item 元素
1170
+ * @namespace 数组
1171
+ * @example ARRAYINCLUDES(arr, 2)
1172
+ * @returns {any} 结果
1173
+ */
1174
+ fnARRAYINCLUDES(arr: any[], item: any): boolean;
1026
1175
  /**
1027
1176
  * 数组过滤掉 false、null、0 和 ""
1028
1177
  *
@@ -1078,13 +1227,58 @@ export declare class Evaluator {
1078
1227
  * @returns {Array<any>} 结果
1079
1228
  */
1080
1229
  fnUNIQ(arr: any[], field?: string): any[];
1230
+ /**
1231
+ * 将JS对象转换成JSON字符串
1232
+ *
1233
+ * 示例:
1234
+ *
1235
+ * ENCODEJSON({name: 'amis'}) 得到 '{"name":"amis"}'
1236
+ *
1237
+ * @param {object} obj JS对象
1238
+ * @namespace 编码
1239
+ * @example ENCODEJSON({name: 'amis'})
1240
+ * @returns {string} 结果
1241
+ */
1242
+ fnENCODEJSON(obj: object): string;
1243
+ /**
1244
+ * 解析JSON编码数据,返回JS对象
1245
+ *
1246
+ * 示例:
1247
+ *
1248
+ * DECODEJSON('{\"name\": "amis"}') 得到 {name: 'amis'}
1249
+ *
1250
+ * @param {string} str 字符串
1251
+ * @namespace 编码
1252
+ * @example DECODEJSON('{\"name\": "amis"}')
1253
+ * @returns {object} 结果
1254
+ */
1255
+ fnDECODEJSON(str: string): object;
1256
+ /**
1257
+ * 根据对象或者数组的path路径获取值。 如果解析 value 是 undefined 会以 defaultValue 取代
1258
+ *
1259
+ * 示例:
1260
+ *
1261
+ * GET([0, 2, {name: 'amis', age: 18}], 1) 得到 2
1262
+ * GET([0, 2, {name: 'amis', age: 18}], '2.name') 得到 'amis'
1263
+ * GET({arr: [{name: 'amis', age: 18}]}, 'arr[0].name') 得到 'amis'
1264
+ * GET({arr: [{name: 'amis', age: 18}]}, 'arr.0.name') 得到 'amis'
1265
+ * GET({arr: [{name: 'amis', age: 18}]}, 'arr.1.name', 'not-found') 得到 'not-found'
1266
+ *
1267
+ * @param {any} obj 对象或数组
1268
+ * @param {string} path 路径
1269
+ * @param {any} defaultValue 如果解析不到则返回该值
1270
+ * @namespace 其他
1271
+ * @example GET(arr, 2)
1272
+ * @returns {any} 结果
1273
+ */
1274
+ fnGET(obj: any, path: string, defaultValue?: any): any;
1081
1275
  /**
1082
1276
  * 判断是否为类型支持:string, number, array, date, plain-object。
1083
1277
  *
1084
1278
  * @param {string} 判断对象
1085
1279
  * @namespace 其他
1086
1280
  * @example ISTYPE([{a: '1'}, {b: '2'}, {a: '1'}], 'array')
1087
- * @returns {boolean} 结果结果
1281
+ * @returns {boolean} 结果
1088
1282
  */
1089
1283
  fnISTYPE(target: any, type: 'string' | 'number' | 'array' | 'date' | 'plain-object' | 'nil'): boolean;
1090
1284
  }