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.
- package/dist/doc.js +1163 -0
- package/dist/doc.md +658 -0
- package/dist/evalutor.d.ts +576 -1
- package/dist/index.js +589 -13
- package/package.json +7 -3
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-formula v1.2.
|
|
2
|
+
* amis-formula v1.2.7
|
|
3
3
|
* Copyright 2021 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -367,10 +367,39 @@ var Evaluator = /** @class */ (function () {
|
|
|
367
367
|
}
|
|
368
368
|
return fn.apply(this, args);
|
|
369
369
|
};
|
|
370
|
-
|
|
370
|
+
/**
|
|
371
|
+
* 示例:IF(A, B, C)
|
|
372
|
+
*
|
|
373
|
+
* 如果满足条件A,则返回B,否则返回C,支持多层嵌套IF函数。
|
|
374
|
+
*
|
|
375
|
+
* 也可以用表达式如:A ? B : C
|
|
376
|
+
*
|
|
377
|
+
* @example IF(condition, consequent, alternate)
|
|
378
|
+
* @param {expression} condition - 条件表达式.
|
|
379
|
+
* @param {any} consequent 条件判断通过的返回结果
|
|
380
|
+
* @param {any} alternate 条件判断不通过的返回结果
|
|
381
|
+
* @namespace 逻辑函数
|
|
382
|
+
*
|
|
383
|
+
* @returns {any} 根据条件返回不同的结果
|
|
384
|
+
*/
|
|
371
385
|
Evaluator.prototype.fnIF = function (condition, trueValue, falseValue) {
|
|
372
386
|
return condition() ? trueValue() : falseValue();
|
|
373
387
|
};
|
|
388
|
+
/**
|
|
389
|
+
* 条件全部符合,返回 true,否则返回 false
|
|
390
|
+
*
|
|
391
|
+
* 示例:AND(语文成绩>80, 数学成绩>80)
|
|
392
|
+
*
|
|
393
|
+
* 语文成绩和数学成绩都大于 80,则返回 true,否则返回 false
|
|
394
|
+
*
|
|
395
|
+
* 也可以直接用表达式如:语文成绩>80 && 数学成绩>80
|
|
396
|
+
*
|
|
397
|
+
* @example AND(expression1, expression2, ...expressionN)
|
|
398
|
+
* @param {...expression} conditions - 条件表达式.
|
|
399
|
+
* @namespace 逻辑函数
|
|
400
|
+
*
|
|
401
|
+
* @returns {boolean}
|
|
402
|
+
*/
|
|
374
403
|
Evaluator.prototype.fnAND = function () {
|
|
375
404
|
var condtions = [];
|
|
376
405
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -378,6 +407,21 @@ var Evaluator = /** @class */ (function () {
|
|
|
378
407
|
}
|
|
379
408
|
return condtions.every(function (c) { return c(); });
|
|
380
409
|
};
|
|
410
|
+
/**
|
|
411
|
+
* 条件任意一个满足条件,返回 true,否则返回 false
|
|
412
|
+
*
|
|
413
|
+
* 示例:OR(语文成绩>80, 数学成绩>80)
|
|
414
|
+
*
|
|
415
|
+
* 语文成绩和数学成绩任意一个大于 80,则返回 true,否则返回 false
|
|
416
|
+
*
|
|
417
|
+
* 也可以直接用表达式如:语文成绩>80 || 数学成绩>80
|
|
418
|
+
*
|
|
419
|
+
* @example OR(expression1, expression2, ...expressionN)
|
|
420
|
+
* @param {...expression} conditions - 条件表达式.
|
|
421
|
+
* @namespace 逻辑函数
|
|
422
|
+
*
|
|
423
|
+
* @returns {boolean}
|
|
424
|
+
*/
|
|
381
425
|
Evaluator.prototype.fnOR = function () {
|
|
382
426
|
var condtions = [];
|
|
383
427
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -385,9 +429,31 @@ var Evaluator = /** @class */ (function () {
|
|
|
385
429
|
}
|
|
386
430
|
return condtions.some(function (c) { return c(); });
|
|
387
431
|
};
|
|
432
|
+
/**
|
|
433
|
+
* 异或处理,两个表达式同时为「真」,或者同时为「假」,则结果返回为「真」
|
|
434
|
+
*
|
|
435
|
+
* @example XOR(condition1, condition2)
|
|
436
|
+
* @param {expression} condition1 - 条件表达式1
|
|
437
|
+
* @param {expression} condition2 - 条件表达式2
|
|
438
|
+
* @namespace 逻辑函数
|
|
439
|
+
*
|
|
440
|
+
* @returns {boolean}
|
|
441
|
+
*/
|
|
388
442
|
Evaluator.prototype.fnXOR = function (c1, c2) {
|
|
389
443
|
return !!c1() === !!c2();
|
|
390
444
|
};
|
|
445
|
+
/**
|
|
446
|
+
* 判断函数集合,相当于多个 else if 合并成一个。
|
|
447
|
+
*
|
|
448
|
+
* 示例:IFS(语文成绩 > 80, "优秀", 语文成绩 > 60, "良", "继续努力")
|
|
449
|
+
*
|
|
450
|
+
* 如果语文成绩大于 80,则返回优秀,否则判断大于 60 分,则返回良,否则返回继续努力。
|
|
451
|
+
*
|
|
452
|
+
* @example IFS(condition1, result1, condition2, result2,...conditionN, resultN)
|
|
453
|
+
* @param {...any} args - 条件,返回值集合
|
|
454
|
+
* @namespace 逻辑函数
|
|
455
|
+
* @returns {any} 第一个满足条件的结果,没有命中的返回 false。
|
|
456
|
+
*/
|
|
391
457
|
Evaluator.prototype.fnIFS = function () {
|
|
392
458
|
var args = [];
|
|
393
459
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -405,11 +471,28 @@ var Evaluator = /** @class */ (function () {
|
|
|
405
471
|
}
|
|
406
472
|
return;
|
|
407
473
|
};
|
|
408
|
-
|
|
474
|
+
/**
|
|
475
|
+
* 返回传入数字的绝对值
|
|
476
|
+
*
|
|
477
|
+
* @example ABS(num)
|
|
478
|
+
* @param {number} num - 数值
|
|
479
|
+
* @namespace 数学函数
|
|
480
|
+
*
|
|
481
|
+
* @returns {number} 传入数值的绝对值
|
|
482
|
+
*/
|
|
409
483
|
Evaluator.prototype.fnABS = function (a) {
|
|
410
484
|
a = this.formatNumber(a);
|
|
411
485
|
return Math.abs(a);
|
|
412
486
|
};
|
|
487
|
+
/**
|
|
488
|
+
* 获取最大值
|
|
489
|
+
*
|
|
490
|
+
* @example MAX(num1, num2, ...numN)
|
|
491
|
+
* @param {...number} num - 数值
|
|
492
|
+
* @namespace 数学函数
|
|
493
|
+
*
|
|
494
|
+
* @returns {number} 所有传入值中最大的那个
|
|
495
|
+
*/
|
|
413
496
|
Evaluator.prototype.fnMAX = function () {
|
|
414
497
|
var _this = this;
|
|
415
498
|
var args = [];
|
|
@@ -418,6 +501,15 @@ var Evaluator = /** @class */ (function () {
|
|
|
418
501
|
}
|
|
419
502
|
return Math.max.apply(Math, args.map(function (item) { return _this.formatNumber(item); }));
|
|
420
503
|
};
|
|
504
|
+
/**
|
|
505
|
+
* 获取最小值
|
|
506
|
+
*
|
|
507
|
+
* @example MIN(num1, num2, ...numN)
|
|
508
|
+
* @param {...number} num - 数值
|
|
509
|
+
* @namespace 数学函数
|
|
510
|
+
*
|
|
511
|
+
* @returns {number} 所有传入值中最小的那个
|
|
512
|
+
*/
|
|
421
513
|
Evaluator.prototype.fnMIN = function () {
|
|
422
514
|
var _this = this;
|
|
423
515
|
var args = [];
|
|
@@ -426,6 +518,15 @@ var Evaluator = /** @class */ (function () {
|
|
|
426
518
|
}
|
|
427
519
|
return Math.min.apply(Math, args.map(function (item) { return _this.formatNumber(item); }));
|
|
428
520
|
};
|
|
521
|
+
/**
|
|
522
|
+
* 求和
|
|
523
|
+
*
|
|
524
|
+
* @example SUM(num1, num2, ...numN)
|
|
525
|
+
* @param {...number} num - 数值
|
|
526
|
+
* @namespace 数学函数
|
|
527
|
+
*
|
|
528
|
+
* @returns {number} 所有传入数值的总和
|
|
529
|
+
*/
|
|
429
530
|
Evaluator.prototype.fnSUM = function () {
|
|
430
531
|
var _this = this;
|
|
431
532
|
var args = [];
|
|
@@ -434,15 +535,52 @@ var Evaluator = /** @class */ (function () {
|
|
|
434
535
|
}
|
|
435
536
|
return args.reduce(function (sum, a) { return sum + _this.formatNumber(a) || 0; }, 0);
|
|
436
537
|
};
|
|
538
|
+
/**
|
|
539
|
+
* 将数值向下取整为最接近的整数
|
|
540
|
+
*
|
|
541
|
+
* @example INT(num)
|
|
542
|
+
* @param {number} num - 数值
|
|
543
|
+
* @namespace 数学函数
|
|
544
|
+
*
|
|
545
|
+
* @returns {number} 数值对应的整形
|
|
546
|
+
*/
|
|
437
547
|
Evaluator.prototype.fnINT = function (n) {
|
|
438
548
|
return Math.floor(this.formatNumber(n));
|
|
439
549
|
};
|
|
550
|
+
/**
|
|
551
|
+
* 返回两数相除的余数,参数 number 是被除数,divisor 是除数
|
|
552
|
+
*
|
|
553
|
+
* @example MOD(num, divisor)
|
|
554
|
+
* @param {number} num - 被除数
|
|
555
|
+
* @param {number} divisor - 除数
|
|
556
|
+
* @namespace 数学函数
|
|
557
|
+
*
|
|
558
|
+
* @returns {number} 两数相除的余数
|
|
559
|
+
*/
|
|
440
560
|
Evaluator.prototype.fnMOD = function (a, b) {
|
|
441
561
|
return this.formatNumber(a) % this.formatNumber(b);
|
|
442
562
|
};
|
|
563
|
+
/**
|
|
564
|
+
* 圆周率 3.1415...
|
|
565
|
+
*
|
|
566
|
+
* @example PI()
|
|
567
|
+
* @namespace 数学函数
|
|
568
|
+
*
|
|
569
|
+
* @returns {number} 圆周率数值
|
|
570
|
+
*/
|
|
443
571
|
Evaluator.prototype.fnPI = function () {
|
|
444
572
|
return Math.PI;
|
|
445
573
|
};
|
|
574
|
+
/**
|
|
575
|
+
* 将数字四舍五入到指定的位数,可以设置小数位。
|
|
576
|
+
*
|
|
577
|
+
* @example ROUND(num[, numDigits = 2])
|
|
578
|
+
* @param {number} num - 要处理的数字
|
|
579
|
+
* @param {number} numDigits - 小数位数
|
|
580
|
+
* @namespace 数学函数
|
|
581
|
+
*
|
|
582
|
+
* @returns {number} 传入数值四舍五入后的结果
|
|
583
|
+
*/
|
|
446
584
|
Evaluator.prototype.fnROUND = function (a, b) {
|
|
447
585
|
a = this.formatNumber(a);
|
|
448
586
|
b = this.formatNumber(b);
|
|
@@ -453,6 +591,16 @@ var Evaluator = /** @class */ (function () {
|
|
|
453
591
|
}
|
|
454
592
|
return Math.round(a);
|
|
455
593
|
};
|
|
594
|
+
/**
|
|
595
|
+
* 将数字向下取整到指定的位数,可以设置小数位。
|
|
596
|
+
*
|
|
597
|
+
* @example FLOOR(num[, numDigits=2])
|
|
598
|
+
* @param {number} num - 要处理的数字
|
|
599
|
+
* @param {number} numDigits - 小数位数
|
|
600
|
+
* @namespace 数学函数
|
|
601
|
+
*
|
|
602
|
+
* @returns {number} 传入数值向下取整后的结果
|
|
603
|
+
*/
|
|
456
604
|
Evaluator.prototype.fnFLOOR = function (a, b) {
|
|
457
605
|
a = this.formatNumber(a);
|
|
458
606
|
b = this.formatNumber(b);
|
|
@@ -463,6 +611,16 @@ var Evaluator = /** @class */ (function () {
|
|
|
463
611
|
}
|
|
464
612
|
return Math.floor(a);
|
|
465
613
|
};
|
|
614
|
+
/**
|
|
615
|
+
* 将数字向上取整到指定的位数,可以设置小数位。
|
|
616
|
+
*
|
|
617
|
+
* @example CEIL(num[, numDigits=2])
|
|
618
|
+
* @param {number} num - 要处理的数字
|
|
619
|
+
* @param {number} numDigits - 小数位数
|
|
620
|
+
* @namespace 数学函数
|
|
621
|
+
*
|
|
622
|
+
* @returns {number} 传入数值向上取整后的结果
|
|
623
|
+
*/
|
|
466
624
|
Evaluator.prototype.fnCEIL = function (a, b) {
|
|
467
625
|
a = this.formatNumber(a);
|
|
468
626
|
b = this.formatNumber(b);
|
|
@@ -473,9 +631,27 @@ var Evaluator = /** @class */ (function () {
|
|
|
473
631
|
}
|
|
474
632
|
return Math.ceil(a);
|
|
475
633
|
};
|
|
634
|
+
/**
|
|
635
|
+
* 开平方,参数 number 为非负数
|
|
636
|
+
*
|
|
637
|
+
* @example SQRT(num)
|
|
638
|
+
* @param {number} num - 要处理的数字
|
|
639
|
+
* @namespace 数学函数
|
|
640
|
+
*
|
|
641
|
+
* @returns {number} 开平方的结果
|
|
642
|
+
*/
|
|
476
643
|
Evaluator.prototype.fnSQRT = function (n) {
|
|
477
644
|
return Math.sqrt(this.formatNumber(n));
|
|
478
645
|
};
|
|
646
|
+
/**
|
|
647
|
+
* 返回所有参数的平均值
|
|
648
|
+
*
|
|
649
|
+
* @example AVG(num1, num2, ...numN)
|
|
650
|
+
* @param {...number} num - 要处理的数字
|
|
651
|
+
* @namespace 数学函数
|
|
652
|
+
*
|
|
653
|
+
* @returns {number} 所有数值的平均值
|
|
654
|
+
*/
|
|
479
655
|
Evaluator.prototype.fnAVG = function () {
|
|
480
656
|
var _this = this;
|
|
481
657
|
var args = [];
|
|
@@ -484,6 +660,15 @@ var Evaluator = /** @class */ (function () {
|
|
|
484
660
|
}
|
|
485
661
|
return (this.fnSUM.apply(this, args.map(function (item) { return _this.formatNumber(item); })) / args.length);
|
|
486
662
|
};
|
|
663
|
+
/**
|
|
664
|
+
* 将数值转为中文大写金额
|
|
665
|
+
*
|
|
666
|
+
* @example UPPERMONEY(num)
|
|
667
|
+
* @param {number} num - 要处理的数字
|
|
668
|
+
* @namespace 数学函数
|
|
669
|
+
*
|
|
670
|
+
* @returns {string} 数值中文大写字符
|
|
671
|
+
*/
|
|
487
672
|
Evaluator.prototype.fnUPPERMONEY = function (n) {
|
|
488
673
|
n = this.formatNumber(n);
|
|
489
674
|
var fraction = ['角', '分'];
|
|
@@ -514,6 +699,18 @@ var Evaluator = /** @class */ (function () {
|
|
|
514
699
|
.replace(/(零.)+/g, '零')
|
|
515
700
|
.replace(/^整$/, '零元整'));
|
|
516
701
|
};
|
|
702
|
+
/**
|
|
703
|
+
* 返回大于等于 0 且小于 1 的均匀分布随机实数。每一次触发计算都会变化。
|
|
704
|
+
*
|
|
705
|
+
* 示例:`RAND()*100`
|
|
706
|
+
*
|
|
707
|
+
* 返回 0-100 之间的随机数
|
|
708
|
+
*
|
|
709
|
+
* @example RAND()
|
|
710
|
+
* @namespace 数学函数
|
|
711
|
+
*
|
|
712
|
+
* @returns {number} 随机数
|
|
713
|
+
*/
|
|
517
714
|
Evaluator.prototype.fnRAND = function () {
|
|
518
715
|
return Math.random();
|
|
519
716
|
};
|
|
@@ -524,18 +721,56 @@ var Evaluator = /** @class */ (function () {
|
|
|
524
721
|
}
|
|
525
722
|
return "".concat(raw);
|
|
526
723
|
};
|
|
724
|
+
/**
|
|
725
|
+
* 返回传入文本左侧的指定长度字符串。
|
|
726
|
+
*
|
|
727
|
+
* @example LEFT(text, len)
|
|
728
|
+
* @param {string} text - 要处理的文本
|
|
729
|
+
* @param {number} len - 要处理的长度
|
|
730
|
+
* @namespace 文本函数
|
|
731
|
+
*
|
|
732
|
+
* @returns {string} 对应字符串
|
|
733
|
+
*/
|
|
527
734
|
Evaluator.prototype.fnLEFT = function (text, len) {
|
|
528
735
|
text = this.normalizeText(text);
|
|
529
736
|
return text.substring(0, len);
|
|
530
737
|
};
|
|
738
|
+
/**
|
|
739
|
+
* 返回传入文本右侧的指定长度字符串。
|
|
740
|
+
*
|
|
741
|
+
* @example RIGHT(text, len)
|
|
742
|
+
* @param {string} text - 要处理的文本
|
|
743
|
+
* @param {number} len - 要处理的长度
|
|
744
|
+
* @namespace 文本函数
|
|
745
|
+
*
|
|
746
|
+
* @returns {string} 对应字符串
|
|
747
|
+
*/
|
|
531
748
|
Evaluator.prototype.fnRIGHT = function (text, len) {
|
|
532
749
|
text = this.normalizeText(text);
|
|
533
750
|
return text.substring(text.length - len, text.length);
|
|
534
751
|
};
|
|
752
|
+
/**
|
|
753
|
+
* 计算文本的长度
|
|
754
|
+
*
|
|
755
|
+
* @example LEN(text)
|
|
756
|
+
* @param {string} text - 要处理的文本
|
|
757
|
+
* @namespace 文本函数
|
|
758
|
+
*
|
|
759
|
+
* @returns {number} 长度
|
|
760
|
+
*/
|
|
535
761
|
Evaluator.prototype.fnLEN = function (text) {
|
|
536
762
|
text = this.normalizeText(text);
|
|
537
763
|
return text === null || text === void 0 ? void 0 : text.length;
|
|
538
764
|
};
|
|
765
|
+
/**
|
|
766
|
+
* 计算文本集合中所有文本的长度
|
|
767
|
+
*
|
|
768
|
+
* @example LENGTH(textArr)
|
|
769
|
+
* @param {string[]} textArr - 要处理的文本集合
|
|
770
|
+
* @namespace 文本函数
|
|
771
|
+
*
|
|
772
|
+
* @returns {number[]} 长度集合
|
|
773
|
+
*/
|
|
539
774
|
Evaluator.prototype.fnLENGTH = function () {
|
|
540
775
|
var args = [];
|
|
541
776
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -543,9 +778,27 @@ var Evaluator = /** @class */ (function () {
|
|
|
543
778
|
}
|
|
544
779
|
return this.fnLEN.call(this, args);
|
|
545
780
|
};
|
|
781
|
+
/**
|
|
782
|
+
* 判断文本是否为空
|
|
783
|
+
*
|
|
784
|
+
* @example ISEMPTY(text)
|
|
785
|
+
* @param {string} text - 要处理的文本
|
|
786
|
+
* @namespace 文本函数
|
|
787
|
+
*
|
|
788
|
+
* @returns {boolean} 判断结果
|
|
789
|
+
*/
|
|
546
790
|
Evaluator.prototype.fnISEMPTY = function (text) {
|
|
547
791
|
return !text || !String(text).trim();
|
|
548
792
|
};
|
|
793
|
+
/**
|
|
794
|
+
* 将多个传入值连接成文本
|
|
795
|
+
*
|
|
796
|
+
* @example CONCATENATE(text1, text2, ...textN)
|
|
797
|
+
* @param {...string} text - 文本集合
|
|
798
|
+
* @namespace 文本函数
|
|
799
|
+
*
|
|
800
|
+
* @returns {string} 连接后的文本
|
|
801
|
+
*/
|
|
549
802
|
Evaluator.prototype.fnCONCATENATE = function () {
|
|
550
803
|
var args = [];
|
|
551
804
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -553,26 +806,88 @@ var Evaluator = /** @class */ (function () {
|
|
|
553
806
|
}
|
|
554
807
|
return args.join('');
|
|
555
808
|
};
|
|
809
|
+
/**
|
|
810
|
+
* 返回计算机字符集的数字代码所对应的字符。
|
|
811
|
+
*
|
|
812
|
+
* `CHAR(97)` 等价于 "a"
|
|
813
|
+
*
|
|
814
|
+
* @example CHAR(code)
|
|
815
|
+
* @param {number} code - 编码值
|
|
816
|
+
* @namespace 文本函数
|
|
817
|
+
*
|
|
818
|
+
* @returns {string} 指定位置的字符
|
|
819
|
+
*/
|
|
556
820
|
Evaluator.prototype.fnCHAR = function (code) {
|
|
557
821
|
return String.fromCharCode(code);
|
|
558
822
|
};
|
|
823
|
+
/**
|
|
824
|
+
* 将传入文本转成小写
|
|
825
|
+
*
|
|
826
|
+
* @example LOWER(text)
|
|
827
|
+
* @param {string} text - 文本
|
|
828
|
+
* @namespace 文本函数
|
|
829
|
+
*
|
|
830
|
+
* @returns {string} 结果文本
|
|
831
|
+
*/
|
|
559
832
|
Evaluator.prototype.fnLOWER = function (text) {
|
|
560
833
|
text = this.normalizeText(text);
|
|
561
834
|
return text.toLowerCase();
|
|
562
835
|
};
|
|
836
|
+
/**
|
|
837
|
+
* 将传入文本转成大写
|
|
838
|
+
*
|
|
839
|
+
* @example UPPER(text)
|
|
840
|
+
* @param {string} text - 文本
|
|
841
|
+
* @namespace 文本函数
|
|
842
|
+
*
|
|
843
|
+
* @returns {string} 结果文本
|
|
844
|
+
*/
|
|
563
845
|
Evaluator.prototype.fnUPPER = function (text) {
|
|
564
846
|
text = this.normalizeText(text);
|
|
565
847
|
return text.toUpperCase();
|
|
566
848
|
};
|
|
849
|
+
/**
|
|
850
|
+
* 将文本根据指定片段分割成数组
|
|
851
|
+
*
|
|
852
|
+
* 示例:`SPLIT("a,b,c", ",")`
|
|
853
|
+
*
|
|
854
|
+
* 返回 `["a", "b", "c"]`
|
|
855
|
+
*
|
|
856
|
+
* @example SPLIT(text, ',')
|
|
857
|
+
* @param {string} text - 文本
|
|
858
|
+
* @param {string} delimiter - 文本片段
|
|
859
|
+
* @namespace 文本函数
|
|
860
|
+
*
|
|
861
|
+
* @returns {Array<string>} 文本集
|
|
862
|
+
*/
|
|
567
863
|
Evaluator.prototype.fnSPLIT = function (text, sep) {
|
|
568
864
|
if (sep === void 0) { sep = ','; }
|
|
569
865
|
text = this.normalizeText(text);
|
|
570
866
|
return text.split(sep);
|
|
571
867
|
};
|
|
868
|
+
/**
|
|
869
|
+
* 将文本去除前后空格
|
|
870
|
+
*
|
|
871
|
+
* @example TRIM(text)
|
|
872
|
+
* @param {string} text - 文本
|
|
873
|
+
* @namespace 文本函数
|
|
874
|
+
*
|
|
875
|
+
* @returns {string} 处理后的文本
|
|
876
|
+
*/
|
|
572
877
|
Evaluator.prototype.fnTRIM = function (text) {
|
|
573
878
|
text = this.normalizeText(text);
|
|
574
879
|
return text.trim();
|
|
575
880
|
};
|
|
881
|
+
/**
|
|
882
|
+
* 判断字符串(text)是否以特定字符串(startString)开始,是则返回 True,否则返回 False
|
|
883
|
+
*
|
|
884
|
+
* @example STARTSWITH(text, '片段')
|
|
885
|
+
* @param {string} text - 文本
|
|
886
|
+
* @param {string} startString - 起始文本
|
|
887
|
+
* @namespace 文本函数
|
|
888
|
+
*
|
|
889
|
+
* @returns {string} 判断结果
|
|
890
|
+
*/
|
|
576
891
|
Evaluator.prototype.fnSTARTSWITH = function (text, search) {
|
|
577
892
|
if (!search) {
|
|
578
893
|
return false;
|
|
@@ -580,6 +895,16 @@ var Evaluator = /** @class */ (function () {
|
|
|
580
895
|
text = this.normalizeText(text);
|
|
581
896
|
return text.indexOf(search) === 0;
|
|
582
897
|
};
|
|
898
|
+
/**
|
|
899
|
+
* 判断参数 1 中的文本是否包含参数 2 中的文本。
|
|
900
|
+
*
|
|
901
|
+
* @example CONTAINS(text, searchText)
|
|
902
|
+
* @param {string} text - 文本
|
|
903
|
+
* @param {string} searchText - 搜索文本
|
|
904
|
+
* @namespace 文本函数
|
|
905
|
+
*
|
|
906
|
+
* @returns {string} 判断结果
|
|
907
|
+
*/
|
|
583
908
|
Evaluator.prototype.fnCONTAINS = function (text, search) {
|
|
584
909
|
if (!search) {
|
|
585
910
|
return false;
|
|
@@ -587,6 +912,17 @@ var Evaluator = /** @class */ (function () {
|
|
|
587
912
|
text = this.normalizeText(text);
|
|
588
913
|
return !!~text.indexOf(search);
|
|
589
914
|
};
|
|
915
|
+
/**
|
|
916
|
+
* 对文本进行全量替换。
|
|
917
|
+
*
|
|
918
|
+
* @example REPLACE(text, search, replace)
|
|
919
|
+
* @param {string} text - 要处理的文本
|
|
920
|
+
* @param {string} search - 要被替换的文本
|
|
921
|
+
* @param {string} replace - 要替换的文本
|
|
922
|
+
* @namespace 文本函数
|
|
923
|
+
*
|
|
924
|
+
* @returns {string} 处理结果
|
|
925
|
+
*/
|
|
590
926
|
Evaluator.prototype.fnREPLACE = function (text, search, replace) {
|
|
591
927
|
text = this.normalizeText(text);
|
|
592
928
|
var result = text;
|
|
@@ -602,6 +938,17 @@ var Evaluator = /** @class */ (function () {
|
|
|
602
938
|
}
|
|
603
939
|
return result;
|
|
604
940
|
};
|
|
941
|
+
/**
|
|
942
|
+
* 对文本进行搜索,返回命中的位置
|
|
943
|
+
*
|
|
944
|
+
* @example SEARCH(text, search, 0)
|
|
945
|
+
* @param {string} text - 要处理的文本
|
|
946
|
+
* @param {string} search - 用来搜索的文本
|
|
947
|
+
* @param {number} start - 起始位置
|
|
948
|
+
* @namespace 文本函数
|
|
949
|
+
*
|
|
950
|
+
* @returns {number} 命中的位置
|
|
951
|
+
*/
|
|
605
952
|
Evaluator.prototype.fnSEARCH = function (text, search, start) {
|
|
606
953
|
if (start === void 0) { start = 0; }
|
|
607
954
|
text = this.normalizeText(text);
|
|
@@ -612,35 +959,111 @@ var Evaluator = /** @class */ (function () {
|
|
|
612
959
|
}
|
|
613
960
|
return -1;
|
|
614
961
|
};
|
|
962
|
+
/**
|
|
963
|
+
* 返回文本字符串中从指定位置开始的特定数目的字符
|
|
964
|
+
*
|
|
965
|
+
* @example MID(text, from, len)
|
|
966
|
+
* @param {string} text - 要处理的文本
|
|
967
|
+
* @param {number} from - 起始位置
|
|
968
|
+
* @param {number} len - 处理长度
|
|
969
|
+
* @namespace 文本函数
|
|
970
|
+
*
|
|
971
|
+
* @returns {number} 命中的位置
|
|
972
|
+
*/
|
|
615
973
|
Evaluator.prototype.fnMID = function (text, from, len) {
|
|
616
974
|
text = this.normalizeText(text);
|
|
617
975
|
return text.substring(from, from + len);
|
|
618
976
|
};
|
|
619
977
|
// 日期函数
|
|
978
|
+
/**
|
|
979
|
+
* 创建日期对象,可以通过特定格式的字符串,或者数值。
|
|
980
|
+
*
|
|
981
|
+
* 需要注意的是,其中月份的数值是从0开始的,也就是说,
|
|
982
|
+
* 如果是12月份,你应该传入数值11。
|
|
983
|
+
*
|
|
984
|
+
* @example DATE(2021, 11, 6, 8, 20, 0)
|
|
985
|
+
* @example DATE('2021-12-06 08:20:00')
|
|
986
|
+
* @namespace 日期函数
|
|
987
|
+
*
|
|
988
|
+
* @returns {Date} 日期对象
|
|
989
|
+
*/
|
|
620
990
|
Evaluator.prototype.fnDATE = function (year, month, day, hour, minute, second) {
|
|
621
991
|
if (month === undefined) {
|
|
622
992
|
return new Date(year);
|
|
623
993
|
}
|
|
624
994
|
return new Date(year, month, day, hour, minute, second);
|
|
625
995
|
};
|
|
996
|
+
/**
|
|
997
|
+
* 返回时间的时间戳
|
|
998
|
+
*
|
|
999
|
+
* @example TIMESTAMP(date[, format = "X"])
|
|
1000
|
+
* @namespace 日期函数
|
|
1001
|
+
* @param {date} date 日期对象
|
|
1002
|
+
* @param {string} format 时间戳格式,带毫秒传入 'x'。默认为 'X' 不带毫秒的。
|
|
1003
|
+
*
|
|
1004
|
+
* @returns {number} 时间戳
|
|
1005
|
+
*/
|
|
626
1006
|
Evaluator.prototype.fnTIMESTAMP = function (date, format) {
|
|
627
1007
|
return parseInt(moment__default["default"](date).format(format === 'x' ? 'x' : 'X'), 10);
|
|
628
1008
|
};
|
|
1009
|
+
/**
|
|
1010
|
+
* 返回今天的日期
|
|
1011
|
+
*
|
|
1012
|
+
* @example TODAY()
|
|
1013
|
+
* @namespace 日期函数
|
|
1014
|
+
*
|
|
1015
|
+
* @returns {number} 日期
|
|
1016
|
+
*/
|
|
629
1017
|
Evaluator.prototype.fnTODAY = function () {
|
|
630
1018
|
return new Date();
|
|
631
1019
|
};
|
|
1020
|
+
/**
|
|
1021
|
+
* 返回现在的日期
|
|
1022
|
+
*
|
|
1023
|
+
* @example NOW()
|
|
1024
|
+
* @namespace 日期函数
|
|
1025
|
+
*
|
|
1026
|
+
* @returns {number} 日期
|
|
1027
|
+
*/
|
|
632
1028
|
Evaluator.prototype.fnNOW = function () {
|
|
633
1029
|
return new Date();
|
|
634
1030
|
};
|
|
1031
|
+
/**
|
|
1032
|
+
* 将日期转成日期字符串
|
|
1033
|
+
*
|
|
1034
|
+
* @example DATETOSTR(date[, format="YYYY-MM-DD HH:mm:ss"])
|
|
1035
|
+
* @namespace 日期函数
|
|
1036
|
+
* @param {date} date 日期对象
|
|
1037
|
+
* @param {string} format 日期格式,默认为 "YYYY-MM-DD HH:mm:ss"
|
|
1038
|
+
*
|
|
1039
|
+
* @returns {number} 日期字符串
|
|
1040
|
+
*/
|
|
635
1041
|
Evaluator.prototype.fnDATETOSTR = function (date, format) {
|
|
636
1042
|
if (format === void 0) { format = 'YYYY-MM-DD HH:mm:ss'; }
|
|
637
1043
|
return moment__default["default"](date).format(format);
|
|
638
1044
|
};
|
|
1045
|
+
/**
|
|
1046
|
+
* 返回日期的指定范围的开端
|
|
1047
|
+
*
|
|
1048
|
+
* @namespace 日期函数
|
|
1049
|
+
* @example STARTOF(date[unit = "day"])
|
|
1050
|
+
* @param {date} date 日期对象
|
|
1051
|
+
* @param {string} unit 比如可以传入 'day'、'month'、'year' 或者 `week` 等等
|
|
1052
|
+
* @returns {date} 新的日期对象
|
|
1053
|
+
*/
|
|
639
1054
|
Evaluator.prototype.fnSTARTOF = function (date, unit) {
|
|
640
1055
|
return moment__default["default"](date)
|
|
641
1056
|
.startOf(unit || 'day')
|
|
642
1057
|
.toDate();
|
|
643
1058
|
};
|
|
1059
|
+
/**
|
|
1060
|
+
* 返回日期的指定范围的末尾
|
|
1061
|
+
* @namespace 日期函数
|
|
1062
|
+
* @example ENDOF(date[unit = "day"])
|
|
1063
|
+
* @param {date} date 日期对象
|
|
1064
|
+
* @param {string} unit 比如可以传入 'day'、'month'、'year' 或者 `week` 等等
|
|
1065
|
+
* @returns {date} 新的日期对象
|
|
1066
|
+
*/
|
|
644
1067
|
Evaluator.prototype.fnENDOF = function (date, unit) {
|
|
645
1068
|
return moment__default["default"](date)
|
|
646
1069
|
.endOf(unit || 'day')
|
|
@@ -662,82 +1085,232 @@ var Evaluator = /** @class */ (function () {
|
|
|
662
1085
|
}
|
|
663
1086
|
return raw;
|
|
664
1087
|
};
|
|
1088
|
+
/**
|
|
1089
|
+
* 返回日期的年份
|
|
1090
|
+
* @namespace 日期函数
|
|
1091
|
+
* @example YEAR(date)
|
|
1092
|
+
* @param {date} date 日期对象
|
|
1093
|
+
* @returns {number} 数值
|
|
1094
|
+
*/
|
|
665
1095
|
Evaluator.prototype.fnYEAR = function (date) {
|
|
666
1096
|
date = this.normalizeDate(date);
|
|
667
1097
|
return date.getFullYear();
|
|
668
1098
|
};
|
|
1099
|
+
/**
|
|
1100
|
+
* 返回日期的月份,这里就是自然月份。
|
|
1101
|
+
*
|
|
1102
|
+
* @namespace 日期函数
|
|
1103
|
+
* @example MONTH(date)
|
|
1104
|
+
* @param {date} date 日期对象
|
|
1105
|
+
* @returns {number} 数值
|
|
1106
|
+
*/
|
|
669
1107
|
Evaluator.prototype.fnMONTH = function (date) {
|
|
670
1108
|
date = this.normalizeDate(date);
|
|
671
1109
|
return date.getMonth() + 1;
|
|
672
1110
|
};
|
|
1111
|
+
/**
|
|
1112
|
+
* 返回日期的天
|
|
1113
|
+
* @namespace 日期函数
|
|
1114
|
+
* @example DAY(date)
|
|
1115
|
+
* @param {date} date 日期对象
|
|
1116
|
+
* @returns {number} 数值
|
|
1117
|
+
*/
|
|
673
1118
|
Evaluator.prototype.fnDAY = function (date) {
|
|
674
1119
|
date = this.normalizeDate(date);
|
|
675
1120
|
return date.getDate();
|
|
676
1121
|
};
|
|
1122
|
+
/**
|
|
1123
|
+
* 返回日期的小时
|
|
1124
|
+
* @param {date} date 日期对象
|
|
1125
|
+
* @namespace 日期函数
|
|
1126
|
+
* @example HOUR(date)
|
|
1127
|
+
* @returns {number} 数值
|
|
1128
|
+
*/
|
|
677
1129
|
Evaluator.prototype.fnHOUR = function (date) {
|
|
678
1130
|
date = this.normalizeDate(date);
|
|
679
1131
|
return date.getHours();
|
|
680
1132
|
};
|
|
681
|
-
|
|
1133
|
+
/**
|
|
1134
|
+
* 返回日期的分
|
|
1135
|
+
* @param {date} date 日期对象
|
|
1136
|
+
* @namespace 日期函数
|
|
1137
|
+
* @example MINUTE(date)
|
|
1138
|
+
* @returns {number} 数值
|
|
1139
|
+
*/
|
|
1140
|
+
Evaluator.prototype.fnMINUTE = function (date) {
|
|
682
1141
|
date = this.normalizeDate(date);
|
|
683
1142
|
return date.getMinutes();
|
|
684
1143
|
};
|
|
1144
|
+
/**
|
|
1145
|
+
* 返回日期的秒
|
|
1146
|
+
* @param {date} date 日期对象
|
|
1147
|
+
* @namespace 日期函数
|
|
1148
|
+
* @example SECOND(date)
|
|
1149
|
+
* @returns {number} 数值
|
|
1150
|
+
*/
|
|
685
1151
|
Evaluator.prototype.fnSECOND = function (date) {
|
|
686
1152
|
date = this.normalizeDate(date);
|
|
687
1153
|
return date.getSeconds();
|
|
688
1154
|
};
|
|
1155
|
+
/**
|
|
1156
|
+
* 返回两个日期相差多少年
|
|
1157
|
+
* @param {date} endDate 日期对象
|
|
1158
|
+
* @param {date} startDate 日期对象
|
|
1159
|
+
* @namespace 日期函数
|
|
1160
|
+
* @example YEARS(endDate, startDate)
|
|
1161
|
+
* @returns {number} 数值
|
|
1162
|
+
*/
|
|
689
1163
|
Evaluator.prototype.fnYEARS = function (endDate, startDate) {
|
|
690
1164
|
endDate = this.normalizeDate(endDate);
|
|
691
1165
|
startDate = this.normalizeDate(startDate);
|
|
692
1166
|
return moment__default["default"](endDate).diff(moment__default["default"](startDate), 'year');
|
|
693
1167
|
};
|
|
1168
|
+
/**
|
|
1169
|
+
* 返回两个日期相差多少分钟
|
|
1170
|
+
* @param {date} endDate 日期对象
|
|
1171
|
+
* @param {date} startDate 日期对象
|
|
1172
|
+
* @namespace 日期函数
|
|
1173
|
+
* @example MINUTES(endDate, startDate)
|
|
1174
|
+
* @returns {number} 数值
|
|
1175
|
+
*/
|
|
694
1176
|
Evaluator.prototype.fnMINUTES = function (endDate, startDate) {
|
|
695
1177
|
endDate = this.normalizeDate(endDate);
|
|
696
1178
|
startDate = this.normalizeDate(startDate);
|
|
697
1179
|
return moment__default["default"](endDate).diff(moment__default["default"](startDate), 'minutes');
|
|
698
1180
|
};
|
|
1181
|
+
/**
|
|
1182
|
+
* 返回两个日期相差多少天
|
|
1183
|
+
* @param {date} endDate 日期对象
|
|
1184
|
+
* @param {date} startDate 日期对象
|
|
1185
|
+
* @namespace 日期函数
|
|
1186
|
+
* @example DAYS(endDate, startDate)
|
|
1187
|
+
* @returns {number} 数值
|
|
1188
|
+
*/
|
|
699
1189
|
Evaluator.prototype.fnDAYS = function (endDate, startDate) {
|
|
700
1190
|
endDate = this.normalizeDate(endDate);
|
|
701
1191
|
startDate = this.normalizeDate(startDate);
|
|
702
1192
|
return moment__default["default"](endDate).diff(moment__default["default"](startDate), 'days');
|
|
703
1193
|
};
|
|
1194
|
+
/**
|
|
1195
|
+
* 返回两个日期相差多少小时
|
|
1196
|
+
* @param {date} endDate 日期对象
|
|
1197
|
+
* @param {date} startDate 日期对象
|
|
1198
|
+
* @namespace 日期函数
|
|
1199
|
+
* @example HOURS(endDate, startDate)
|
|
1200
|
+
* @returns {number} 数值
|
|
1201
|
+
*/
|
|
704
1202
|
Evaluator.prototype.fnHOURS = function (endDate, startDate) {
|
|
705
1203
|
endDate = this.normalizeDate(endDate);
|
|
706
1204
|
startDate = this.normalizeDate(startDate);
|
|
707
1205
|
return moment__default["default"](endDate).diff(moment__default["default"](startDate), 'hour');
|
|
708
1206
|
};
|
|
1207
|
+
/**
|
|
1208
|
+
* 修改日期,对日期进行加减天、月份、年等操作
|
|
1209
|
+
*
|
|
1210
|
+
* 示例:
|
|
1211
|
+
*
|
|
1212
|
+
* DATEMODIFY(A, -2, 'month')
|
|
1213
|
+
*
|
|
1214
|
+
* 对日期 A 进行往前减2月的操作。
|
|
1215
|
+
*
|
|
1216
|
+
* @param {date} date 日期对象
|
|
1217
|
+
* @param {number} num 数值
|
|
1218
|
+
* @param {string} unit 单位:支持年、月、天等等
|
|
1219
|
+
* @namespace 日期函数
|
|
1220
|
+
* @example DATEMODIFY(date, 2, 'days')
|
|
1221
|
+
* @returns {date} 日期对象
|
|
1222
|
+
*/
|
|
709
1223
|
Evaluator.prototype.fnDATEMODIFY = function (date, num, format) {
|
|
710
1224
|
date = this.normalizeDate(date);
|
|
711
1225
|
return moment__default["default"](date).add(num, format).toDate();
|
|
712
1226
|
};
|
|
1227
|
+
/**
|
|
1228
|
+
* 将字符日期转成日期对象,可以指定日期格式。
|
|
1229
|
+
*
|
|
1230
|
+
* 示例:STRTODATE('2021/12/6', 'YYYY/MM/DD')
|
|
1231
|
+
*
|
|
1232
|
+
* @param {string} value 日期字符
|
|
1233
|
+
* @param {string} format 日期格式
|
|
1234
|
+
* @namespace 日期函数
|
|
1235
|
+
* @example STRTODATE(value[, format=""])
|
|
1236
|
+
* @returns {date} 日期对象
|
|
1237
|
+
*/
|
|
713
1238
|
Evaluator.prototype.fnSTRTODATE = function (value, format) {
|
|
714
1239
|
if (format === void 0) { format = ''; }
|
|
715
1240
|
return moment__default["default"](value, format).toDate();
|
|
716
1241
|
};
|
|
1242
|
+
/**
|
|
1243
|
+
* 判断两个日期,是否第一个日期在第二个日期的前面
|
|
1244
|
+
*
|
|
1245
|
+
* @param {date} a 第一个日期
|
|
1246
|
+
* @param {date} b 第二个日期
|
|
1247
|
+
* @param {string} unit 单位,默认是 'day', 即之比较到天
|
|
1248
|
+
* @namespace 日期函数
|
|
1249
|
+
* @example ISBEFORE(a, b)
|
|
1250
|
+
* @returns {boolean} 判断结果
|
|
1251
|
+
*/
|
|
717
1252
|
Evaluator.prototype.fnISBEFORE = function (a, b, unit) {
|
|
718
1253
|
if (unit === void 0) { unit = 'day'; }
|
|
719
1254
|
a = this.normalizeDate(a);
|
|
720
1255
|
b = this.normalizeDate(b);
|
|
721
1256
|
return moment__default["default"](a).isBefore(moment__default["default"](b), unit);
|
|
722
1257
|
};
|
|
1258
|
+
/**
|
|
1259
|
+
* 判断两个日期,是否第一个日期在第二个日期的后面
|
|
1260
|
+
*
|
|
1261
|
+
* @param {date} a 第一个日期
|
|
1262
|
+
* @param {date} b 第二个日期
|
|
1263
|
+
* @param {string} unit 单位,默认是 'day', 即之比较到天
|
|
1264
|
+
* @namespace 日期函数
|
|
1265
|
+
* @example ISAFTER(a, b)
|
|
1266
|
+
* @returns {boolean} 判断结果
|
|
1267
|
+
*/
|
|
723
1268
|
Evaluator.prototype.fnISAFTER = function (a, b, unit) {
|
|
724
1269
|
if (unit === void 0) { unit = 'day'; }
|
|
725
1270
|
a = this.normalizeDate(a);
|
|
726
1271
|
b = this.normalizeDate(b);
|
|
727
1272
|
return moment__default["default"](a).isAfter(moment__default["default"](b), unit);
|
|
728
1273
|
};
|
|
1274
|
+
/**
|
|
1275
|
+
* 判断两个日期,是否第一个日期在第二个日期的前面或者相等
|
|
1276
|
+
*
|
|
1277
|
+
* @param {date} a 第一个日期
|
|
1278
|
+
* @param {date} b 第二个日期
|
|
1279
|
+
* @param {string} unit 单位,默认是 'day', 即之比较到天
|
|
1280
|
+
* @namespace 日期函数
|
|
1281
|
+
* @example ISSAMEORBEFORE(a, b)
|
|
1282
|
+
* @returns {boolean} 判断结果
|
|
1283
|
+
*/
|
|
729
1284
|
Evaluator.prototype.fnISSAMEORBEFORE = function (a, b, unit) {
|
|
730
1285
|
if (unit === void 0) { unit = 'day'; }
|
|
731
1286
|
a = this.normalizeDate(a);
|
|
732
1287
|
b = this.normalizeDate(b);
|
|
733
1288
|
return moment__default["default"](a).isSameOrBefore(moment__default["default"](b), unit);
|
|
734
1289
|
};
|
|
1290
|
+
/**
|
|
1291
|
+
* 判断两个日期,是否第一个日期在第二个日期的后面或者相等
|
|
1292
|
+
*
|
|
1293
|
+
* @param {date} a 第一个日期
|
|
1294
|
+
* @param {date} b 第二个日期
|
|
1295
|
+
* @param {string} unit 单位,默认是 'day', 即之比较到天
|
|
1296
|
+
* @namespace 日期函数
|
|
1297
|
+
* @example ISSAMEORAFTER(a, b)
|
|
1298
|
+
* @returns {boolean} 判断结果
|
|
1299
|
+
*/
|
|
735
1300
|
Evaluator.prototype.fnISSAMEORAFTER = function (a, b, unit) {
|
|
736
1301
|
if (unit === void 0) { unit = 'day'; }
|
|
737
1302
|
a = this.normalizeDate(a);
|
|
738
1303
|
b = this.normalizeDate(b);
|
|
739
1304
|
return moment__default["default"](a).isSameOrAfter(moment__default["default"](b), unit);
|
|
740
1305
|
};
|
|
1306
|
+
/**
|
|
1307
|
+
* 返回数组的长度
|
|
1308
|
+
*
|
|
1309
|
+
* @param {Array<any>} arr 数组
|
|
1310
|
+
* @namespace 其他
|
|
1311
|
+
* @example COUNT(arr)
|
|
1312
|
+
* @returns {boolean} 结果
|
|
1313
|
+
*/
|
|
741
1314
|
Evaluator.prototype.fnCOUNT = function (value) {
|
|
742
1315
|
return Array.isArray(value) ? value.length : value ? 1 : 0;
|
|
743
1316
|
};
|
|
@@ -999,17 +1572,17 @@ function lexer(input, options) {
|
|
|
999
1572
|
else {
|
|
1000
1573
|
// 支持旧的 $varName 的取值方法
|
|
1001
1574
|
var j = i + 2;
|
|
1002
|
-
while (/^[a-zA-Z0-9_
|
|
1575
|
+
while (/^[a-zA-Z0-9_][a-zA-Z0-9_]*$/.test(input.substring(i + 1, j)) &&
|
|
1003
1576
|
j <= input.length) {
|
|
1004
1577
|
j++;
|
|
1005
1578
|
}
|
|
1006
1579
|
if (j - i > 2) {
|
|
1007
1580
|
tokenCache.push({
|
|
1008
1581
|
type: TokenName[TokenEnum.Variable],
|
|
1009
|
-
value: input.substring(i + 1, j),
|
|
1010
|
-
raw: input.substring(i, j),
|
|
1582
|
+
value: input.substring(i + 1, j - 1),
|
|
1583
|
+
raw: input.substring(i, j - 1),
|
|
1011
1584
|
start: position(input.substring(index, i)),
|
|
1012
|
-
end: position(input.substring(index, j))
|
|
1585
|
+
end: position(input.substring(index, j - 1))
|
|
1013
1586
|
});
|
|
1014
1587
|
break;
|
|
1015
1588
|
}
|
|
@@ -1788,10 +2361,7 @@ function parse(input, options) {
|
|
|
1788
2361
|
while (matchPunctuator('[') || matchPunctuator('.')) {
|
|
1789
2362
|
var isDot = matchPunctuator('.');
|
|
1790
2363
|
next();
|
|
1791
|
-
var right = assert((
|
|
1792
|
-
? identifier() || numberLiteral()
|
|
1793
|
-
: varibleKey(true)) /* 为了兼容久的语法,理论上来说只需要 identifier, 下面的 rawScript 是不应该有的 */ ||
|
|
1794
|
-
rawScript());
|
|
2364
|
+
var right = assert(isDot ? identifier() || numberLiteral() || rawScript() : expression());
|
|
1795
2365
|
if (!isDot) {
|
|
1796
2366
|
assert(matchPunctuator(']'));
|
|
1797
2367
|
next();
|
|
@@ -2593,7 +3163,12 @@ var filters = {
|
|
|
2593
3163
|
length = parseInt(length, 10) || 200;
|
|
2594
3164
|
return input.substring(0, length) + (input.length > length ? end : '');
|
|
2595
3165
|
},
|
|
2596
|
-
url_encode: function (input) {
|
|
3166
|
+
url_encode: function (input) {
|
|
3167
|
+
if (input == null) {
|
|
3168
|
+
return '';
|
|
3169
|
+
}
|
|
3170
|
+
return encodeURIComponent(input);
|
|
3171
|
+
},
|
|
2597
3172
|
url_decode: function (input) { return decodeURIComponent(input); },
|
|
2598
3173
|
default: function (input, defaultValue, strict) {
|
|
2599
3174
|
var _a;
|
|
@@ -2907,6 +3482,7 @@ function skipRestTest(restFilters) {
|
|
|
2907
3482
|
}
|
|
2908
3483
|
function registerFilter(name, fn) {
|
|
2909
3484
|
filters[name] = fn;
|
|
3485
|
+
Evaluator.setDefaultFilters(filters);
|
|
2910
3486
|
}
|
|
2911
3487
|
function getFilters() {
|
|
2912
3488
|
return filters;
|