@liberfi.io/utils 0.1.24 → 0.1.26

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 ADDED
@@ -0,0 +1,290 @@
1
+ # @liberfi.io/utils
2
+
3
+ Framework-agnostic utility library for the Liberfi React SDK monorepo. Provides number/currency formatting, chain metadata, HTTP helpers, date/time formatting, token registries, URL builders, and string utilities. Consumed by all UI and integration packages in the monorepo.
4
+
5
+ ## Design Philosophy
6
+
7
+ - **Pure functions** — All exports are stateless, side-effect-free functions (except `version` registration). No React, no DOM.
8
+ - **Tiered precision formatting** — Number formatters automatically select decimal places and abbreviation based on magnitude, matching financial UI conventions.
9
+ - **Single source of truth for chain data** — Chain slugs, colors, icons, and address validation live here so UI packages don't duplicate chain logic.
10
+ - **Minimal dependencies** — Only `bignumber.js` for precision math, `lodash-es` for common utilities, and `@solana/kit` for Solana address validation.
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ pnpm add @liberfi.io/utils
16
+ ```
17
+
18
+ Peer dependencies: none (all dependencies are direct).
19
+
20
+ ## API Reference
21
+
22
+ ### Number Formatting
23
+
24
+ #### `SafeBigNumber`
25
+
26
+ A `BigNumber` subclass that never throws on construction. Invalid/undefined values fall back to `0`.
27
+
28
+ ```typescript
29
+ new SafeBigNumber(value?: BigNumber.Value, base?: number)
30
+ ```
31
+
32
+ #### `isValidNumber(num: unknown): boolean`
33
+
34
+ Returns `true` if `num` is a finite number, numeric string, or `BigNumber`/`SafeBigNumber` instance.
35
+
36
+ #### `formatAmount(num, options?): string`
37
+
38
+ Format a raw token/asset amount (no currency symbol). Precision auto-selects by magnitude.
39
+
40
+ ```typescript
41
+ formatAmount(num: BigNumber.Value, options?: FormatAmountOptions): string
42
+ ```
43
+
44
+ | Option | Type | Default | Description |
45
+ | -------------------- | --------- | ------- | ------------------------------- |
46
+ | `showPlusGtThanZero` | `boolean` | `false` | Prefix positive values with "+" |
47
+
48
+ #### `formatAmountUSD(num, options?): string`
49
+
50
+ Format a USD amount with `$` prefix. Standard precision tiers.
51
+
52
+ #### `formatAmountUSDCompact(num, options?): string`
53
+
54
+ Compact USD formatting — more aggressive rounding, suited for space-constrained UIs.
55
+
56
+ #### `formatPriceUSD(num, options?): string`
57
+
58
+ Format a token price with `$` prefix. Supports high-precision and low-precision modes.
59
+
60
+ ```typescript
61
+ formatPriceUSD(num: BigNumber.Value, options?: FormatPriceOptions): string
62
+ ```
63
+
64
+ | Option | Type | Default | Description |
65
+ | --------------- | --------- | ------- | -------------------------------------- |
66
+ | `isHighPrecise` | `boolean` | `true` | Use high-precision mode (4 dp vs 2 dp) |
67
+
68
+ #### `formatPercent(num, options?): string`
69
+
70
+ Format a ratio as percentage (0.3 = 30%).
71
+
72
+ ```typescript
73
+ formatPercent(num: BigNumber.Value, options?: FormatPercentOptions): string
74
+ ```
75
+
76
+ | Option | Type | Default | Description |
77
+ | -------------------- | --------- | ------- | ------------------------------- |
78
+ | `showPlusGtThanZero` | `boolean` | `false` | Prefix positive values with "+" |
79
+ | `precision` | `number` | `2` | Decimal precision override |
80
+
81
+ ### Chain Utilities
82
+
83
+ #### `chainToNamespace(chain: Chain): ChainNamespace`
84
+
85
+ Returns `ChainNamespace.SOLANA` or `ChainNamespace.EVM` for a given chain.
86
+
87
+ #### `chainSlug(chainId: Chain): string | undefined`
88
+
89
+ Returns the lowercase slug (e.g. `"ethereum"`, `"solana"`).
90
+
91
+ #### `chainDisplayName(chainId: Chain): string`
92
+
93
+ Returns a display-friendly name. Uses abbreviation if available (e.g. `"ETH"`, `"BSC"`), otherwise title-cases the slug.
94
+
95
+ #### `chainColor(chainId: Chain): string | undefined`
96
+
97
+ Returns the brand hex color for a chain.
98
+
99
+ #### `chainIcon(chain: Chain | string): string | undefined`
100
+
101
+ Returns a llamao.fi icon URL for the chain.
102
+
103
+ #### `chainIdBySlug(slug: string): Chain | undefined`
104
+
105
+ Reverse lookup — resolves a slug or abbreviation to a `Chain` enum value. Case-insensitive.
106
+
107
+ #### `isValidEvmAddress(value: string): boolean`
108
+
109
+ Validates a `0x`-prefixed 40-hex-character EVM address.
110
+
111
+ #### `isValidSolanaAddress(value: string): boolean`
112
+
113
+ Validates a Solana base58 address using `@solana/kit`.
114
+
115
+ #### `isValidWalletAddress(chain: Chain | string, addr: string): boolean`
116
+
117
+ Dispatches to the correct validator based on the chain's namespace.
118
+
119
+ ### Date/Time Formatting
120
+
121
+ #### `formatAgeInSeconds(age: number, options?): string`
122
+
123
+ Formats elapsed time in seconds to a compact string (`"just now"`, `"45s"`, `"2m"`, `"3h"`, `"5d"`, `"1y"`).
124
+
125
+ #### `formatAge(age: number, options?): string`
126
+
127
+ Same as `formatAgeInSeconds` but accepts milliseconds.
128
+
129
+ ```typescript
130
+ interface FormatAgeOptions {
131
+ justNow?: string;
132
+ secondsAgo?: string; // use {n} placeholder
133
+ minutesAgo?: string;
134
+ hoursAgo?: string;
135
+ daysAgo?: string;
136
+ yearsAgo?: string;
137
+ }
138
+ ```
139
+
140
+ ### HTTP Helpers
141
+
142
+ #### `httpRequest<R>(url: string, options: RequestInit): Promise<R>`
143
+
144
+ Core HTTP function. Throws `ApiError` for 400 responses, `Error` for other failures.
145
+
146
+ #### `httpGet<R>(url, options?): Promise<R>`
147
+
148
+ #### `httpPost<R, P>(url, data, options?): Promise<R>`
149
+
150
+ #### `httpPut<R, P>(url, data, options?): Promise<R>`
151
+
152
+ #### `httpDelete<R>(url, options?): Promise<R>`
153
+
154
+ #### `httpMutate<R>(url, init): Promise<R>`
155
+
156
+ ### URL Builders
157
+
158
+ #### `txExplorerUrl(chainId: Chain, txHash: string): string | undefined`
159
+
160
+ Returns a block explorer URL for a transaction hash.
161
+
162
+ #### `accountExplorerUrl(chainId: Chain, account: string): string | undefined`
163
+
164
+ Returns a block explorer URL for an account/address.
165
+
166
+ #### `searchImageUrl(image: string): string`
167
+
168
+ Google Lens reverse image search URL.
169
+
170
+ #### `searchTwitterUrl(q: string): string`
171
+
172
+ X/Twitter search URL.
173
+
174
+ #### `twitterUserUrl(username: string): string`
175
+
176
+ #### `twitterTweetUrl(id: string): string`
177
+
178
+ ### String Utilities
179
+
180
+ #### `capitalize(str: string): string`
181
+
182
+ Capitalizes the first letter, lowercases the rest.
183
+
184
+ #### `truncateAddress(address: string, start?: number, end?: number): string`
185
+
186
+ Truncates a string with `...` in the middle. Defaults: `start=6`, `end=4`.
187
+
188
+ ### Symbol Formatting
189
+
190
+ #### `formatSymbol(symbol: string, formatString?: string): string`
191
+
192
+ Formats a trading pair symbol (`"PERP_BTC_USDT"`) using a template string with `type`, `base`, `quote` placeholders. Default format: `"base-type"`.
193
+
194
+ ### Token Protocols
195
+
196
+ #### `parseTokenProtocolFamily(chain: Chain, protocolFamily: string): TokenProtocol | undefined`
197
+
198
+ Parses a protocol family string to a known `TokenProtocol` (Solana only).
199
+
200
+ #### `formatTokenProtocolName(protocol: TokenProtocol): string`
201
+
202
+ Formats a protocol slug to display name (e.g. `"pump-amm"` → `"Pump Amm"`).
203
+
204
+ ### Token Registry
205
+
206
+ #### `getNativeToken(chain: Chain): PredefinedToken | undefined`
207
+
208
+ #### `getWrappedToken(chain: Chain): PredefinedToken | undefined`
209
+
210
+ #### `getStablecoins(chain: Chain): Record<string, PredefinedToken> | undefined`
211
+
212
+ #### `getCommonTokenAddresses(chain: Chain): string[]`
213
+
214
+ #### `getCommonTokenSymbolsMap(chain: Chain): Record<string, string>`
215
+
216
+ ### Types
217
+
218
+ - `FormatAmountOptions` — `{ showPlusGtThanZero: boolean }`
219
+ - `FormatPriceOptions` — `{ isHighPrecise: boolean }`
220
+ - `FormatPercentOptions` — `{ showPlusGtThanZero?: boolean; precision?: number }`
221
+ - `FormatAgeOptions` — i18n label overrides for age formatting
222
+ - `PredefinedToken` — `{ address: string; symbol: string; decimals: number }`
223
+ - `ChainPredefinedTokens` — `{ native, wrapped, stablecoins }`
224
+ - `ApiError` — Error subclass with `code: number`
225
+
226
+ ### Constants
227
+
228
+ - `SOLANA_TOKENS`, `ETHEREUM_TOKENS`, `BSC_TOKENS`, `ARBITRUM_TOKENS`, `OPTIMISM_TOKENS`, `AVALANCHE_TOKENS` — Per-chain token registries
229
+ - `CHAIN_TOKENS` — `Partial<Record<Chain, ChainPredefinedTokens>>`
230
+ - `version` — Package version string
231
+
232
+ ### Re-exported from lodash-es
233
+
234
+ `throttle`, `debounce`, `uniqBy`, `intersectionBy`, `keyBy`, `groupBy`, `mapKeys`, `mapValues`
235
+
236
+ ## Usage Examples
237
+
238
+ ### Number formatting
239
+
240
+ ```tsx
241
+ import {
242
+ formatAmount,
243
+ formatAmountUSD,
244
+ formatPriceUSD,
245
+ formatPercent,
246
+ } from "@liberfi.io/utils";
247
+
248
+ formatAmount(1_500_000); // "1.5M"
249
+ formatAmountUSD(42.678); // "$42.67"
250
+ formatPriceUSD(0.0000382); // "$0.0₄382"
251
+ formatPercent(0.3); // "30%"
252
+ formatPercent(-0.05, { showPlusGtThanZero: true }); // "-5%"
253
+ ```
254
+
255
+ ### Chain utilities
256
+
257
+ ```tsx
258
+ import { Chain } from "@liberfi.io/types";
259
+ import {
260
+ chainDisplayName,
261
+ chainIcon,
262
+ isValidWalletAddress,
263
+ } from "@liberfi.io/utils";
264
+
265
+ chainDisplayName(Chain.ETHEREUM); // "ETH"
266
+ chainIcon(Chain.SOLANA); // "https://icons.llamao.fi/icons/chains/rsz_solana.jpg"
267
+ isValidWalletAddress(
268
+ Chain.ETHEREUM,
269
+ "0x1234567890abcdef1234567890abcdef12345678",
270
+ ); // true
271
+ ```
272
+
273
+ ### Date formatting
274
+
275
+ ```tsx
276
+ import { formatAge } from "@liberfi.io/utils";
277
+
278
+ formatAge(120000); // "2m"
279
+ formatAge(120000, { minutesAgo: "{n} 分钟前" }); // "2 分钟前"
280
+ ```
281
+
282
+ ## Future Improvements
283
+
284
+ - Extract shared formatting logic in `number.ts` to reduce DRY violations across `formatAmount` / `formatAmountUSD` / `formatAmountUSDCompact`.
285
+ - Replace `any` defaults with `unknown` in `fetch.ts` generic type parameters.
286
+ - Remove catch-rethrow antipattern in `fetch.ts` error handling.
287
+ - Move `version.ts` window side effect to opt-in registration or provider initialization.
288
+ - Consolidate chain metadata (`chainSlugs`, `chainSlugAbbrs`, `chainColors`) into a single structured registry.
289
+ - Add grouping separators to `stringifyPercent` for large percentage values.
290
+ - Extend `ApiError` with HTTP status code and response body fields.
package/dist/index.d.mts CHANGED
@@ -9,7 +9,7 @@ declare global {
9
9
  };
10
10
  }
11
11
  }
12
- declare const _default: "0.1.24";
12
+ declare const _default: "0.1.26";
13
13
 
14
14
  /** Returns the chain namespace (EVM or SOLANA) for a given chain */
15
15
  declare function chainToNamespace(chain: Chain): ChainNamespace;
@@ -27,12 +27,7 @@ declare class ApiError extends Error {
27
27
  constructor(message: string, code: number);
28
28
  }
29
29
 
30
- declare const millisecondsToHMS: (milliseconds: number) => [number, number, number];
31
- declare const timestampToString: (timestamp: number | Date) => string;
32
- declare function subtractDaysFromCurrentDate(days: number, startDate?: Date): Date;
33
- declare function formatTimeAgo(date: number | string | Date | null | undefined): string;
34
- declare function secondsSince(timestamp: number | Date, now?: number | Date): number;
35
- interface FormatReadableTimeOptions {
30
+ interface FormatAgeOptions {
36
31
  justNow?: string;
37
32
  secondsAgo?: string;
38
33
  minutesAgo?: string;
@@ -41,94 +36,189 @@ interface FormatReadableTimeOptions {
41
36
  yearsAgo?: string;
42
37
  }
43
38
  /**
44
- * Formats a timestamp into a human-readable time ago string.
45
-
39
+ * Formats an age (elapsed time) given in **seconds** into a compact
40
+ * human-readable string like "3m", "2h", or "just now".
46
41
  *
47
- * @param timestamp - The timestamp (number) or Date object to format
48
- * @param options - Optional custom text translations
49
- * @returns Formatted time ago string
50
- */
51
- declare function formatReadableTime(timestamp: number | Date, options?: FormatReadableTimeOptions): string;
52
- /**
53
- * Formats an age in milliseconds into a human-readable time ago string.
54
- * @param timestamp Age in milliseconds
55
- * @param options Optional custom text translations
56
- * @returns Formatted time ago string
42
+ * Use this when you already have the elapsed time in seconds (e.g. from
43
+ * a server-provided `age` field). If you have milliseconds instead, use
44
+ * {@link formatAge}.
45
+ *
46
+ * @example
47
+ * formatAgeInSeconds(5) // "just now" (< 10s)
48
+ * formatAgeInSeconds(45) // "45s"
49
+ * formatAgeInSeconds(120) // "2m"
50
+ * formatAgeInSeconds(7200) // "2h"
51
+ * formatAgeInSeconds(172800) // "2d"
52
+ * formatAgeInSeconds(63072000) // "2y"
53
+ *
54
+ * @example Custom labels (e.g. for i18n)
55
+ * formatAgeInSeconds(120, { minutesAgo: "{n} minutes ago" }) // "2 minutes ago"
57
56
  */
58
- declare function formatAge(age: number, options?: FormatReadableTimeOptions): string;
57
+ declare function formatAgeInSeconds(age: number, options?: FormatAgeOptions): string;
59
58
  /**
60
- * Formats an age in seconds into a human-readable time ago string.
61
- * @param timestamp Age in seconds
62
- * @param options Optional custom text translations
63
- * @returns Formatted time ago string
64
- * @examples
65
- * formatAgeInSeconds(0) // "just now"
66
- * formatAgeInSeconds(10) // "10s"
67
- * formatAgeInSeconds(60) // "1m"
68
- * formatAgeInSeconds(3600) // "1h"
69
- * formatAgeInSeconds(86400) // "1d"
70
- * formatAgeInSeconds(31536000) // "1y"
59
+ * Formats an age (elapsed time) given in **milliseconds** into a compact
60
+ * human-readable string. Internally converts to seconds and delegates to
61
+ * {@link formatAgeInSeconds}.
62
+ *
63
+ * This is the primary function used across UI components to display how
64
+ * long ago something happened (e.g. a trade, a tweet, a channel update).
65
+ *
66
+ * @example
67
+ * formatAge(3000) // "just now" (3 s < 10 s threshold)
68
+ * formatAge(45000) // "45s"
69
+ * formatAge(120000) // "2m"
70
+ * formatAge(7200000) // "2h"
71
+ *
72
+ * @example Custom labels (e.g. for i18n)
73
+ * formatAge(120000, { minutesAgo: "{n} 分钟前" }) // "2 分钟前"
71
74
  */
72
- declare function formatAgeInSeconds(age: number, options?: FormatReadableTimeOptions): string;
75
+ declare function formatAge(age: number, options?: FormatAgeOptions): string;
73
76
 
74
- declare function request<R = any>(url: string, options: RequestInit): Promise<R>;
75
- declare function get<R = any>(url: string, options?: RequestInit): Promise<R>;
76
- declare function post<R = any, P = any>(url: string, data: P, options?: Omit<RequestInit, "method">): Promise<R>;
77
- declare function put<R = any, P = any>(url: string, data: P, options?: Omit<RequestInit, "method">): Promise<R>;
78
- declare function del<R = any>(url: string, options?: Omit<RequestInit, "method">): Promise<R>;
79
- declare function mutate<R = any>(url: string, init: RequestInit): Promise<R>;
77
+ declare function httpRequest<R = any>(url: string, options: RequestInit): Promise<R>;
78
+ declare function httpGet<R = any>(url: string, options?: RequestInit): Promise<R>;
79
+ declare function httpPost<R = any, P = any>(url: string, data: P, options?: Omit<RequestInit, "method">): Promise<R>;
80
+ declare function httpPut<R = any, P = any>(url: string, data: P, options?: Omit<RequestInit, "method">): Promise<R>;
81
+ declare function httpDelete<R = any>(url: string, options?: Omit<RequestInit, "method">): Promise<R>;
82
+ declare function httpMutate<R = any>(url: string, init: RequestInit): Promise<R>;
80
83
 
84
+ /**
85
+ * A `BigNumber` subclass that never throws on construction.
86
+ * Invalid / undefined values fall back to `0`.
87
+ */
81
88
  declare class SafeBigNumber extends BigNumber {
82
89
  constructor(num?: BigNumber.Value, base?: number);
83
90
  }
84
91
  declare const isValidNumber: (num: unknown) => boolean;
85
- declare const canConvertToNumber: (num: unknown) => boolean;
86
- declare const isValidTimeframe: (timeframe?: string) => boolean;
87
92
  type FormatAmountOptions = {
88
93
  showPlusGtThanZero: boolean;
89
94
  };
95
+ /**
96
+ * Format a raw token / asset amount (no currency symbol).
97
+ *
98
+ * Precision tiers (ROUND_DOWN):
99
+ * | Range | Format | Example input → output |
100
+ * |---------------|-------------------------|------------------------------|
101
+ * | < 0.001 | 5 decimal places | 0.0001234 → "0.00012" |
102
+ * | < 1 | 3 decimal places | 0.56789 → "0.567" |
103
+ * | < 100 | 2 decimal places | 42.678 → "42.67" |
104
+ * | < 100 000 | grouped, 2 dp | 12345.6 → "12,345.60" |
105
+ * | ≥ 100 000 | abbreviated (K/M/B/T) | 1_500_000 → "1.5M" |
106
+ *
107
+ * @param num - The numeric value.
108
+ * @param options.showPlusGtThanZero - Prefix positive values with "+".
109
+ */
90
110
  declare const formatAmount: (num?: BigNumber.Value, options?: FormatAmountOptions) => string;
91
- declare const formatAmount2: (num?: BigNumber.Value, options?: FormatAmountOptions) => string;
92
- declare const formatAmount3: (num?: BigNumber.Value, options?: FormatAmountOptions) => string;
111
+ /**
112
+ * Format a USD dollar amount with "$" prefix (standard precision).
113
+ *
114
+ * Precision tiers (ROUND_DOWN):
115
+ * | Range | Format | Example input → output |
116
+ * |---------------|-------------------------|------------------------------|
117
+ * | < 0.001 | "$0" | 0.00001 → "$0" |
118
+ * | < 1 | 3 decimal places | 0.56789 → "$0.567" |
119
+ * | < 100 | 2 decimal places | 42.678 → "$42.67" |
120
+ * | < 10 000 | grouped, 2 dp | 1234.5 → "$1,234.50" |
121
+ * | ≥ 10 000 | abbreviated (K/M/B/T) | 1_500_000 → "$1.5M" |
122
+ *
123
+ * Use this for standard financial displays (volume, market cap, liquidity).
124
+ *
125
+ * @param num - The numeric value.
126
+ * @param options.showPlusGtThanZero - Prefix positive values with "+".
127
+ */
93
128
  declare const formatAmountUSD: (num?: BigNumber.Value, options?: FormatAmountOptions) => string;
94
- declare const formatAmountUSD2: (num?: BigNumber.Value, options?: FormatAmountOptions) => string;
95
- declare const formatAmountUSD3: (num?: BigNumber.Value, options?: FormatAmountOptions) => string;
96
- declare const formatAmountUSD4: (num?: BigNumber.Value, options?: FormatAmountOptions) => string;
97
- declare const formatAmountUSD5: (num?: BigNumber.Value, options?: FormatAmountOptions) => string;
129
+ /**
130
+ * Format a USD dollar amount with "$" prefix — **compact** variant.
131
+ *
132
+ * Compared to {@link formatAmountUSD}, this variant is more aggressively
133
+ * rounded and suited for space-constrained UIs (cards, badges, list items):
134
+ *
135
+ * | Range | Format | Example input → output |
136
+ * |---------------|-------------------------|------------------------------|
137
+ * | < 0.001 | "$0" | 0.00001 → "$0" |
138
+ * | < 1 | 3 decimal places | 0.56789 → "$0.567" |
139
+ * | < 100 | 2 decimal places | 42.678 → "$42.67" |
140
+ * | < 1 000 | 0 decimal places | 567.89 → "$567" |
141
+ * | ≥ 1 000 | abbreviated, 0 dp, | 15 678 → "$15.6K" |
142
+ * | | rounded to nearest 100 | 1 234 567 → "$1.2M" |
143
+ *
144
+ * Key differences from `formatAmountUSD`:
145
+ * - 100–1 000: shows 0 dp instead of 2 dp
146
+ * - ≥ 1 000: abbreviates earlier (1K vs 10K) with 0 precision, rounded to 100s
147
+ *
148
+ * @param num - The numeric value.
149
+ * @param options.showPlusGtThanZero - Prefix positive values with "+".
150
+ */
151
+ declare const formatAmountUSDCompact: (num?: BigNumber.Value, options?: FormatAmountOptions) => string;
98
152
  type FormatPriceOptions = {
99
153
  isHighPrecise: boolean;
100
154
  };
101
- declare const formatPrice: (num?: BigNumber.Value, options?: FormatPriceOptions) => string;
155
+ /**
156
+ * Format a token price with "$" prefix.
157
+ *
158
+ * Two precision modes controlled by `isHighPrecise` (default: `true`):
159
+ *
160
+ * | Range | High precision (default) | Low precision |
161
+ * |---------------|-------------------------------|------------------------------|
162
+ * | < 0.0001 | subscript notation, 4 sig | subscript notation, 2 sig |
163
+ * | | 0.0000382 → "$0.0₄382" | 0.0000382 → "$0.0₄38" |
164
+ * | < 1 | 4 dp, grouped | 2 significant dp |
165
+ * | | 0.12345 → "$0.1234" | 0.12345 → "$0.12" |
166
+ * | < 10 000 | 4 dp, grouped | 2 dp, grouped |
167
+ * | | 1234.567 → "$1,234.5670" | 1234.567 → "$1,234.56" |
168
+ * | < 100 000 | 2 dp, grouped | 2 dp, grouped |
169
+ * | ≥ 100 000 | abbreviated (K/M/B/T) | abbreviated (K/M/B/T) |
170
+ *
171
+ * @param num - The price value.
172
+ * @param options.isHighPrecise - Use high-precision mode (default: true).
173
+ */
102
174
  declare const formatPriceUSD: (num?: BigNumber.Value, options?: FormatPriceOptions) => string;
103
175
  type FormatPercentOptions = {
104
176
  showPlusGtThanZero?: boolean;
105
177
  precision?: number;
106
178
  };
107
179
  /**
108
- * Format a number as a percentage.
109
- * @param num - The number to format, 0.3 means 30%.
110
- * @param options - The options to format the number.
111
- * @param options.showPlusGtThanZero - Whether to show the plus sign if the number is greater than zero.
112
- * @param options.precision - The precision to format the number.
113
- * @returns
180
+ * Format a ratio as a percentage string.
181
+ *
182
+ * The input is a **ratio** (0.3 = 30%, 1.5 = 150%).
183
+ *
184
+ * | Input range | Output example |
185
+ * |---------------|-----------------------------------------|
186
+ * | < 0.0001 | "0%" |
187
+ * | < 100 | "56.79%" (2 dp by default) |
188
+ * | < 1000 | "15,000.5%" (1 dp by default) |
189
+ * | ≥ 1000 | "> 99,999%" |
190
+ *
191
+ * @param num - The ratio value (0.3 means 30%).
192
+ * @param options.showPlusGtThanZero - Prefix positive values with "+".
193
+ * @param options.precision - Decimal precision override.
114
194
  */
115
195
  declare const formatPercent: (num?: BigNumber.Value, options?: FormatPercentOptions) => string;
116
- type FormatMultiplierOptions = {
117
- showPlusGtThanZero?: boolean;
118
- };
119
- declare const formatMultiplier: (num?: BigNumber.Value, options?: FormatMultiplierOptions) => string;
120
- declare const formatCount: (num?: BigNumber.Value) => string | number;
121
- declare const formatCount2: (num?: BigNumber.Value) => string | number;
122
- declare const formatCount3: (num?: BigNumber.Value) => string;
123
- declare const displayCount4: (num?: BigNumber.Value) => string;
124
- declare const displayCount3: (num?: BigNumber.Value) => string | number;
125
196
 
126
- declare function capitalizeString(str: string): string;
127
- declare function camelCaseToSnakeCase(str: string): string;
128
- declare const findLongestCommonSubString: (str1: string, str2: string) => number;
129
- declare function isHex(value: string): boolean;
130
- declare function isHexString(value: string): boolean;
131
- declare function shortAddress(address: string, start?: number, end?: number): string;
197
+ /**
198
+ * Capitalize the first letter of a string, lowercasing the rest.
199
+ *
200
+ * @example
201
+ * capitalize("hello") // "Hello"
202
+ * capitalize("hELLO") // "Hello"
203
+ * capitalize("solana") // "Solana"
204
+ */
205
+ declare function capitalize(str: string): string;
206
+ /**
207
+ * Truncate an address (or any string) to show the first `start` and last `end`
208
+ * characters with "..." in between.
209
+ *
210
+ * @param address - The full address string.
211
+ * @param start - Number of characters to keep from the beginning (default 6).
212
+ * @param end - Number of characters to keep from the end (default 4).
213
+ *
214
+ * @example
215
+ * truncateAddress("0x1234567890abcdef1234567890abcdef12345678")
216
+ * // "0x1234...5678"
217
+ *
218
+ * truncateAddress("0x1234567890abcdef1234567890abcdef12345678", 4, 4)
219
+ * // "0x12...5678"
220
+ */
221
+ declare function truncateAddress(address: string, start?: number, end?: number): string;
132
222
 
133
223
  /**
134
224
  * Format trading pair symbol *
@@ -182,15 +272,10 @@ declare function getCommonTokenAddresses(chain: Chain): string[];
182
272
  declare function getCommonTokenSymbolsMap(chain: Chain): Record<string, string>;
183
273
 
184
274
  declare function txExplorerUrl(chainId: Chain, txHash: string): string | undefined;
185
- declare const accountExplorerUrl: (chainId: Chain, account: string) => string | undefined;
275
+ declare function accountExplorerUrl(chainId: Chain, account: string): string | undefined;
186
276
  declare function searchImageUrl(image: string): string;
187
277
  declare function searchTwitterUrl(q: string): string;
188
278
  declare function twitterUserUrl(username: string): string;
189
279
  declare function twitterTweetUrl(id: string): string;
190
- declare function twitterMediaUrl(id: string): string;
191
-
192
- declare const windowGuard: (cb: Function) => void;
193
- declare const getGlobalObject: () => typeof globalThis;
194
- declare const getTimestamp: () => number;
195
280
 
196
- export { ARBITRUM_TOKENS, AVALANCHE_TOKENS, ApiError, BSC_TOKENS, CHAIN_TOKENS, type ChainPredefinedTokens, ETHEREUM_TOKENS, type FormatAmountOptions, type FormatMultiplierOptions, type FormatPercentOptions, type FormatPriceOptions, type FormatReadableTimeOptions, OPTIMISM_TOKENS, type PredefinedToken, SOLANA_TOKENS, SafeBigNumber, accountExplorerUrl, camelCaseToSnakeCase, canConvertToNumber, capitalizeString, chainColor, chainDisplayName, chainIcon, chainIdBySlug, chainSlug, chainToNamespace, del, displayCount3, displayCount4, findLongestCommonSubString, formatAge, formatAgeInSeconds, formatAmount, formatAmount2, formatAmount3, formatAmountUSD, formatAmountUSD2, formatAmountUSD3, formatAmountUSD4, formatAmountUSD5, formatCount, formatCount2, formatCount3, formatMultiplier, formatPercent, formatPrice, formatPriceUSD, formatReadableTime, formatSymbol, formatTimeAgo, formatTokenProtocolName, get, getCommonTokenAddresses, getCommonTokenSymbolsMap, getGlobalObject, getNativeToken, getStablecoins, getTimestamp, getWrappedToken, isHex, isHexString, isValidEvmAddress, isValidNumber, isValidSolanaAddress, isValidTimeframe, isValidWalletAddress, millisecondsToHMS, mutate, parseTokenProtocolFamily, post, put, request, searchImageUrl, searchTwitterUrl, secondsSince, shortAddress, subtractDaysFromCurrentDate, timestampToString, twitterMediaUrl, twitterTweetUrl, twitterUserUrl, txExplorerUrl, _default as version, windowGuard };
281
+ export { ARBITRUM_TOKENS, AVALANCHE_TOKENS, ApiError, BSC_TOKENS, CHAIN_TOKENS, type ChainPredefinedTokens, ETHEREUM_TOKENS, type FormatAgeOptions, type FormatAmountOptions, type FormatPercentOptions, type FormatPriceOptions, OPTIMISM_TOKENS, type PredefinedToken, SOLANA_TOKENS, SafeBigNumber, accountExplorerUrl, capitalize, chainColor, chainDisplayName, chainIcon, chainIdBySlug, chainSlug, chainToNamespace, formatAge, formatAgeInSeconds, formatAmount, formatAmountUSD, formatAmountUSDCompact, formatPercent, formatPriceUSD, formatSymbol, formatTokenProtocolName, getCommonTokenAddresses, getCommonTokenSymbolsMap, getNativeToken, getStablecoins, getWrappedToken, httpDelete, httpGet, httpMutate, httpPost, httpPut, httpRequest, isValidEvmAddress, isValidNumber, isValidSolanaAddress, isValidWalletAddress, parseTokenProtocolFamily, searchImageUrl, searchTwitterUrl, truncateAddress, twitterTweetUrl, twitterUserUrl, txExplorerUrl, _default as version };