@argent/x-shared 1.57.0 → 1.58.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.
@@ -197,8 +197,8 @@ export declare const webTokenWithBalanceAndPriceSchema: z.ZodObject<z.objectUtil
197
197
  }>, "strip", z.ZodTypeAny, {
198
198
  address: `0x${string}`;
199
199
  networkId: string;
200
- balance: string;
201
200
  currencyValue: string;
201
+ balance: string;
202
202
  symbol?: string | undefined;
203
203
  name?: string | undefined;
204
204
  decimals?: number | undefined;
@@ -215,8 +215,8 @@ export declare const webTokenWithBalanceAndPriceSchema: z.ZodObject<z.objectUtil
215
215
  }, {
216
216
  address: string;
217
217
  networkId: string;
218
- balance: string;
219
218
  currencyValue: string;
219
+ balance: string;
220
220
  symbol?: string | undefined;
221
221
  name?: string | undefined;
222
222
  decimals?: number | undefined;
@@ -267,8 +267,8 @@ export declare const webTokensWithBalanceAndPriceSchema: z.ZodArray<z.ZodObject<
267
267
  }>, "strip", z.ZodTypeAny, {
268
268
  address: `0x${string}`;
269
269
  networkId: string;
270
- balance: string;
271
270
  currencyValue: string;
271
+ balance: string;
272
272
  symbol?: string | undefined;
273
273
  name?: string | undefined;
274
274
  decimals?: number | undefined;
@@ -285,8 +285,8 @@ export declare const webTokensWithBalanceAndPriceSchema: z.ZodArray<z.ZodObject<
285
285
  }, {
286
286
  address: string;
287
287
  networkId: string;
288
- balance: string;
289
288
  currencyValue: string;
289
+ balance: string;
290
290
  symbol?: string | undefined;
291
291
  name?: string | undefined;
292
292
  decimals?: number | undefined;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../../../_virtual/numeral.cjs"),o=require("./isNumeric.cjs"),b=(e,i=",",a=2)=>{let r=e;if(typeof e=="string"&&(r=e.replaceAll(i,"")),!o.isNumeric(r))return;const t=Number(r);if(Math.abs(t)<1e3)return t.toString();const u=`0.[${"0".repeat(a)}]a`;return n.default(t).format(u).toUpperCase()};exports.abbreviateNumber=b;
@@ -0,0 +1,13 @@
1
+ import { BigNumberish } from 'starknet';
2
+ /**
3
+ * Abbreviates large numbers into a more readable format with metric prefixes (K, M, B, etc.)
4
+ * @param value - The number to abbreviate. Can be a number, string, or bigint
5
+ * @param groupSeparator - The separator used for grouping digits in string input (default: ",")
6
+ * @param digitsAfterDecimal - Number of decimal places to show in abbreviated result (default: 2)
7
+ * @returns Abbreviated number as string (e.g. "1.23K", "45.6M") or undefined if input is invalid
8
+ * @example
9
+ * abbreviateNumber(1234) // "1.23K"
10
+ * abbreviateNumber("1,234,567") // "1.23M"
11
+ * abbreviateNumber(1234567890) // "1.23B"
12
+ */
13
+ export declare const abbreviateNumber: (value?: BigNumberish, groupSeparator?: string, digitsAfterDecimal?: number) => string | undefined;
@@ -0,0 +1,15 @@
1
+ import m from "../../../_virtual/numeral.js";
2
+ import { isNumeric as n } from "./isNumeric.js";
3
+ const p = (r, o = ",", a = 2) => {
4
+ let e = r;
5
+ if (typeof r == "string" && (e = r.replaceAll(o, "")), !n(e))
6
+ return;
7
+ const t = Number(e);
8
+ if (Math.abs(t) < 1e3)
9
+ return t.toString();
10
+ const i = `0.[${"0".repeat(a)}]a`;
11
+ return m(t).format(i).toUpperCase();
12
+ };
13
+ export {
14
+ p as abbreviateNumber
15
+ };
@@ -2,3 +2,4 @@ export * from './isAllowedAddressHexInputValue';
2
2
  export * from './isAllowedNumericInputValue';
3
3
  export * from './isNumeric';
4
4
  export * from './prettifyNumber';
5
+ export * from './abbreviateNumber';
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../../../node_modules/.pnpm/bignumber.js@9.1.2/node_modules/bignumber.js/bignumber.cjs"),P=require("./isNumeric.cjs"),c={CURRENCY:{minDecimalPlaces:2,maxDecimalPlaces:10,minDecimalSignificantDigits:2,decimalPlacesWhenZero:2,allowLeadingZerosInDecimalPart:!0},TOKEN:{minDecimalPlaces:4,maxDecimalPlaces:16,minDecimalSignificantDigits:2,decimalPlacesWhenZero:1,allowLeadingZerosInDecimalPart:!0}},h=(t,e)=>l(t,{...c.CURRENCY,...e||{}}),C=(t,e)=>l(t,{...c.TOKEN,...e||{}}),l=(t,{minDecimalPlaces:e,maxDecimalPlaces:N,minDecimalSignificantDigits:p,decimalPlacesWhenZero:m,allowLeadingZerosInDecimalPart:u}=c.CURRENCY)=>{if(!P.isNumeric(t))return null;const r=new s.BigNumber(typeof t=="bigint"?t.toString():t);let i;const b=`0.${"".padStart(m-1,"0")}1`;if(r.lt(new s.BigNumber(b))&&!u)i=`0.${"".padStart(m,"0")}`;else if(r.gte(1))i=e!==0?r.toFormat(e):r.toFormat(e,s.BigNumber.ROUND_FLOOR);else{const o=r.toFormat(N).split(".")[1].match(/^0+/),d=u&&o&&o.length?o[0].length:0,y=Math.max(d+p,e);i=r.toFormat(y)}const[D,g]=i.split(".");let a=D;if(g){const n=g.replace(/0+$/,"");a+=n?`.${n}`:""}const f=1+i.indexOf(".")+m;return a.length<f&&(a=i.substring(0,f)),a};exports.prettifyCurrencyNumber=h;exports.prettifyNumber=l;exports.prettifyNumberConfig=c;exports.prettifyTokenNumber=C;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../../../node_modules/.pnpm/bignumber.js@9.1.2/node_modules/bignumber.js/bignumber.cjs"),x=require("./isNumeric.cjs"),u={CURRENCY:{minDecimalPlaces:2,maxDecimalPlaces:10,minDecimalSignificantDigits:2,decimalPlacesWhenZero:2,allowLeadingZerosInDecimalPart:!0,groupSeparator:",",decimalSeparator:"."},TOKEN:{minDecimalPlaces:4,maxDecimalPlaces:16,minDecimalSignificantDigits:2,decimalPlacesWhenZero:1,allowLeadingZerosInDecimalPart:!0,groupSeparator:",",decimalSeparator:"."}},E=(r,e)=>D(r,{...u.CURRENCY,...e||{}}),T=(r,e)=>D(r,{...u.TOKEN,...e||{}}),R={groupSize:3,decimalSeparator:".",groupSeparator:","},D=(r,{minDecimalPlaces:e,maxDecimalPlaces:y,minDecimalSignificantDigits:C,decimalPlacesWhenZero:p,allowLeadingZerosInDecimalPart:S,groupSeparator:N,decimalSeparator:o=R.decimalSeparator,maxNrDigits:g,roundingMode:s}=u.CURRENCY)=>{if(!x.isNumeric(r))return null;const c={...R,groupSeparator:N,decimalSeparator:o},i=new h.BigNumber(typeof r=="bigint"?r.toString():r);let a;const F=`0.${"".padStart(p-1,"0")}1`;if(i.lt(new h.BigNumber(F))&&!S)a=`0.${"".padStart(p,"0")}`;else if(i.gte(1))a=e!==0?s?i.toFormat(e,s,c):i.toFormat(e,c):i.toFormat(e,h.BigNumber.ROUND_FLOOR,c);else{const l=(s?i.toFormat(y,s,c):i.toFormat(y,c)).split(o)[1].match(/^0+/),m=S&&l&&l.length?l[0].length:0,f=Math.max(m+C,e);a=s?i.toFormat(f,s,c):i.toFormat(f,c)}const[b,O]=a.split(o);let t=b;if(O){const n=O.replace(/0+$/,"");t+=n?`.${n}`:""}const P=1+a.indexOf(".")+p;if(t.length<P&&(t=a.substring(0,P)),g){const n=t.replace(new RegExp(`[${N}${o}]`,"g"),"").length;if(b.replace(new RegExp(`[${N}]`,"g"),"").length>g)t=b;else if(n>g){const l=n-g,m=t.indexOf(o);if(m!==-1){const f=Math.max(0,t.length-m-1-l);t=t.substring(0,m+1+f)}}}return t};exports.prettifyCurrencyNumber=E;exports.prettifyNumber=D;exports.prettifyNumberConfig=u;exports.prettifyTokenNumber=T;
@@ -1,3 +1,4 @@
1
+ import { BigNumber } from 'big-decimal-number';
1
2
  import { BigNumberish } from 'starknet';
2
3
  export interface IPrettifyNumberConfig {
3
4
  minDecimalPlaces: number;
@@ -8,13 +9,18 @@ export interface IPrettifyNumberConfig {
8
9
  decimalPlacesWhenZero: number;
9
10
  /** allow leading zeros in the decimal part e.g. 0.0123 -> 0.012 */
10
11
  allowLeadingZerosInDecimalPart: boolean;
12
+ /** group separator for the number e.g. 123456 -> 123,456 */
13
+ groupSeparator: string;
14
+ /** decimal separator for the number e.g. 123456 -> 123.456 */
15
+ decimalSeparator: string;
16
+ /** maximum number of digits to display. Does not override the other decimal places config.It is applied as a last step.
17
+ * If the number has more integer digits than maxNrDigits, it will keep only the integer part.
18
+ * If the number has more digits than maxNrDigits, it will trim the decimal part. */
19
+ maxNrDigits?: number;
20
+ /** rounding mode for the number */
21
+ roundingMode?: BigNumber.RoundingMode;
11
22
  }
12
23
  export declare const prettifyNumberConfig: Record<string, IPrettifyNumberConfig>;
13
24
  export declare const prettifyCurrencyNumber: (number: BigNumberish, overrides?: Partial<IPrettifyNumberConfig>) => string | null;
14
25
  export declare const prettifyTokenNumber: (number: BigNumberish, overrides?: Partial<IPrettifyNumberConfig>) => string | null;
15
- /**
16
- * Prettify an input number for display according to the config
17
- *
18
- * @see test suite for examples
19
- */
20
- export declare const prettifyNumber: (number: BigNumberish, { minDecimalPlaces, maxDecimalPlaces, minDecimalSignificantDigits, decimalPlacesWhenZero, allowLeadingZerosInDecimalPart, }?: IPrettifyNumberConfig) => string | null;
26
+ export declare const prettifyNumber: (number: BigNumberish, { minDecimalPlaces, maxDecimalPlaces, minDecimalSignificantDigits, decimalPlacesWhenZero, allowLeadingZerosInDecimalPart, groupSeparator, decimalSeparator, maxNrDigits, roundingMode, }?: IPrettifyNumberConfig) => string | null;
@@ -1,52 +1,76 @@
1
- import { BigNumber as m } from "../../../node_modules/.pnpm/bignumber.js@9.1.2/node_modules/bignumber.js/bignumber.js";
2
- import { isNumeric as C } from "./isNumeric.js";
3
- const s = {
1
+ import { BigNumber as u } from "../../../node_modules/.pnpm/bignumber.js@9.1.2/node_modules/bignumber.js/bignumber.js";
2
+ import { isNumeric as y } from "./isNumeric.js";
3
+ const N = {
4
4
  CURRENCY: {
5
5
  minDecimalPlaces: 2,
6
6
  maxDecimalPlaces: 10,
7
7
  minDecimalSignificantDigits: 2,
8
8
  decimalPlacesWhenZero: 2,
9
- allowLeadingZerosInDecimalPart: !0
9
+ allowLeadingZerosInDecimalPart: !0,
10
+ groupSeparator: ",",
11
+ decimalSeparator: "."
10
12
  },
11
13
  TOKEN: {
12
14
  minDecimalPlaces: 4,
13
15
  maxDecimalPlaces: 16,
14
16
  minDecimalSignificantDigits: 2,
15
17
  decimalPlacesWhenZero: 1,
16
- allowLeadingZerosInDecimalPart: !0
18
+ allowLeadingZerosInDecimalPart: !0,
19
+ groupSeparator: ",",
20
+ decimalSeparator: "."
17
21
  }
18
- }, y = (t, e) => D(t, {
19
- ...s.CURRENCY,
22
+ }, T = (r, e) => x(r, {
23
+ ...N.CURRENCY,
20
24
  ...e || {}
21
- }), O = (t, e) => D(t, {
22
- ...s.TOKEN,
25
+ }), d = (r, e) => x(r, {
26
+ ...N.TOKEN,
23
27
  ...e || {}
24
- }), D = (t, { minDecimalPlaces: e, maxDecimalPlaces: p, minDecimalSignificantDigits: u, decimalPlacesWhenZero: c, allowLeadingZerosInDecimalPart: l } = s.CURRENCY) => {
25
- if (!C(t))
28
+ }), F = {
29
+ groupSize: 3,
30
+ decimalSeparator: ".",
31
+ groupSeparator: ","
32
+ }, x = (r, { minDecimalPlaces: e, maxDecimalPlaces: O, minDecimalSignificantDigits: w, decimalPlacesWhenZero: p, allowLeadingZerosInDecimalPart: P, groupSeparator: h, decimalSeparator: s = F.decimalSeparator, maxNrDigits: g, roundingMode: c } = N.CURRENCY) => {
33
+ if (!y(r))
26
34
  return null;
27
- const i = new m(typeof t == "bigint" ? t.toString() : t);
28
- let r;
29
- const N = `0.${"".padStart(c - 1, "0")}1`;
30
- if (i.lt(new m(N)) && !l)
31
- r = `0.${"".padStart(c, "0")}`;
35
+ const a = {
36
+ ...F,
37
+ groupSeparator: h,
38
+ decimalSeparator: s
39
+ }, i = new u(typeof r == "bigint" ? r.toString() : r);
40
+ let o;
41
+ const C = `0.${"".padStart(p - 1, "0")}1`;
42
+ if (i.lt(new u(C)) && !P)
43
+ o = `0.${"".padStart(p, "0")}`;
32
44
  else if (i.gte(1))
33
- r = e !== 0 ? i.toFormat(e) : i.toFormat(e, m.ROUND_FLOOR);
45
+ o = e !== 0 ? c ? i.toFormat(e, c, a) : i.toFormat(e, a) : i.toFormat(e, u.ROUND_FLOOR, a);
34
46
  else {
35
- const o = i.toFormat(p).split(".")[1].match(/^0+/), P = l && o && o.length ? o[0].length : 0, h = Math.max(P + u, e);
36
- r = i.toFormat(h);
47
+ const l = (c ? i.toFormat(O, c, a) : i.toFormat(O, a)).split(s)[1].match(/^0+/), m = P && l && l.length ? l[0].length : 0, f = Math.max(m + w, e);
48
+ o = c ? i.toFormat(f, c, a) : i.toFormat(f, a);
37
49
  }
38
- const [d, g] = r.split(".");
39
- let n = d;
40
- if (g) {
41
- const a = g.replace(/0+$/, "");
42
- n += a ? `.${a}` : "";
50
+ const [D, R] = o.split(s);
51
+ let t = D;
52
+ if (R) {
53
+ const n = R.replace(/0+$/, "");
54
+ t += n ? `.${n}` : "";
43
55
  }
44
- const f = 1 + r.indexOf(".") + c;
45
- return n.length < f && (n = r.substring(0, f)), n;
56
+ const S = 1 + o.indexOf(".") + p;
57
+ if (t.length < S && (t = o.substring(0, S)), g) {
58
+ const n = t.replace(new RegExp(`[${h}${s}]`, "g"), "").length;
59
+ if (D.replace(new RegExp(`[${h}]`, "g"), "").length > g)
60
+ t = D;
61
+ else if (n > g) {
62
+ const l = n - g, m = t.indexOf(s);
63
+ if (m !== -1) {
64
+ const f = Math.max(0, t.length - m - 1 - l);
65
+ t = t.substring(0, m + 1 + f);
66
+ }
67
+ }
68
+ }
69
+ return t;
46
70
  };
47
71
  export {
48
- y as prettifyCurrencyNumber,
49
- D as prettifyNumber,
50
- s as prettifyNumberConfig,
51
- O as prettifyTokenNumber
72
+ T as prettifyCurrencyNumber,
73
+ x as prettifyNumber,
74
+ N as prettifyNumberConfig,
75
+ d as prettifyTokenNumber
52
76
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@argent/x-shared",
3
- "version": "1.57.0",
3
+ "version": "1.58.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/argentlabs/x-shared.git"
@@ -50,6 +50,7 @@
50
50
  "@semantic-release/git": "10.0.1",
51
51
  "@types/async-retry": "1.4.9",
52
52
  "@types/lodash-es": "4.17.12",
53
+ "@types/numeral": "2.0.5",
53
54
  "@types/ua-parser-js": "0.7.39",
54
55
  "@typescript-eslint/eslint-plugin": "8.18.0",
55
56
  "@typescript-eslint/parser": "8.18.0",
@@ -73,6 +74,7 @@
73
74
  "@starknet-io/types-js": "^0.7.7",
74
75
  "big-decimal-number": "npm:bignumber.js@^9.1.2",
75
76
  "micro-starknet": "^0.2.3",
77
+ "numeral": "2.0.6",
76
78
  "starknet": "6.21.1",
77
79
  "starknet4-deprecated": "npm:starknet@4.4.0",
78
80
  "starknet5": "npm:starknet@5.25.0"