@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 u=(n,t)=>{const[o,e=""]=n.split("."),s=o.startsWith("-"),i=s?o.slice(1):o,r=t??e.length,a=e.slice(0,r),c=t!==void 0&&e.length>t?l(a,e[t]):a.padEnd(r,"0");return{value:BigInt(`${s?"-":""}${i}${c}`),decimals:r}},l=(n,t)=>Number(t)>=5?(BigInt(n)+1n).toString().padStart(n.length,"0"):n;exports.parseUnits=u;
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
- * If decimals are specified and the fraction part of the string value is longer than the allowed decimal places, it rounds the value.
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 d = (n, t) => {
2
- const [e, o = ""] = n.split("."), s = e.startsWith("-"), c = s ? e.slice(1) : e, r = t ?? o.length, a = o.slice(0, r), i = t !== void 0 && o.length > t ? u(a, o[t]) : a.padEnd(r, "0");
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}${i}`),
15
+ value: BigInt(`${s ? "-" : ""}${c}${a}`),
5
16
  decimals: r
6
17
  };
7
- }, u = (n, t) => Number(t) >= 5 ? (BigInt(n) + 1n).toString().padStart(n.length, "0") : n;
18
+ }, p = (t, n) => Number(n) >= 5 ? (BigInt(t) + 1n).toString().padStart(t.length, "0") : t;
8
19
  export {
9
- d as parseUnits
20
+ g as parseUnits
10
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@argent/x-shared",
3
- "version": "1.46.1",
3
+ "version": "1.47.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/argentlabs/x-shared.git"