@leankylin-sheet/formula-parser 4.0.44 → 4.0.45
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function multiplyNumber(num1?: number, num2?: number): number;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Emitter from 'tiny-emitter';
|
|
2
2
|
import * as formulajs from '@formulajs/formulajs';
|
|
3
3
|
import { utils } from '@formulajs/formulajs';
|
|
4
|
+
import { Decimal } from 'decimal.js';
|
|
4
5
|
|
|
5
6
|
function _callSuper(t, o, e) {
|
|
6
7
|
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
|
|
@@ -472,6 +473,19 @@ function func$9(first) {
|
|
|
472
473
|
}
|
|
473
474
|
func$9.SYMBOL = SYMBOL$9;
|
|
474
475
|
|
|
476
|
+
/**
|
|
477
|
+
* 解决js处理精度问题
|
|
478
|
+
* 0.3 * 0.1 = 0.03
|
|
479
|
+
* @param num1
|
|
480
|
+
* @param num2
|
|
481
|
+
* @returns
|
|
482
|
+
*/
|
|
483
|
+
var multiplyNumber = function multiplyNumber() {
|
|
484
|
+
var num1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
485
|
+
var num2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
486
|
+
return new Decimal(num1).mul(num2).toNumber();
|
|
487
|
+
};
|
|
488
|
+
|
|
475
489
|
var SYMBOL$a = "*";
|
|
476
490
|
|
|
477
491
|
// export default function func(first, ...rest) {
|
|
@@ -496,7 +510,7 @@ function func$a(first) {
|
|
|
496
510
|
return Array.isArray(rItem) ? rItem[index] : toNumber(rItem);
|
|
497
511
|
});
|
|
498
512
|
var v = _list.reduce(function (acc, value) {
|
|
499
|
-
return acc
|
|
513
|
+
return multiplyNumber(acc, toNumber(value));
|
|
500
514
|
}, toNumber(item));
|
|
501
515
|
if (isNaN(v)) {
|
|
502
516
|
throw Error(ERROR_VALUE);
|
|
@@ -506,7 +520,7 @@ function func$a(first) {
|
|
|
506
520
|
return dd;
|
|
507
521
|
}
|
|
508
522
|
var result = rest.reduce(function (acc, value) {
|
|
509
|
-
return acc
|
|
523
|
+
return multiplyNumber(acc, toNumber(value));
|
|
510
524
|
}, toNumber(first));
|
|
511
525
|
if (isNaN(result)) {
|
|
512
526
|
throw Error(ERROR_VALUE);
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var Emitter = require('tiny-emitter');
|
|
6
6
|
var formulajs = require('@formulajs/formulajs');
|
|
7
|
+
var decimal_js = require('decimal.js');
|
|
7
8
|
|
|
8
9
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
10
|
|
|
@@ -500,6 +501,19 @@ function func$9(first) {
|
|
|
500
501
|
}
|
|
501
502
|
func$9.SYMBOL = SYMBOL$9;
|
|
502
503
|
|
|
504
|
+
/**
|
|
505
|
+
* 解决js处理精度问题
|
|
506
|
+
* 0.3 * 0.1 = 0.03
|
|
507
|
+
* @param num1
|
|
508
|
+
* @param num2
|
|
509
|
+
* @returns
|
|
510
|
+
*/
|
|
511
|
+
var multiplyNumber = function multiplyNumber() {
|
|
512
|
+
var num1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
513
|
+
var num2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
514
|
+
return new decimal_js.Decimal(num1).mul(num2).toNumber();
|
|
515
|
+
};
|
|
516
|
+
|
|
503
517
|
var SYMBOL$a = "*";
|
|
504
518
|
|
|
505
519
|
// export default function func(first, ...rest) {
|
|
@@ -524,7 +538,7 @@ function func$a(first) {
|
|
|
524
538
|
return Array.isArray(rItem) ? rItem[index] : toNumber(rItem);
|
|
525
539
|
});
|
|
526
540
|
var v = _list.reduce(function (acc, value) {
|
|
527
|
-
return acc
|
|
541
|
+
return multiplyNumber(acc, toNumber(value));
|
|
528
542
|
}, toNumber(item));
|
|
529
543
|
if (isNaN(v)) {
|
|
530
544
|
throw Error(ERROR_VALUE);
|
|
@@ -534,7 +548,7 @@ function func$a(first) {
|
|
|
534
548
|
return dd;
|
|
535
549
|
}
|
|
536
550
|
var result = rest.reduce(function (acc, value) {
|
|
537
|
-
return acc
|
|
551
|
+
return multiplyNumber(acc, toNumber(value));
|
|
538
552
|
}, toNumber(first));
|
|
539
553
|
if (isNaN(result)) {
|
|
540
554
|
throw Error(ERROR_VALUE);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leankylin-sheet/formula-parser",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.45",
|
|
4
4
|
"description": "Formula parser",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@formulajs/formulajs": "^4.5.6",
|
|
40
|
+
"decimal.js": "^10.6.0",
|
|
40
41
|
"tiny-emitter": "^2.1.0"
|
|
41
42
|
},
|
|
42
43
|
"jest": {
|