amis-formula 1.2.3 → 1.2.7

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.
@@ -196,65 +196,640 @@ export declare class Evaluator {
196
196
  identifier: string;
197
197
  args: Array<any>;
198
198
  }): any;
199
+ /**
200
+ * 示例:IF(A, B, C)
201
+ *
202
+ * 如果满足条件A,则返回B,否则返回C,支持多层嵌套IF函数。
203
+ *
204
+ * 也可以用表达式如:A ? B : C
205
+ *
206
+ * @example IF(condition, consequent, alternate)
207
+ * @param {expression} condition - 条件表达式.
208
+ * @param {any} consequent 条件判断通过的返回结果
209
+ * @param {any} alternate 条件判断不通过的返回结果
210
+ * @namespace 逻辑函数
211
+ *
212
+ * @returns {any} 根据条件返回不同的结果
213
+ */
199
214
  fnIF(condition: () => any, trueValue: () => any, falseValue: () => any): any;
215
+ /**
216
+ * 条件全部符合,返回 true,否则返回 false
217
+ *
218
+ * 示例:AND(语文成绩>80, 数学成绩>80)
219
+ *
220
+ * 语文成绩和数学成绩都大于 80,则返回 true,否则返回 false
221
+ *
222
+ * 也可以直接用表达式如:语文成绩>80 && 数学成绩>80
223
+ *
224
+ * @example AND(expression1, expression2, ...expressionN)
225
+ * @param {...expression} conditions - 条件表达式.
226
+ * @namespace 逻辑函数
227
+ *
228
+ * @returns {boolean}
229
+ */
200
230
  fnAND(...condtions: Array<() => any>): boolean;
231
+ /**
232
+ * 条件任意一个满足条件,返回 true,否则返回 false
233
+ *
234
+ * 示例:OR(语文成绩>80, 数学成绩>80)
235
+ *
236
+ * 语文成绩和数学成绩任意一个大于 80,则返回 true,否则返回 false
237
+ *
238
+ * 也可以直接用表达式如:语文成绩>80 || 数学成绩>80
239
+ *
240
+ * @example OR(expression1, expression2, ...expressionN)
241
+ * @param {...expression} conditions - 条件表达式.
242
+ * @namespace 逻辑函数
243
+ *
244
+ * @returns {boolean}
245
+ */
201
246
  fnOR(...condtions: Array<() => any>): boolean;
247
+ /**
248
+ * 异或处理,两个表达式同时为「真」,或者同时为「假」,则结果返回为「真」
249
+ *
250
+ * @example XOR(condition1, condition2)
251
+ * @param {expression} condition1 - 条件表达式1
252
+ * @param {expression} condition2 - 条件表达式2
253
+ * @namespace 逻辑函数
254
+ *
255
+ * @returns {boolean}
256
+ */
202
257
  fnXOR(c1: () => any, c2: () => any): boolean;
258
+ /**
259
+ * 判断函数集合,相当于多个 else if 合并成一个。
260
+ *
261
+ * 示例:IFS(语文成绩 > 80, "优秀", 语文成绩 > 60, "良", "继续努力")
262
+ *
263
+ * 如果语文成绩大于 80,则返回优秀,否则判断大于 60 分,则返回良,否则返回继续努力。
264
+ *
265
+ * @example IFS(condition1, result1, condition2, result2,...conditionN, resultN)
266
+ * @param {...any} args - 条件,返回值集合
267
+ * @namespace 逻辑函数
268
+ * @returns {any} 第一个满足条件的结果,没有命中的返回 false。
269
+ */
203
270
  fnIFS(...args: Array<() => any>): any;
271
+ /**
272
+ * 返回传入数字的绝对值
273
+ *
274
+ * @example ABS(num)
275
+ * @param {number} num - 数值
276
+ * @namespace 数学函数
277
+ *
278
+ * @returns {number} 传入数值的绝对值
279
+ */
204
280
  fnABS(a: number): number;
281
+ /**
282
+ * 获取最大值
283
+ *
284
+ * @example MAX(num1, num2, ...numN)
285
+ * @param {...number} num - 数值
286
+ * @namespace 数学函数
287
+ *
288
+ * @returns {number} 所有传入值中最大的那个
289
+ */
205
290
  fnMAX(...args: Array<any>): any;
291
+ /**
292
+ * 获取最小值
293
+ *
294
+ * @example MIN(num1, num2, ...numN)
295
+ * @param {...number} num - 数值
296
+ * @namespace 数学函数
297
+ *
298
+ * @returns {number} 所有传入值中最小的那个
299
+ */
206
300
  fnMIN(...args: Array<number>): any;
301
+ /**
302
+ * 求和
303
+ *
304
+ * @example SUM(num1, num2, ...numN)
305
+ * @param {...number} num - 数值
306
+ * @namespace 数学函数
307
+ *
308
+ * @returns {number} 所有传入数值的总和
309
+ */
207
310
  fnSUM(...args: Array<number>): any;
311
+ /**
312
+ * 将数值向下取整为最接近的整数
313
+ *
314
+ * @example INT(num)
315
+ * @param {number} num - 数值
316
+ * @namespace 数学函数
317
+ *
318
+ * @returns {number} 数值对应的整形
319
+ */
208
320
  fnINT(n: number): number;
321
+ /**
322
+ * 返回两数相除的余数,参数 number 是被除数,divisor 是除数
323
+ *
324
+ * @example MOD(num, divisor)
325
+ * @param {number} num - 被除数
326
+ * @param {number} divisor - 除数
327
+ * @namespace 数学函数
328
+ *
329
+ * @returns {number} 两数相除的余数
330
+ */
209
331
  fnMOD(a: number, b: number): number;
332
+ /**
333
+ * 圆周率 3.1415...
334
+ *
335
+ * @example PI()
336
+ * @namespace 数学函数
337
+ *
338
+ * @returns {number} 圆周率数值
339
+ */
210
340
  fnPI(): number;
341
+ /**
342
+ * 将数字四舍五入到指定的位数,可以设置小数位。
343
+ *
344
+ * @example ROUND(num[, numDigits = 2])
345
+ * @param {number} num - 要处理的数字
346
+ * @param {number} numDigits - 小数位数
347
+ * @namespace 数学函数
348
+ *
349
+ * @returns {number} 传入数值四舍五入后的结果
350
+ */
211
351
  fnROUND(a: number, b: number): number;
352
+ /**
353
+ * 将数字向下取整到指定的位数,可以设置小数位。
354
+ *
355
+ * @example FLOOR(num[, numDigits=2])
356
+ * @param {number} num - 要处理的数字
357
+ * @param {number} numDigits - 小数位数
358
+ * @namespace 数学函数
359
+ *
360
+ * @returns {number} 传入数值向下取整后的结果
361
+ */
212
362
  fnFLOOR(a: number, b: number): number;
363
+ /**
364
+ * 将数字向上取整到指定的位数,可以设置小数位。
365
+ *
366
+ * @example CEIL(num[, numDigits=2])
367
+ * @param {number} num - 要处理的数字
368
+ * @param {number} numDigits - 小数位数
369
+ * @namespace 数学函数
370
+ *
371
+ * @returns {number} 传入数值向上取整后的结果
372
+ */
213
373
  fnCEIL(a: number, b: number): number;
374
+ /**
375
+ * 开平方,参数 number 为非负数
376
+ *
377
+ * @example SQRT(num)
378
+ * @param {number} num - 要处理的数字
379
+ * @namespace 数学函数
380
+ *
381
+ * @returns {number} 开平方的结果
382
+ */
214
383
  fnSQRT(n: number): number;
384
+ /**
385
+ * 返回所有参数的平均值
386
+ *
387
+ * @example AVG(num1, num2, ...numN)
388
+ * @param {...number} num - 要处理的数字
389
+ * @namespace 数学函数
390
+ *
391
+ * @returns {number} 所有数值的平均值
392
+ */
215
393
  fnAVG(...args: Array<any>): number;
394
+ /**
395
+ * 将数值转为中文大写金额
396
+ *
397
+ * @example UPPERMONEY(num)
398
+ * @param {number} num - 要处理的数字
399
+ * @namespace 数学函数
400
+ *
401
+ * @returns {string} 数值中文大写字符
402
+ */
216
403
  fnUPPERMONEY(n: number): string;
404
+ /**
405
+ * 返回大于等于 0 且小于 1 的均匀分布随机实数。每一次触发计算都会变化。
406
+ *
407
+ * 示例:`RAND()*100`
408
+ *
409
+ * 返回 0-100 之间的随机数
410
+ *
411
+ * @example RAND()
412
+ * @namespace 数学函数
413
+ *
414
+ * @returns {number} 随机数
415
+ */
217
416
  fnRAND(): number;
218
417
  normalizeText(raw: any): string;
418
+ /**
419
+ * 返回传入文本左侧的指定长度字符串。
420
+ *
421
+ * @example LEFT(text, len)
422
+ * @param {string} text - 要处理的文本
423
+ * @param {number} len - 要处理的长度
424
+ * @namespace 文本函数
425
+ *
426
+ * @returns {string} 对应字符串
427
+ */
219
428
  fnLEFT(text: string, len: number): string;
429
+ /**
430
+ * 返回传入文本右侧的指定长度字符串。
431
+ *
432
+ * @example RIGHT(text, len)
433
+ * @param {string} text - 要处理的文本
434
+ * @param {number} len - 要处理的长度
435
+ * @namespace 文本函数
436
+ *
437
+ * @returns {string} 对应字符串
438
+ */
220
439
  fnRIGHT(text: string, len: number): string;
440
+ /**
441
+ * 计算文本的长度
442
+ *
443
+ * @example LEN(text)
444
+ * @param {string} text - 要处理的文本
445
+ * @namespace 文本函数
446
+ *
447
+ * @returns {number} 长度
448
+ */
221
449
  fnLEN(text: string): number;
450
+ /**
451
+ * 计算文本集合中所有文本的长度
452
+ *
453
+ * @example LENGTH(textArr)
454
+ * @param {string[]} textArr - 要处理的文本集合
455
+ * @namespace 文本函数
456
+ *
457
+ * @returns {number[]} 长度集合
458
+ */
222
459
  fnLENGTH(...args: any[]): any;
460
+ /**
461
+ * 判断文本是否为空
462
+ *
463
+ * @example ISEMPTY(text)
464
+ * @param {string} text - 要处理的文本
465
+ * @namespace 文本函数
466
+ *
467
+ * @returns {boolean} 判断结果
468
+ */
223
469
  fnISEMPTY(text: string): boolean;
470
+ /**
471
+ * 将多个传入值连接成文本
472
+ *
473
+ * @example CONCATENATE(text1, text2, ...textN)
474
+ * @param {...string} text - 文本集合
475
+ * @namespace 文本函数
476
+ *
477
+ * @returns {string} 连接后的文本
478
+ */
224
479
  fnCONCATENATE(...args: Array<any>): string;
480
+ /**
481
+ * 返回计算机字符集的数字代码所对应的字符。
482
+ *
483
+ * `CHAR(97)` 等价于 "a"
484
+ *
485
+ * @example CHAR(code)
486
+ * @param {number} code - 编码值
487
+ * @namespace 文本函数
488
+ *
489
+ * @returns {string} 指定位置的字符
490
+ */
225
491
  fnCHAR(code: number): string;
492
+ /**
493
+ * 将传入文本转成小写
494
+ *
495
+ * @example LOWER(text)
496
+ * @param {string} text - 文本
497
+ * @namespace 文本函数
498
+ *
499
+ * @returns {string} 结果文本
500
+ */
226
501
  fnLOWER(text: string): string;
502
+ /**
503
+ * 将传入文本转成大写
504
+ *
505
+ * @example UPPER(text)
506
+ * @param {string} text - 文本
507
+ * @namespace 文本函数
508
+ *
509
+ * @returns {string} 结果文本
510
+ */
227
511
  fnUPPER(text: string): string;
512
+ /**
513
+ * 将文本根据指定片段分割成数组
514
+ *
515
+ * 示例:`SPLIT("a,b,c", ",")`
516
+ *
517
+ * 返回 `["a", "b", "c"]`
518
+ *
519
+ * @example SPLIT(text, ',')
520
+ * @param {string} text - 文本
521
+ * @param {string} delimiter - 文本片段
522
+ * @namespace 文本函数
523
+ *
524
+ * @returns {Array<string>} 文本集
525
+ */
228
526
  fnSPLIT(text: string, sep?: string): string[];
527
+ /**
528
+ * 将文本去除前后空格
529
+ *
530
+ * @example TRIM(text)
531
+ * @param {string} text - 文本
532
+ * @namespace 文本函数
533
+ *
534
+ * @returns {string} 处理后的文本
535
+ */
229
536
  fnTRIM(text: string): string;
537
+ /**
538
+ * 判断字符串(text)是否以特定字符串(startString)开始,是则返回 True,否则返回 False
539
+ *
540
+ * @example STARTSWITH(text, '片段')
541
+ * @param {string} text - 文本
542
+ * @param {string} startString - 起始文本
543
+ * @namespace 文本函数
544
+ *
545
+ * @returns {string} 判断结果
546
+ */
230
547
  fnSTARTSWITH(text: string, search: string): boolean;
548
+ /**
549
+ * 判断参数 1 中的文本是否包含参数 2 中的文本。
550
+ *
551
+ * @example CONTAINS(text, searchText)
552
+ * @param {string} text - 文本
553
+ * @param {string} searchText - 搜索文本
554
+ * @namespace 文本函数
555
+ *
556
+ * @returns {string} 判断结果
557
+ */
231
558
  fnCONTAINS(text: string, search: string): boolean;
559
+ /**
560
+ * 对文本进行全量替换。
561
+ *
562
+ * @example REPLACE(text, search, replace)
563
+ * @param {string} text - 要处理的文本
564
+ * @param {string} search - 要被替换的文本
565
+ * @param {string} replace - 要替换的文本
566
+ * @namespace 文本函数
567
+ *
568
+ * @returns {string} 处理结果
569
+ */
232
570
  fnREPLACE(text: string, search: string, replace: string): string;
571
+ /**
572
+ * 对文本进行搜索,返回命中的位置
573
+ *
574
+ * @example SEARCH(text, search, 0)
575
+ * @param {string} text - 要处理的文本
576
+ * @param {string} search - 用来搜索的文本
577
+ * @param {number} start - 起始位置
578
+ * @namespace 文本函数
579
+ *
580
+ * @returns {number} 命中的位置
581
+ */
233
582
  fnSEARCH(text: string, search: string, start?: number): number;
583
+ /**
584
+ * 返回文本字符串中从指定位置开始的特定数目的字符
585
+ *
586
+ * @example MID(text, from, len)
587
+ * @param {string} text - 要处理的文本
588
+ * @param {number} from - 起始位置
589
+ * @param {number} len - 处理长度
590
+ * @namespace 文本函数
591
+ *
592
+ * @returns {number} 命中的位置
593
+ */
234
594
  fnMID(text: string, from: number, len: number): string;
595
+ /**
596
+ * 创建日期对象,可以通过特定格式的字符串,或者数值。
597
+ *
598
+ * 需要注意的是,其中月份的数值是从0开始的,也就是说,
599
+ * 如果是12月份,你应该传入数值11。
600
+ *
601
+ * @example DATE(2021, 11, 6, 8, 20, 0)
602
+ * @example DATE('2021-12-06 08:20:00')
603
+ * @namespace 日期函数
604
+ *
605
+ * @returns {Date} 日期对象
606
+ */
235
607
  fnDATE(year: number, month: number, day: number, hour: number, minute: number, second: number): Date;
608
+ /**
609
+ * 返回时间的时间戳
610
+ *
611
+ * @example TIMESTAMP(date[, format = "X"])
612
+ * @namespace 日期函数
613
+ * @param {date} date 日期对象
614
+ * @param {string} format 时间戳格式,带毫秒传入 'x'。默认为 'X' 不带毫秒的。
615
+ *
616
+ * @returns {number} 时间戳
617
+ */
236
618
  fnTIMESTAMP(date: Date, format?: 'x' | 'X'): number;
619
+ /**
620
+ * 返回今天的日期
621
+ *
622
+ * @example TODAY()
623
+ * @namespace 日期函数
624
+ *
625
+ * @returns {number} 日期
626
+ */
237
627
  fnTODAY(): Date;
628
+ /**
629
+ * 返回现在的日期
630
+ *
631
+ * @example NOW()
632
+ * @namespace 日期函数
633
+ *
634
+ * @returns {number} 日期
635
+ */
238
636
  fnNOW(): Date;
637
+ /**
638
+ * 将日期转成日期字符串
639
+ *
640
+ * @example DATETOSTR(date[, format="YYYY-MM-DD HH:mm:ss"])
641
+ * @namespace 日期函数
642
+ * @param {date} date 日期对象
643
+ * @param {string} format 日期格式,默认为 "YYYY-MM-DD HH:mm:ss"
644
+ *
645
+ * @returns {number} 日期字符串
646
+ */
239
647
  fnDATETOSTR(date: Date, format?: string): string;
648
+ /**
649
+ * 返回日期的指定范围的开端
650
+ *
651
+ * @namespace 日期函数
652
+ * @example STARTOF(date[unit = "day"])
653
+ * @param {date} date 日期对象
654
+ * @param {string} unit 比如可以传入 'day'、'month'、'year' 或者 `week` 等等
655
+ * @returns {date} 新的日期对象
656
+ */
240
657
  fnSTARTOF(date: Date, unit?: any): Date;
658
+ /**
659
+ * 返回日期的指定范围的末尾
660
+ * @namespace 日期函数
661
+ * @example ENDOF(date[unit = "day"])
662
+ * @param {date} date 日期对象
663
+ * @param {string} unit 比如可以传入 'day'、'month'、'year' 或者 `week` 等等
664
+ * @returns {date} 新的日期对象
665
+ */
241
666
  fnENDOF(date: Date, unit?: any): Date;
242
667
  normalizeDate(raw: any): Date;
668
+ /**
669
+ * 返回日期的年份
670
+ * @namespace 日期函数
671
+ * @example YEAR(date)
672
+ * @param {date} date 日期对象
673
+ * @returns {number} 数值
674
+ */
243
675
  fnYEAR(date: Date): number;
676
+ /**
677
+ * 返回日期的月份,这里就是自然月份。
678
+ *
679
+ * @namespace 日期函数
680
+ * @example MONTH(date)
681
+ * @param {date} date 日期对象
682
+ * @returns {number} 数值
683
+ */
244
684
  fnMONTH(date: Date): number;
685
+ /**
686
+ * 返回日期的天
687
+ * @namespace 日期函数
688
+ * @example DAY(date)
689
+ * @param {date} date 日期对象
690
+ * @returns {number} 数值
691
+ */
245
692
  fnDAY(date: Date): number;
693
+ /**
694
+ * 返回日期的小时
695
+ * @param {date} date 日期对象
696
+ * @namespace 日期函数
697
+ * @example HOUR(date)
698
+ * @returns {number} 数值
699
+ */
246
700
  fnHOUR(date: Date): number;
247
- fnHMINUTE(date: Date): number;
701
+ /**
702
+ * 返回日期的分
703
+ * @param {date} date 日期对象
704
+ * @namespace 日期函数
705
+ * @example MINUTE(date)
706
+ * @returns {number} 数值
707
+ */
708
+ fnMINUTE(date: Date): number;
709
+ /**
710
+ * 返回日期的秒
711
+ * @param {date} date 日期对象
712
+ * @namespace 日期函数
713
+ * @example SECOND(date)
714
+ * @returns {number} 数值
715
+ */
248
716
  fnSECOND(date: Date): number;
717
+ /**
718
+ * 返回两个日期相差多少年
719
+ * @param {date} endDate 日期对象
720
+ * @param {date} startDate 日期对象
721
+ * @namespace 日期函数
722
+ * @example YEARS(endDate, startDate)
723
+ * @returns {number} 数值
724
+ */
249
725
  fnYEARS(endDate: Date, startDate: Date): number;
726
+ /**
727
+ * 返回两个日期相差多少分钟
728
+ * @param {date} endDate 日期对象
729
+ * @param {date} startDate 日期对象
730
+ * @namespace 日期函数
731
+ * @example MINUTES(endDate, startDate)
732
+ * @returns {number} 数值
733
+ */
250
734
  fnMINUTES(endDate: Date, startDate: Date): number;
735
+ /**
736
+ * 返回两个日期相差多少天
737
+ * @param {date} endDate 日期对象
738
+ * @param {date} startDate 日期对象
739
+ * @namespace 日期函数
740
+ * @example DAYS(endDate, startDate)
741
+ * @returns {number} 数值
742
+ */
251
743
  fnDAYS(endDate: Date, startDate: Date): number;
744
+ /**
745
+ * 返回两个日期相差多少小时
746
+ * @param {date} endDate 日期对象
747
+ * @param {date} startDate 日期对象
748
+ * @namespace 日期函数
749
+ * @example HOURS(endDate, startDate)
750
+ * @returns {number} 数值
751
+ */
252
752
  fnHOURS(endDate: Date, startDate: Date): number;
753
+ /**
754
+ * 修改日期,对日期进行加减天、月份、年等操作
755
+ *
756
+ * 示例:
757
+ *
758
+ * DATEMODIFY(A, -2, 'month')
759
+ *
760
+ * 对日期 A 进行往前减2月的操作。
761
+ *
762
+ * @param {date} date 日期对象
763
+ * @param {number} num 数值
764
+ * @param {string} unit 单位:支持年、月、天等等
765
+ * @namespace 日期函数
766
+ * @example DATEMODIFY(date, 2, 'days')
767
+ * @returns {date} 日期对象
768
+ */
253
769
  fnDATEMODIFY(date: Date, num: number, format: any): Date;
770
+ /**
771
+ * 将字符日期转成日期对象,可以指定日期格式。
772
+ *
773
+ * 示例:STRTODATE('2021/12/6', 'YYYY/MM/DD')
774
+ *
775
+ * @param {string} value 日期字符
776
+ * @param {string} format 日期格式
777
+ * @namespace 日期函数
778
+ * @example STRTODATE(value[, format=""])
779
+ * @returns {date} 日期对象
780
+ */
254
781
  fnSTRTODATE(value: any, format?: string): Date;
782
+ /**
783
+ * 判断两个日期,是否第一个日期在第二个日期的前面
784
+ *
785
+ * @param {date} a 第一个日期
786
+ * @param {date} b 第二个日期
787
+ * @param {string} unit 单位,默认是 'day', 即之比较到天
788
+ * @namespace 日期函数
789
+ * @example ISBEFORE(a, b)
790
+ * @returns {boolean} 判断结果
791
+ */
255
792
  fnISBEFORE(a: Date, b: Date, unit?: any): boolean;
793
+ /**
794
+ * 判断两个日期,是否第一个日期在第二个日期的后面
795
+ *
796
+ * @param {date} a 第一个日期
797
+ * @param {date} b 第二个日期
798
+ * @param {string} unit 单位,默认是 'day', 即之比较到天
799
+ * @namespace 日期函数
800
+ * @example ISAFTER(a, b)
801
+ * @returns {boolean} 判断结果
802
+ */
256
803
  fnISAFTER(a: Date, b: Date, unit?: any): boolean;
804
+ /**
805
+ * 判断两个日期,是否第一个日期在第二个日期的前面或者相等
806
+ *
807
+ * @param {date} a 第一个日期
808
+ * @param {date} b 第二个日期
809
+ * @param {string} unit 单位,默认是 'day', 即之比较到天
810
+ * @namespace 日期函数
811
+ * @example ISSAMEORBEFORE(a, b)
812
+ * @returns {boolean} 判断结果
813
+ */
257
814
  fnISSAMEORBEFORE(a: Date, b: Date, unit?: any): boolean;
815
+ /**
816
+ * 判断两个日期,是否第一个日期在第二个日期的后面或者相等
817
+ *
818
+ * @param {date} a 第一个日期
819
+ * @param {date} b 第二个日期
820
+ * @param {string} unit 单位,默认是 'day', 即之比较到天
821
+ * @namespace 日期函数
822
+ * @example ISSAMEORAFTER(a, b)
823
+ * @returns {boolean} 判断结果
824
+ */
258
825
  fnISSAMEORAFTER(a: Date, b: Date, unit?: any): boolean;
826
+ /**
827
+ * 返回数组的长度
828
+ *
829
+ * @param {Array<any>} arr 数组
830
+ * @namespace 其他
831
+ * @example COUNT(arr)
832
+ * @returns {boolean} 结果
833
+ */
259
834
  fnCOUNT(value: any): number;
260
835
  }