safe-math-ops 0.0.4 → 0.0.5
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/index.js +1 -90
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,90 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var cache = {};
|
|
3
|
-
setInterval(() => {
|
|
4
|
-
cache = {};
|
|
5
|
-
}, 15000);
|
|
6
|
-
var cache_default = cache;
|
|
7
|
-
|
|
8
|
-
// src/libs/calcHighestDecimalPoint.ts
|
|
9
|
-
function calcHighestDecimalPoint(numbers, type) {
|
|
10
|
-
let key = 0;
|
|
11
|
-
for (let i of numbers) {
|
|
12
|
-
if (type === "add")
|
|
13
|
-
key += i;
|
|
14
|
-
if (type === "substract")
|
|
15
|
-
key -= i;
|
|
16
|
-
if (type === "divide")
|
|
17
|
-
key /= i;
|
|
18
|
-
if (type === "multiply")
|
|
19
|
-
key *= i;
|
|
20
|
-
}
|
|
21
|
-
key = key * numbers.length + "";
|
|
22
|
-
let result = cache_default[key];
|
|
23
|
-
if (!result) {
|
|
24
|
-
cache_default[key] = numbers.filter((v) => typeof v === "number").map((v) => (v.toString().split(".")?.[1] || "").length).sort((a, b) => b - a)?.[0] || 0;
|
|
25
|
-
result = cache_default[key];
|
|
26
|
-
}
|
|
27
|
-
return {
|
|
28
|
-
result,
|
|
29
|
-
key
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// src/libs/add.ts
|
|
34
|
-
function add(...numbers) {
|
|
35
|
-
const highDecimalPoint = calcHighestDecimalPoint(numbers, "add");
|
|
36
|
-
const key = "a" + highDecimalPoint.key;
|
|
37
|
-
let result = cache_default[key];
|
|
38
|
-
if (!result) {
|
|
39
|
-
cache_default[key] = parseFloat(numbers.filter((v) => typeof v === "number").reduce((a, b) => a + b).toFixed(highDecimalPoint.result));
|
|
40
|
-
result = cache_default[key];
|
|
41
|
-
}
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// src/libs/divide.ts
|
|
46
|
-
function divide(...numbers) {
|
|
47
|
-
const highDecimalPoint = calcHighestDecimalPoint(numbers, "divide");
|
|
48
|
-
const key = "d" + highDecimalPoint.key;
|
|
49
|
-
let result = cache_default[key];
|
|
50
|
-
if (!result) {
|
|
51
|
-
cache_default[key] = parseFloat(numbers.filter((v) => typeof v === "number").reduce((a, b) => a / b).toFixed(highDecimalPoint.result));
|
|
52
|
-
result = cache_default[key];
|
|
53
|
-
}
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// src/libs/multiply.ts
|
|
58
|
-
function multiply(...numbers) {
|
|
59
|
-
const highDecimalPoint = calcHighestDecimalPoint(numbers, "multiply");
|
|
60
|
-
const key = "m" + highDecimalPoint.key;
|
|
61
|
-
let result = cache_default[key];
|
|
62
|
-
if (!result) {
|
|
63
|
-
cache_default[key] = parseFloat(numbers.filter((v) => typeof v === "number").reduce((a, b) => a * b).toFixed(highDecimalPoint.result));
|
|
64
|
-
result = cache_default[key];
|
|
65
|
-
}
|
|
66
|
-
return result;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// src/libs/substract.ts
|
|
70
|
-
function substract(...numbers) {
|
|
71
|
-
const highDecimalPoint = calcHighestDecimalPoint(numbers, "substract");
|
|
72
|
-
const key = "s" + highDecimalPoint.key;
|
|
73
|
-
let result = cache_default[key];
|
|
74
|
-
if (!result) {
|
|
75
|
-
cache_default[key] = parseFloat(numbers.filter((v) => typeof v === "number").reduce((a, b) => a - b).toFixed(highDecimalPoint.result));
|
|
76
|
-
result = cache_default[key];
|
|
77
|
-
}
|
|
78
|
-
return result;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// src/index.ts
|
|
82
|
-
var src_default = { add, substract, multiply, divide, calcHighestDecimalPoint };
|
|
83
|
-
export {
|
|
84
|
-
substract,
|
|
85
|
-
multiply,
|
|
86
|
-
divide,
|
|
87
|
-
src_default as default,
|
|
88
|
-
calcHighestDecimalPoint,
|
|
89
|
-
add
|
|
90
|
-
};
|
|
1
|
+
var s={};setInterval(()=>{s={}},15000);var i=s;function c(l,o){let t=0;for(let e of l){if(o==="add")t+=e;if(o==="substract")t-=e;if(o==="divide")t/=e;if(o==="multiply")t*=e}t=t*l.length+"";let r=i[t];if(!r)i[t]=l.filter((e)=>typeof e==="number").map((e)=>(e.toString().split(".")?.[1]||"").length).sort((e,a)=>a-e)?.[0]||0,r=i[t];return{result:r,key:t}}function m(...l){let o=c(l,"add"),t="a"+o.key,r=i[t];if(!r)i[t]=parseFloat(l.filter((e)=>typeof e==="number").reduce((e,a)=>e+a).toFixed(o.result)),r=i[t];return r}function f(...l){let o=c(l,"divide"),t="d"+o.key,r=i[t];if(!r)i[t]=parseFloat(l.filter((e)=>typeof e==="number").reduce((e,a)=>e/a).toFixed(o.result)),r=i[t];return r}function n(...l){let o=c(l,"multiply"),t="m"+o.key,r=i[t];if(!r)i[t]=parseFloat(l.filter((e)=>typeof e==="number").reduce((e,a)=>e*a).toFixed(o.result)),r=i[t];return r}function u(...l){let o=c(l,"substract"),t="s"+o.key,r=i[t];if(!r)i[t]=parseFloat(l.filter((e)=>typeof e==="number").reduce((e,a)=>e-a).toFixed(o.result)),r=i[t];return r}var B={add:m,substract:u,multiply:n,divide:f,calcHighestDecimalPoint:c};export{u as substract,n as multiply,f as divide,B as default,c as calcHighestDecimalPoint,m as add};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "safe-math-ops",
|
|
3
3
|
"module": "src/index.ts",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.5",
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@types/bun": "latest",
|
|
8
8
|
"rimraf": "^6.1.3"
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"author": "ctev",
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "bun build --target=node ./src/index.ts --outfile=dist/index.js && bun run build:declaration",
|
|
20
|
+
"build": "bun build --minify --target=node ./src/index.ts --outfile=dist/index.js && bun run build:declaration",
|
|
21
21
|
"build:declaration": "tsc --emitDeclarationOnly --project tsconfig.types.json",
|
|
22
22
|
"postbuild": "rimraf tsconfig.types.tsbuildinfo"
|
|
23
23
|
},
|