@argent/x-shared 1.46.1 → 1.47.0
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=t=>/^(-?\d+\.?\d*|\.\d+)[eE]([+-]?\d+)$/.test(t),d=t=>{if(!l(t))throw new Error("Invalid scientific notation");const[e,s]=t.toLowerCase().split("e"),n=parseInt(s,10),o=e.indexOf("."),c=e.replace(".","").replace("-",""),r=e.startsWith("-");let i=c,a=o===-1?0:e.length-o-1;return n>0?i=i.padEnd(i.length+n,"0"):n<0&&(a+=Math.abs(n)),i=i.replace(/^0+/,"")||"0",{value:BigInt(`${r?"-":""}${i}`),decimals:a}},u=(t,e)=>{if(l(t))return d(t);const[s,n=""]=t.split("."),o=s.startsWith("-"),c=o?s.slice(1):s,r=e??n.length,i=n.slice(0,r),a=e!==void 0&&n.length>e?p(i,n[e]):i.padEnd(r,"0");return{value:BigInt(`${o?"-":""}${c}${a}`),decimals:r}},p=(t,e)=>Number(e)>=5?(BigInt(t)+1n).toString().padStart(t.length,"0"):t;exports.parseUnits=u;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BigDecimal } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Parses a string value representing a number to a BigInt, with a specified or determined number of decimals.
|
|
4
|
-
*
|
|
4
|
+
* Supports both regular decimal notation and scientific notation (e.g., "3.834e-9").
|
|
5
5
|
*
|
|
6
6
|
* @param {string} value - The string value to be parsed.
|
|
7
7
|
* @param {number} [decimals] - The number of decimals to consider during parsing. If not provided, it uses as many as needed.
|
|
@@ -1,10 +1,21 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
1
|
+
const l = (t) => /^(-?\d+\.?\d*|\.\d+)[eE]([+-]?\d+)$/.test(t), d = (t) => {
|
|
2
|
+
if (!l(t))
|
|
3
|
+
throw new Error("Invalid scientific notation");
|
|
4
|
+
const [n, o] = t.toLowerCase().split("e"), e = parseInt(o, 10), s = n.indexOf("."), c = n.replace(".", "").replace("-", ""), r = n.startsWith("-");
|
|
5
|
+
let i = c, a = s === -1 ? 0 : n.length - s - 1;
|
|
6
|
+
return e > 0 ? i = i.padEnd(i.length + e, "0") : e < 0 && (a += Math.abs(e)), i = i.replace(/^0+/, "") || "0", {
|
|
7
|
+
value: BigInt(`${r ? "-" : ""}${i}`),
|
|
8
|
+
decimals: a
|
|
9
|
+
};
|
|
10
|
+
}, g = (t, n) => {
|
|
11
|
+
if (l(t))
|
|
12
|
+
return d(t);
|
|
13
|
+
const [o, e = ""] = t.split("."), s = o.startsWith("-"), c = s ? o.slice(1) : o, r = n ?? e.length, i = e.slice(0, r), a = n !== void 0 && e.length > n ? p(i, e[n]) : i.padEnd(r, "0");
|
|
3
14
|
return {
|
|
4
|
-
value: BigInt(`${s ? "-" : ""}${c}${
|
|
15
|
+
value: BigInt(`${s ? "-" : ""}${c}${a}`),
|
|
5
16
|
decimals: r
|
|
6
17
|
};
|
|
7
|
-
},
|
|
18
|
+
}, p = (t, n) => Number(n) >= 5 ? (BigInt(t) + 1n).toString().padStart(t.length, "0") : t;
|
|
8
19
|
export {
|
|
9
|
-
|
|
20
|
+
g as parseUnits
|
|
10
21
|
};
|