amis-formula 1.2.6 → 1.3.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/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # amis-tpl
2
2
 
3
- 负责 amis 里面的表达式实现,内置公式,编辑器等
3
+ 负责 amis 里面的表达式、公式及模板的实现
4
4
 
5
5
  属于 [amis](https://github.com/baidu/amis) 子项目
package/dist/doc.js CHANGED
@@ -320,6 +320,79 @@ export default [
320
320
  },
321
321
  namespace: "数学函数"
322
322
  },
323
+ {
324
+ name: "DEVSQ",
325
+ description: "返回数据点与数据均值点之差(数据偏差)的平方和",
326
+ example: "DEVSQ(num1, num2, ...numN)",
327
+ params: [
328
+ {
329
+ type: "...number",
330
+ name: "num",
331
+ description: "要处理的数字"
332
+ }
333
+ ],
334
+ returns: {
335
+ type: "number",
336
+ description: "所有数值的平均值"
337
+ },
338
+ namespace: "数学函数"
339
+ },
340
+ {
341
+ name: "AVEDEV",
342
+ description: "数据点到其算术平均值的绝对偏差的平均值",
343
+ example: "AVEDEV(num1, num2, ...numN)",
344
+ params: [
345
+ {
346
+ type: "...number",
347
+ name: "num",
348
+ description: "要处理的数字"
349
+ }
350
+ ],
351
+ returns: {
352
+ type: "number",
353
+ description: "所有数值的平均值"
354
+ },
355
+ namespace: "数学函数"
356
+ },
357
+ {
358
+ name: "HARMEAN",
359
+ description: "数据点的调和平均值",
360
+ example: "HARMEAN(num1, num2, ...numN)",
361
+ params: [
362
+ {
363
+ type: "...number",
364
+ name: "num",
365
+ description: "要处理的数字"
366
+ }
367
+ ],
368
+ returns: {
369
+ type: "number",
370
+ description: "所有数值的平均值"
371
+ },
372
+ namespace: "数学函数"
373
+ },
374
+ {
375
+ name: "LARGE",
376
+ description: "数据集中第 k 个最大值",
377
+ example: "LARGE(array, k)",
378
+ params: [
379
+ {
380
+ type: "array",
381
+ name: "nums",
382
+ description: "要处理的数字"
383
+ },
384
+ {
385
+ type: "number",
386
+ name: "k",
387
+ description: "第几大"
388
+ }
389
+ ],
390
+ returns: {
391
+ type: "number",
392
+ description: "所有数值的平均值"
393
+ },
394
+ namespace: "数学函数"
395
+ },
323
396
  {
324
397
  name: "UPPERMONEY",
325
398
  description: "将数值转为中文大写金额",
@@ -511,6 +584,128 @@ export default [
511
584
  },
512
585
  namespace: "文本函数"
513
586
  },
587
+ {
588
+ name: "UPPERFIRST",
589
+ description: "将传入文本首字母转成大写",
590
+ example: "UPPERFIRST(text)",
591
+ params: [
592
+ {
593
+ type: "string",
594
+ name: "text",
595
+ description: "文本"
596
+ }
597
+ ],
598
+ returns: {
599
+ type: "string",
600
+ description: "结果文本"
601
+ },
602
+ namespace: "文本函数"
603
+ },
604
+ {
605
+ name: "PADSTART",
606
+ description: "向前补齐文本长度\n\n示例 `PADSTART(\"6\", 2, \"0\")`\n\n返回 `06`",
607
+ example: "PADSTART(text)",
608
+ params: [
609
+ {
610
+ type: "string",
611
+ name: "text",
612
+ description: "文本"
613
+ },
614
+ {
615
+ type: "number",
616
+ name: "num",
617
+ description: "目标长度"
618
+ },
619
+ {
620
+ type: "string",
621
+ name: "pad",
622
+ description: "用于补齐的文本"
623
+ }
624
+ ],
625
+ returns: {
626
+ type: "string",
627
+ description: "结果文本"
628
+ },
629
+ namespace: "文本函数"
630
+ },
631
+ {
632
+ name: "CAPITALIZE",
633
+ description: "将文本转成标题\n\n示例 `CAPITALIZE(\"star\")`\n\n返回 `Star`",
634
+ example: "CAPITALIZE(text)",
635
+ params: [
636
+ {
637
+ type: "string",
638
+ name: "text",
639
+ description: "文本"
640
+ }
641
+ ],
642
+ returns: {
643
+ type: "string",
644
+ description: "结果文本"
645
+ },
646
+ namespace: "文本函数"
647
+ },
648
+ {
649
+ name: "ESCAPE",
650
+ description: "对文本进行 HTML 转义\n\n示例 `ESCAPE(\"star\")`\n\n返回 `Star`",
651
+ example: "ESCAPE(text)",
652
+ params: [
653
+ {
654
+ type: "string",
655
+ name: "text",
656
+ description: "文本"
657
+ }
658
+ ],
659
+ returns: {
660
+ type: "string",
661
+ description: "结果文本"
662
+ },
663
+ namespace: "文本函数"
664
+ },
665
+ {
666
+ name: "TRUNCATE",
667
+ description: "对文本长度进行截断\n\n示例 `TRUNCATE(\"amis.baidu.com\", 6)`\n\n返回 `amis...`",
668
+ example: "TRUNCATE(text, 6)",
669
+ params: [
670
+ {
671
+ type: "string",
672
+ name: "text",
673
+ description: "文本"
674
+ },
675
+ {
676
+ type: "number",
677
+ name: "text",
678
+ description: "最长长度"
679
+ }
680
+ ],
681
+ returns: {
682
+ type: "string",
683
+ description: "结果文本"
684
+ },
685
+ namespace: "文本函数"
686
+ },
687
+ {
688
+ name: "BEFORELAST",
689
+ description: "取在某个分隔符之前的所有字符串",
690
+ example: "BEFORELAST(text, '.')",
691
+ params: [
692
+ {
693
+ type: "string",
694
+ name: "text",
695
+ description: "文本"
696
+ },
697
+ {
698
+ type: "string",
699
+ name: "delimiter",
700
+ description: "结束文本"
701
+ }
702
+ ],
703
+ returns: {
704
+ type: "string",
705
+ description: "判断结果"
706
+ },
707
+ namespace: "文本函数"
708
+ },
514
709
  {
515
710
  name: "SPLIT",
516
711
  description: "将文本根据指定片段分割成数组\n\n示例:`SPLIT(\"a,b,c\", \",\")`\n\n返回 `[\"a\", \"b\", \"c\"]`",
@@ -550,6 +745,40 @@ export default [
550
745
  },
551
746
  namespace: "文本函数"
552
747
  },
748
+ {
749
+ name: "STRIPTAG",
750
+ description: "去除文本中的 HTML 标签\n\n示例:`STRIPTAG(\"<b>amis</b>\")`\n\n返回:`amis`",
751
+ example: "STRIPTAG(text)",
752
+ params: [
753
+ {
754
+ type: "string",
755
+ name: "text",
756
+ description: "文本"
757
+ }
758
+ ],
759
+ returns: {
760
+ type: "string",
761
+ description: "处理后的文本"
762
+ },
763
+ namespace: "文本函数"
764
+ },
765
+ {
766
+ name: "LINEBREAK",
767
+ description: "将字符串中的换行转成 HTML `<br>`,用于简单换行的场景\n\n示例:`LINEBREAK(\"\\n\")`\n\n返回:`<br/>`",
768
+ example: "LINEBREAK(text)",
769
+ params: [
770
+ {
771
+ type: "string",
772
+ name: "text",
773
+ description: "文本"
774
+ }
775
+ ],
776
+ returns: {
777
+ type: "string",
778
+ description: "处理后的文本"
779
+ },
780
+ namespace: "文本函数"
781
+ },
553
782
  {
554
783
  name: "STARTSWITH",
555
784
  description: "判断字符串(text)是否以特定字符串(startString)开始,是则返回 True,否则返回 False",
@@ -572,6 +801,28 @@ export default [
572
801
  },
573
802
  namespace: "文本函数"
574
803
  },
804
+ {
805
+ name: "ENDSWITH",
806
+ description: "判断字符串(text)是否以特定字符串(endString)结束,是则返回 True,否则返回 False",
807
+ example: "ENDSWITH(text, '片段')",
808
+ params: [
809
+ {
810
+ type: "string",
811
+ name: "text",
812
+ description: "文本"
813
+ },
814
+ {
815
+ type: "string",
816
+ name: "endString",
817
+ description: "结束文本"
818
+ }
819
+ ],
820
+ returns: {
821
+ type: "string",
822
+ description: "判断结果"
823
+ },
824
+ namespace: "文本函数"
825
+ },
575
826
  {
576
827
  name: "CONTAINS",
577
828
  description: "判断参数 1 中的文本是否包含参数 2 中的文本。",
package/dist/doc.md CHANGED
@@ -195,6 +195,47 @@
195
195
 
196
196
  返回所有参数的平均值
197
197
 
198
+ ### DEVSQ
199
+
200
+ 用法:`DEVSQ(num1, num2, ...numN)`
201
+
202
+ * `num:...number` 要处理的数字
203
+
204
+ 返回:`number` 所有数值的平均值
205
+
206
+ 返回数据点与数据均值点之差(数据偏差)的平方和
207
+
208
+ ### AVEDEV
209
+
210
+ 用法:`AVEDEV(num1, num2, ...numN)`
211
+
212
+ * `num:...number` 要处理的数字
213
+
214
+ 返回:`number` 所有数值的平均值
215
+
216
+ 数据点到其算术平均值的绝对偏差的平均值
217
+
218
+ ### HARMEAN
219
+
220
+ 用法:`HARMEAN(num1, num2, ...numN)`
221
+
222
+ * `num:...number` 要处理的数字
223
+
224
+ 返回:`number` 所有数值的平均值
225
+
226
+ 数据点的调和平均值
227
+
228
+ ### LARGE
229
+
230
+ 用法:`LARGE(array, k)`
231
+
232
+ * `nums:array` 要处理的数字
233
+ * `k:number` 第几大
234
+
235
+ 返回:`number` 所有数值的平均值
236
+
237
+ 数据集中第 k 个最大值
238
+
198
239
  ### UPPERMONEY
199
240
 
200
241
  用法:`UPPERMONEY(num)`
@@ -311,6 +352,86 @@
311
352
 
312
353
  将传入文本转成大写
313
354
 
355
+ ### UPPERFIRST
356
+
357
+ 用法:`UPPERFIRST(text)`
358
+
359
+ * `text:string` 文本
360
+
361
+ 返回:`string` 结果文本
362
+
363
+ 将传入文本首字母转成大写
364
+
365
+ ### PADSTART
366
+
367
+ 用法:`PADSTART(text)`
368
+
369
+ * `text:string` 文本
370
+ * `num:number` 目标长度
371
+ * `pad:string` 用于补齐的文本
372
+
373
+ 返回:`string` 结果文本
374
+
375
+ 向前补齐文本长度
376
+
377
+ 示例 `PADSTART("6", 2, "0")`
378
+
379
+ 返回 `06`
380
+
381
+ ### CAPITALIZE
382
+
383
+ 用法:`CAPITALIZE(text)`
384
+
385
+ * `text:string` 文本
386
+
387
+ 返回:`string` 结果文本
388
+
389
+ 将文本转成标题
390
+
391
+ 示例 `CAPITALIZE("star")`
392
+
393
+ 返回 `Star`
394
+
395
+ ### ESCAPE
396
+
397
+ 用法:`ESCAPE(text)`
398
+
399
+ * `text:string` 文本
400
+
401
+ 返回:`string` 结果文本
402
+
403
+ 对文本进行 HTML 转义
404
+
405
+ 示例 `ESCAPE("star")`
406
+
407
+ 返回 `Star`
408
+
409
+ ### TRUNCATE
410
+
411
+ 用法:`TRUNCATE(text, 6)`
412
+
413
+ * `text:string` 文本
414
+ * `text:number` 最长长度
415
+
416
+ 返回:`string` 结果文本
417
+
418
+ 对文本长度进行截断
419
+
420
+ 示例 `TRUNCATE("amis.baidu.com", 6)`
421
+
422
+ 返回 `amis...`
423
+
424
+ ### BEFORELAST
425
+
426
+ 用法:`BEFORELAST(text, '.')`
427
+
428
+ * `text:string` 文本
429
+ * `delimiter:string` 结束文本
430
+
431
+ 返回:`string` 判断结果
432
+
433
+ 取在某个分隔符之前的所有字符串
434
+
314
435
  ### SPLIT
315
436
 
316
437
  用法:`SPLIT(text, ',')`
@@ -336,6 +457,34 @@
336
457
 
337
458
  将文本去除前后空格
338
459
 
460
+ ### STRIPTAG
461
+
462
+ 用法:`STRIPTAG(text)`
463
+
464
+ * `text:string` 文本
465
+
466
+ 返回:`string` 处理后的文本
467
+
468
+ 去除文本中的 HTML 标签
469
+
470
+ 示例:`STRIPTAG("<b>amis</b>")`
471
+
472
+ 返回:`amis`
473
+
474
+ ### LINEBREAK
475
+
476
+ 用法:`LINEBREAK(text)`
477
+
478
+ * `text:string` 文本
479
+
480
+ 返回:`string` 处理后的文本
481
+
482
+ 将字符串中的换行转成 HTML `<br>`,用于简单换行的场景
483
+
484
+ 示例:`LINEBREAK("\n")`
485
+
486
+ 返回:`<br/>`
487
+
339
488
  ### STARTSWITH
340
489
 
341
490
  用法:`STARTSWITH(text, '片段')`
@@ -347,6 +496,17 @@
347
496
 
348
497
  判断字符串(text)是否以特定字符串(startString)开始,是则返回 True,否则返回 False
349
498
 
499
+ ### ENDSWITH
500
+
501
+ 用法:`ENDSWITH(text, '片段')`
502
+
503
+ * `text:string` 文本
504
+ * `endString:string` 结束文本
505
+
506
+ 返回:`string` 判断结果
507
+
508
+ 判断字符串(text)是否以特定字符串(endString)结束,是则返回 True,否则返回 False
509
+
350
510
  ### CONTAINS
351
511
 
352
512
  用法:`CONTAINS(text, searchText)`
@@ -9,6 +9,10 @@ export interface FunctionMap {
9
9
  }
10
10
  export interface FilterContext {
11
11
  data: Object;
12
+ filter?: {
13
+ name: string;
14
+ args: Array<any>;
15
+ };
12
16
  restFilters: Array<{
13
17
  name: string;
14
18
  args: Array<any>;
@@ -391,6 +395,47 @@ export declare class Evaluator {
391
395
  * @returns {number} 所有数值的平均值
392
396
  */
393
397
  fnAVG(...args: Array<any>): number;
398
+ /**
399
+ * 返回数据点与数据均值点之差(数据偏差)的平方和
400
+ *
401
+ * @example DEVSQ(num1, num2, ...numN)
402
+ * @param {...number} num - 要处理的数字
403
+ * @namespace 数学函数
404
+ *
405
+ * @returns {number} 所有数值的平均值
406
+ */
407
+ fnDEVSQ(...args: Array<any>): number | null;
408
+ /**
409
+ * 数据点到其算术平均值的绝对偏差的平均值
410
+ *
411
+ * @example AVEDEV(num1, num2, ...numN)
412
+ * @param {...number} num - 要处理的数字
413
+ * @namespace 数学函数
414
+ *
415
+ * @returns {number} 所有数值的平均值
416
+ */
417
+ fnAVEDEV(...args: Array<any>): number | null;
418
+ /**
419
+ * 数据点的调和平均值
420
+ *
421
+ * @example HARMEAN(num1, num2, ...numN)
422
+ * @param {...number} num - 要处理的数字
423
+ * @namespace 数学函数
424
+ *
425
+ * @returns {number} 所有数值的平均值
426
+ */
427
+ fnHARMEAN(...args: Array<any>): number | null;
428
+ /**
429
+ * 数据集中第 k 个最大值
430
+ *
431
+ * @example LARGE(array, k)
432
+ * @param {array} nums - 要处理的数字
433
+ * @param {number} k - 第几大
434
+ * @namespace 数学函数
435
+ *
436
+ * @returns {number} 所有数值的平均值
437
+ */
438
+ fnLARGE(nums: Array<any>, k: number): any;
394
439
  /**
395
440
  * 将数值转为中文大写金额
396
441
  *
@@ -509,6 +554,86 @@ export declare class Evaluator {
509
554
  * @returns {string} 结果文本
510
555
  */
511
556
  fnUPPER(text: string): string;
557
+ /**
558
+ * 将传入文本首字母转成大写
559
+ *
560
+ * @example UPPERFIRST(text)
561
+ * @param {string} text - 文本
562
+ * @namespace 文本函数
563
+ *
564
+ * @returns {string} 结果文本
565
+ */
566
+ fnUPPERFIRST(text: string): string;
567
+ /**
568
+ * 向前补齐文本长度
569
+ *
570
+ * 示例 `PADSTART("6", 2, "0")`
571
+ *
572
+ * 返回 `06`
573
+ *
574
+ * @example PADSTART(text)
575
+ * @param {string} text - 文本
576
+ * @param {number} num - 目标长度
577
+ * @param {string} pad - 用于补齐的文本
578
+ * @namespace 文本函数
579
+ *
580
+ * @returns {string} 结果文本
581
+ */
582
+ fnPADSTART(text: string, num: number, pad: string): string;
583
+ /**
584
+ * 将文本转成标题
585
+ *
586
+ * 示例 `CAPITALIZE("star")`
587
+ *
588
+ * 返回 `Star`
589
+ *
590
+ * @example CAPITALIZE(text)
591
+ * @param {string} text - 文本
592
+ * @namespace 文本函数
593
+ *
594
+ * @returns {string} 结果文本
595
+ */
596
+ fnCAPITALIZE(text: string): string;
597
+ /**
598
+ * 对文本进行 HTML 转义
599
+ *
600
+ * 示例 `ESCAPE("star")`
601
+ *
602
+ * 返回 `Star`
603
+ *
604
+ * @example ESCAPE(text)
605
+ * @param {string} text - 文本
606
+ * @namespace 文本函数
607
+ *
608
+ * @returns {string} 结果文本
609
+ */
610
+ fnESCAPE(text: string): string;
611
+ /**
612
+ * 对文本长度进行截断
613
+ *
614
+ * 示例 `TRUNCATE("amis.baidu.com", 6)`
615
+ *
616
+ * 返回 `amis...`
617
+ *
618
+ * @example TRUNCATE(text, 6)
619
+ * @param {string} text - 文本
620
+ * @param {number} text - 最长长度
621
+ * @namespace 文本函数
622
+ *
623
+ * @returns {string} 结果文本
624
+ */
625
+ fnTRUNCATE(text: string, length: number): string;
626
+ /**
627
+ * 取在某个分隔符之前的所有字符串
628
+ *
629
+ * @example BEFORELAST(text, '.')
630
+ * @param {string} text - 文本
631
+ * @param {string} delimiter - 结束文本
632
+ * @namespace 文本函数
633
+ *
634
+ * @returns {string} 判断结果
635
+ */
636
+ fnBEFORELAST(text: string, delimiter?: string): string;
512
637
  /**
513
638
  * 将文本根据指定片段分割成数组
514
639
  *
@@ -534,6 +659,34 @@ export declare class Evaluator {
534
659
  * @returns {string} 处理后的文本
535
660
  */
536
661
  fnTRIM(text: string): string;
662
+ /**
663
+ * 去除文本中的 HTML 标签
664
+ *
665
+ * 示例:`STRIPTAG("<b>amis</b>")`
666
+ *
667
+ * 返回:`amis`
668
+ *
669
+ * @example STRIPTAG(text)
670
+ * @param {string} text - 文本
671
+ * @namespace 文本函数
672
+ *
673
+ * @returns {string} 处理后的文本
674
+ */
675
+ fnSTRIPTAG(text: string): string;
676
+ /**
677
+ * 将字符串中的换行转成 HTML `<br>`,用于简单换行的场景
678
+ *
679
+ * 示例:`LINEBREAK("\n")`
680
+ *
681
+ * 返回:`<br/>`
682
+ *
683
+ * @example LINEBREAK(text)
684
+ * @param {string} text - 文本
685
+ * @namespace 文本函数
686
+ *
687
+ * @returns {string} 处理后的文本
688
+ */
689
+ fnLINEBREAK(text: string): string;
537
690
  /**
538
691
  * 判断字符串(text)是否以特定字符串(startString)开始,是则返回 True,否则返回 False
539
692
  *
@@ -545,6 +698,17 @@ export declare class Evaluator {
545
698
  * @returns {string} 判断结果
546
699
  */
547
700
  fnSTARTSWITH(text: string, search: string): boolean;
701
+ /**
702
+ * 判断字符串(text)是否以特定字符串(endString)结束,是则返回 True,否则返回 False
703
+ *
704
+ * @example ENDSWITH(text, '片段')
705
+ * @param {string} text - 文本
706
+ * @param {string} endString - 结束文本
707
+ * @namespace 文本函数
708
+ *
709
+ * @returns {string} 判断结果
710
+ */
711
+ fnENDSWITH(text: string, search: string): boolean;
548
712
  /**
549
713
  * 判断参数 1 中的文本是否包含参数 2 中的文本。
550
714
  *