@rinxun/numeric-calculator 1.0.3 → 1.0.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/README.md +1 -0
- package/index.d.ts +2 -0
- package/index.js +8 -2
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -48,6 +48,7 @@ This project is licensed under the terms of the [MIT license](https://github.com
|
|
|
48
48
|
|
|
49
49
|
- ```js
|
|
50
50
|
config = {
|
|
51
|
+
precision?: number, // global precision, default to 15
|
|
51
52
|
enableCheckBoundary?: boolean // if true, it will check if the value is out of the safe boundary
|
|
52
53
|
}
|
|
53
54
|
```
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
declare type IConfig = {
|
|
2
|
+
precision?: number;
|
|
2
3
|
enableCheckBoundary?: boolean;
|
|
3
4
|
};
|
|
4
5
|
declare type IOperand = Calculator | number | string;
|
|
@@ -13,6 +14,7 @@ declare class Calculator {
|
|
|
13
14
|
* @description global register for temporary results, core for chaining operations
|
|
14
15
|
*/
|
|
15
16
|
private _VALUE;
|
|
17
|
+
private _precision;
|
|
16
18
|
/**
|
|
17
19
|
* @private
|
|
18
20
|
* @description for debugging, if true, it will check if the value is out of the safe boundary
|
package/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2
3
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
4
|
if (ar || !(i in from)) {
|
|
@@ -7,6 +8,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
7
8
|
}
|
|
8
9
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
10
|
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
12
|
/**
|
|
11
13
|
* @description Calculate addition, subtaction, multiplication, division precisely, for tackling the precision issue
|
|
12
14
|
* @author Janden Ma
|
|
@@ -27,6 +29,7 @@ var Calculator = /** @class */ (function () {
|
|
|
27
29
|
* @description global register for temporary results, core for chaining operations
|
|
28
30
|
*/
|
|
29
31
|
this._VALUE = undefined;
|
|
32
|
+
this._precision = 15;
|
|
30
33
|
/**
|
|
31
34
|
* @private
|
|
32
35
|
* @description for debugging, if true, it will check if the value is out of the safe boundary
|
|
@@ -36,6 +39,9 @@ var Calculator = /** @class */ (function () {
|
|
|
36
39
|
this._VALUE = this.parseOperandToNum(operand);
|
|
37
40
|
}
|
|
38
41
|
if (config) {
|
|
42
|
+
if (config.precision !== undefined) {
|
|
43
|
+
this._precision = config.precision;
|
|
44
|
+
}
|
|
39
45
|
if (config.enableCheckBoundary) {
|
|
40
46
|
this._enableCheckBoundary = config.enableCheckBoundary;
|
|
41
47
|
}
|
|
@@ -89,7 +95,7 @@ var Calculator = /** @class */ (function () {
|
|
|
89
95
|
* @param {number} precision default 15
|
|
90
96
|
*/
|
|
91
97
|
Calculator.prototype.processPrecision = function (num, precision) {
|
|
92
|
-
return +parseFloat(num.toPrecision(precision || 15));
|
|
98
|
+
return +parseFloat(num.toPrecision(precision || this._precision || 15));
|
|
93
99
|
};
|
|
94
100
|
/**
|
|
95
101
|
* core processor for times
|
|
@@ -261,4 +267,4 @@ var Calculator = /** @class */ (function () {
|
|
|
261
267
|
};
|
|
262
268
|
return Calculator;
|
|
263
269
|
}());
|
|
264
|
-
|
|
270
|
+
exports.default = Calculator;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rinxun/numeric-calculator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Calculate addition, subtraction, multiplication, division precisely, for tackling the precision issue",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"long",
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
"division"
|
|
16
16
|
],
|
|
17
17
|
"main": "index.js",
|
|
18
|
-
"type": "module",
|
|
19
18
|
"types": "**/*.d.ts",
|
|
20
19
|
"license": "MIT",
|
|
21
20
|
"private": false,
|