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