@adriangalilea/utils 2.25.1 → 2.27.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.
- package/README.md +17 -12
- package/dist/bot/text.d.ts +23 -0
- package/dist/bot/text.d.ts.map +1 -0
- package/dist/bot/text.js +40 -0
- package/dist/bot/text.js.map +1 -0
- package/dist/bot/update-identity.d.ts +19 -0
- package/dist/bot/update-identity.d.ts.map +1 -0
- package/dist/bot/update-identity.js +92 -0
- package/dist/bot/update-identity.js.map +1 -0
- package/dist/bot/worker.d.ts +62 -0
- package/dist/bot/worker.d.ts.map +1 -1
- package/dist/bot/worker.js +181 -0
- package/dist/bot/worker.js.map +1 -1
- package/dist/universal/currency/classify.d.ts +7 -0
- package/dist/universal/currency/classify.d.ts.map +1 -0
- package/dist/universal/currency/classify.js +147 -0
- package/dist/universal/currency/classify.js.map +1 -0
- package/dist/universal/currency/decimals.d.ts +2 -0
- package/dist/universal/currency/decimals.d.ts.map +1 -0
- package/dist/universal/currency/decimals.js +93 -0
- package/dist/universal/currency/decimals.js.map +1 -0
- package/dist/universal/currency/index.d.ts +12 -57
- package/dist/universal/currency/index.d.ts.map +1 -1
- package/dist/universal/currency/index.js +27 -317
- package/dist/universal/currency/index.js.map +1 -1
- package/dist/universal/currency/money.d.ts +12 -0
- package/dist/universal/currency/money.d.ts.map +1 -0
- package/dist/universal/currency/money.js +40 -0
- package/dist/universal/currency/money.js.map +1 -0
- package/dist/universal/currency/percent.d.ts +7 -0
- package/dist/universal/currency/percent.d.ts.map +1 -0
- package/dist/universal/currency/percent.js +32 -0
- package/dist/universal/currency/percent.js.map +1 -0
- package/dist/universal/currency/symbols.d.ts +32 -0
- package/dist/universal/currency/symbols.d.ts.map +1 -0
- package/dist/universal/currency/symbols.js +36 -0
- package/dist/universal/currency/symbols.js.map +1 -0
- package/dist/universal/currency/usd.d.ts +23 -0
- package/dist/universal/currency/usd.d.ts.map +1 -0
- package/dist/universal/currency/usd.js +54 -0
- package/dist/universal/currency/usd.js.map +1 -0
- package/dist/universal/format.d.ts +17 -29
- package/dist/universal/format.d.ts.map +1 -1
- package/dist/universal/format.js +28 -54
- package/dist/universal/format.js.map +1 -1
- package/package.json +11 -1
|
@@ -1,320 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
BUSD: "$",
|
|
29
|
-
};
|
|
30
|
-
export function getSymbol(code) {
|
|
31
|
-
return CurrencySymbols[code] || code;
|
|
32
|
-
}
|
|
33
|
-
export function getOptimalDecimals(value, currencyCode) {
|
|
34
|
-
if (value === 0) {
|
|
35
|
-
return isCrypto(currencyCode) ? 8 : 2;
|
|
36
|
-
}
|
|
37
|
-
const absValue = Math.abs(value);
|
|
38
|
-
switch (currencyCode) {
|
|
39
|
-
case "BTC":
|
|
40
|
-
case "XBT":
|
|
41
|
-
if (absValue < 0.00001)
|
|
42
|
-
return 10;
|
|
43
|
-
else if (absValue < 0.0001)
|
|
44
|
-
return 9;
|
|
45
|
-
else if (absValue < 0.001)
|
|
46
|
-
return 8;
|
|
47
|
-
else if (absValue < 0.01)
|
|
48
|
-
return 7;
|
|
49
|
-
else if (absValue < 0.1)
|
|
50
|
-
return 6;
|
|
51
|
-
else if (absValue < 1)
|
|
52
|
-
return 5;
|
|
53
|
-
else
|
|
54
|
-
return 4;
|
|
55
|
-
case "ETH":
|
|
56
|
-
if (absValue < 0.001)
|
|
57
|
-
return 8;
|
|
58
|
-
else if (absValue < 0.01)
|
|
59
|
-
return 7;
|
|
60
|
-
else if (absValue < 0.1)
|
|
61
|
-
return 6;
|
|
62
|
-
else if (absValue < 1)
|
|
63
|
-
return 5;
|
|
64
|
-
else
|
|
65
|
-
return 4;
|
|
66
|
-
case "USD":
|
|
67
|
-
case "USDT":
|
|
68
|
-
case "USDC":
|
|
69
|
-
case "DAI":
|
|
70
|
-
case "BUSD":
|
|
71
|
-
return usdDecimals(value);
|
|
72
|
-
case "EUR":
|
|
73
|
-
case "GBP":
|
|
74
|
-
case "CAD":
|
|
75
|
-
case "AUD":
|
|
76
|
-
case "CHF":
|
|
77
|
-
if (absValue < 0.01)
|
|
78
|
-
return 4;
|
|
79
|
-
else if (absValue < 1000)
|
|
80
|
-
return 2;
|
|
81
|
-
else
|
|
82
|
-
return 0;
|
|
83
|
-
case "JPY":
|
|
84
|
-
case "KRW":
|
|
85
|
-
if (absValue < 1)
|
|
86
|
-
return 2;
|
|
87
|
-
else
|
|
88
|
-
return 0;
|
|
89
|
-
}
|
|
90
|
-
if (isCrypto(currencyCode)) {
|
|
91
|
-
if (absValue < 0.00001)
|
|
92
|
-
return sigDecimals(absValue);
|
|
93
|
-
else if (absValue < 0.0001)
|
|
94
|
-
return 6;
|
|
95
|
-
else if (absValue < 0.001)
|
|
96
|
-
return 5;
|
|
97
|
-
else if (absValue < 0.01)
|
|
98
|
-
return 4;
|
|
99
|
-
else if (absValue < 0.1)
|
|
100
|
-
return 3;
|
|
101
|
-
else if (absValue < 1)
|
|
102
|
-
return 3;
|
|
103
|
-
else
|
|
104
|
-
return 2;
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
if (absValue < 0.01)
|
|
108
|
-
return sigDecimals(absValue);
|
|
109
|
-
else if (absValue < 0.1)
|
|
110
|
-
return 3;
|
|
111
|
-
else if (absValue < 1000)
|
|
112
|
-
return 2;
|
|
113
|
-
else
|
|
114
|
-
return 0;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
import { sigDecimals, usd, usdDecimals, usdIntlOptions } from "../format.js";
|
|
118
|
-
import { isCryptoSymbol } from "./crypto-symbols.js";
|
|
119
|
-
// Alternative ticker mappings (some exchanges use different symbols)
|
|
120
|
-
const cryptoAlternatives = {
|
|
121
|
-
XBT: "BTC", // BitMEX and some others use XBT for Bitcoin
|
|
122
|
-
IOTA: "MIOTA", // IOTA vs MIOTA
|
|
123
|
-
STR: "XLM", // Stellar old ticker
|
|
124
|
-
BCHABC: "BCH", // Bitcoin Cash ABC
|
|
125
|
-
BCHSV: "BSV", // Bitcoin SV
|
|
126
|
-
DRK: "DASH", // Darkcoin old name
|
|
127
|
-
XRB: "NANO", // RaiBlocks old name
|
|
128
|
-
ANT: "ANT", // Could be Aragon
|
|
129
|
-
BCC: "BCH", // Bittrex used BCC for Bitcoin Cash
|
|
130
|
-
MIOTA: "IOTA", // Some use MIOTA
|
|
131
|
-
YOYOW: "YOYOW", // Various formats
|
|
132
|
-
IOTX: "IOTX", // IoTeX
|
|
133
|
-
QSH: "QASH", // QASH variations
|
|
134
|
-
YOYO: "YOYOW", // YOYOW variations
|
|
135
|
-
ETHOS: "BQX", // Ethos old ticker
|
|
136
|
-
REP: "REP", // Augur variations
|
|
137
|
-
REPV2: "REP", // Augur v2
|
|
138
|
-
USDt: "USDT", // Case variations
|
|
139
|
-
"USDT.e": "USDT", // Avalanche USDT
|
|
140
|
-
"USDC.e": "USDC", // Avalanche USDC
|
|
141
|
-
"WBTC.e": "WBTC", // Avalanche WBTC
|
|
142
|
-
"DAI.e": "DAI", // Avalanche DAI
|
|
143
|
-
"BTC.b": "BTC", // Avalanche BTC
|
|
144
|
-
BETH: "WBETH", // Binance ETH
|
|
145
|
-
STETH: "STETH", // Lido staked ETH
|
|
146
|
-
WSTETH: "WSTETH", // Wrapped stETH
|
|
147
|
-
};
|
|
148
|
-
// Build reverse mapping for normalization (alternative -> normalized)
|
|
149
|
-
const symbolReverseMap = new Map();
|
|
150
|
-
for (const [alternative, normalized] of Object.entries(cryptoAlternatives)) {
|
|
151
|
-
// Only map if it's actually an alternative, not the same
|
|
152
|
-
if (alternative !== normalized) {
|
|
153
|
-
symbolReverseMap.set(alternative.toUpperCase(), normalized);
|
|
154
|
-
symbolReverseMap.set(alternative.toLowerCase(), normalized);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
export function normalize(symbol) {
|
|
158
|
-
const upperSymbol = symbol.toUpperCase();
|
|
159
|
-
// Check if it's a known alternative
|
|
160
|
-
if (cryptoAlternatives[upperSymbol]) {
|
|
161
|
-
return cryptoAlternatives[upperSymbol];
|
|
162
|
-
}
|
|
163
|
-
// Check reverse mapping
|
|
164
|
-
const normalized = symbolReverseMap.get(upperSymbol) ||
|
|
165
|
-
symbolReverseMap.get(symbol.toLowerCase());
|
|
166
|
-
if (normalized) {
|
|
167
|
-
return normalized;
|
|
168
|
-
}
|
|
169
|
-
// Handle wrapped/bridged tokens
|
|
170
|
-
const unwrapped = upperSymbol
|
|
171
|
-
.replace(/^W/, "") // Remove W prefix (WBTC -> BTC)
|
|
172
|
-
.replace(/\.E$/, "") // Remove .e suffix (USDT.e -> USDT)
|
|
173
|
-
.replace(/\.B$/, ""); // Remove .b suffix (BTC.b -> BTC)
|
|
174
|
-
if (unwrapped !== upperSymbol && cryptoAlternatives[unwrapped]) {
|
|
175
|
-
return cryptoAlternatives[unwrapped];
|
|
176
|
-
}
|
|
177
|
-
return upperSymbol;
|
|
178
|
-
}
|
|
179
|
-
export function areEquivalent(symbol1, symbol2) {
|
|
180
|
-
return normalize(symbol1) === normalize(symbol2);
|
|
181
|
-
}
|
|
182
|
-
export function getVariations(symbol) {
|
|
183
|
-
const normalized = normalize(symbol);
|
|
184
|
-
const variations = new Set([normalized]);
|
|
185
|
-
// Add all known alternatives
|
|
186
|
-
for (const [key, value] of Object.entries(cryptoAlternatives)) {
|
|
187
|
-
if (value === normalized || key === normalized) {
|
|
188
|
-
variations.add(key);
|
|
189
|
-
variations.add(value);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return Array.from(variations);
|
|
193
|
-
}
|
|
194
|
-
export function isCrypto(code) {
|
|
195
|
-
const upperCode = code.toUpperCase();
|
|
196
|
-
// Check if it's a known alternative
|
|
197
|
-
if (cryptoAlternatives[upperCode]) {
|
|
198
|
-
return isCryptoSymbol(cryptoAlternatives[upperCode]);
|
|
199
|
-
}
|
|
200
|
-
// Check if it's a wrapped or bridged token (common patterns)
|
|
201
|
-
const unwrappedCode = upperCode
|
|
202
|
-
.replace(/^W/, "") // Remove W prefix (WBTC -> BTC)
|
|
203
|
-
.replace(/\.E$/, "") // Remove .e suffix (USDT.e -> USDT)
|
|
204
|
-
.replace(/\.B$/, ""); // Remove .b suffix (BTC.b -> BTC)
|
|
205
|
-
if (unwrappedCode !== upperCode) {
|
|
206
|
-
return isCryptoSymbol(unwrappedCode);
|
|
207
|
-
}
|
|
208
|
-
return isCryptoSymbol(upperCode);
|
|
209
|
-
}
|
|
210
|
-
export function isStablecoin(code) {
|
|
211
|
-
const stablecoins = new Set([
|
|
212
|
-
"USDT",
|
|
213
|
-
"USDC",
|
|
214
|
-
"DAI",
|
|
215
|
-
"BUSD",
|
|
216
|
-
"UST",
|
|
217
|
-
"TUSD",
|
|
218
|
-
"USDP",
|
|
219
|
-
"GUSD",
|
|
220
|
-
"FRAX",
|
|
221
|
-
"LUSD",
|
|
222
|
-
]);
|
|
223
|
-
return stablecoins.has(code);
|
|
224
|
-
}
|
|
225
|
-
export function isFiat(code) {
|
|
226
|
-
const fiats = new Set([
|
|
227
|
-
"USD",
|
|
228
|
-
"EUR",
|
|
229
|
-
"GBP",
|
|
230
|
-
"JPY",
|
|
231
|
-
"CNY",
|
|
232
|
-
"CAD",
|
|
233
|
-
"AUD",
|
|
234
|
-
"CHF",
|
|
235
|
-
"HKD",
|
|
236
|
-
"SGD",
|
|
237
|
-
"NZD",
|
|
238
|
-
"KRW",
|
|
239
|
-
"SEK",
|
|
240
|
-
"NOK",
|
|
241
|
-
"DKK",
|
|
242
|
-
"PLN",
|
|
243
|
-
"THB",
|
|
244
|
-
"INR",
|
|
245
|
-
"RUB",
|
|
246
|
-
"TRY",
|
|
247
|
-
"BRL",
|
|
248
|
-
"MXN",
|
|
249
|
-
"ARS",
|
|
250
|
-
"CLP",
|
|
251
|
-
"COP",
|
|
252
|
-
"PEN",
|
|
253
|
-
"UYU",
|
|
254
|
-
"ZAR",
|
|
255
|
-
"NGN",
|
|
256
|
-
"KES",
|
|
257
|
-
]);
|
|
258
|
-
return fiats.has(code);
|
|
259
|
-
}
|
|
260
|
-
export function percentageOf(value, total) {
|
|
261
|
-
if (total === 0)
|
|
262
|
-
return 0;
|
|
263
|
-
return (value / total) * 100;
|
|
264
|
-
}
|
|
265
|
-
export function percentageChange(oldValue, newValue) {
|
|
266
|
-
if (oldValue === 0) {
|
|
267
|
-
if (newValue === 0)
|
|
268
|
-
return 0;
|
|
269
|
-
return newValue > 0 ? 100 : -100;
|
|
270
|
-
}
|
|
271
|
-
return ((newValue - oldValue) / Math.abs(oldValue)) * 100;
|
|
272
|
-
}
|
|
273
|
-
export function percentageDiff(a, b) {
|
|
274
|
-
if (a === 0 && b === 0)
|
|
275
|
-
return 0;
|
|
276
|
-
const avg = (Math.abs(a) + Math.abs(b)) / 2;
|
|
277
|
-
if (avg === 0)
|
|
278
|
-
return 0;
|
|
279
|
-
return (Math.abs(a - b) / avg) * 100;
|
|
280
|
-
}
|
|
281
|
-
export function basisPointsToPercent(bps) {
|
|
282
|
-
return bps / 100.0;
|
|
283
|
-
}
|
|
284
|
-
export function percentToBasisPoints(percent) {
|
|
285
|
-
return Math.round(percent * 100);
|
|
286
|
-
}
|
|
287
|
-
export function formatBasisPoints(bps) {
|
|
288
|
-
return `${bps} bps`;
|
|
289
|
-
}
|
|
290
|
-
// usd/usdIntlOptions live in ../format (dataset-free — see the note there);
|
|
291
|
-
// re-exported here so `currency.usd` and the /currency import path keep working.
|
|
292
|
-
export { usd, usdIntlOptions };
|
|
293
|
-
/** Bitcoin with optimal decimals: 0.00001234 ₿ */
|
|
294
|
-
export function btc(value) {
|
|
295
|
-
return `${value.toFixed(getOptimalDecimals(value, "BTC"))} ₿`;
|
|
296
|
-
}
|
|
297
|
-
/** Ethereum with optimal decimals: 0.123 Ξ */
|
|
298
|
-
export function eth(value) {
|
|
299
|
-
return `${value.toFixed(getOptimalDecimals(value, "ETH"))} Ξ`;
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Format a value in any currency: symbol before for fiat/stablecoins
|
|
303
|
-
* (`$12.34`), after for crypto (`0.5 ₿`), optimal decimals + thousands
|
|
304
|
-
* grouping either way (en-pinned — SSR-hydration-safe).
|
|
305
|
-
*/
|
|
306
|
-
export function money(value, currencyCode) {
|
|
307
|
-
const decimals = getOptimalDecimals(value, currencyCode);
|
|
308
|
-
const symbol = getSymbol(currencyCode);
|
|
309
|
-
const formatted = new Intl.NumberFormat("en-US", {
|
|
310
|
-
minimumFractionDigits: decimals,
|
|
311
|
-
maximumFractionDigits: decimals,
|
|
312
|
-
}).format(Math.abs(value));
|
|
313
|
-
if (isFiat(currencyCode) || isStablecoin(currencyCode)) {
|
|
314
|
-
return value < 0 ? `-${symbol}${formatted}` : `${symbol}${formatted}`;
|
|
315
|
-
}
|
|
316
|
-
return value < 0 ? `-${formatted} ${symbol}` : `${formatted} ${symbol}`;
|
|
317
|
-
}
|
|
1
|
+
// Currency — split by dependency weight so tree-shaking works at file
|
|
2
|
+
// granularity. The 133KB crypto-symbol dataset is imported ONLY by
|
|
3
|
+
// ./classify.ts; a bundler resolving `import { usd } from '…/currency'`
|
|
4
|
+
// through this barrel keeps usd.ts and drops everything else
|
|
5
|
+
// (`sideEffects: false`). The one-file era made that impossible: usd and
|
|
6
|
+
// isCrypto shared a module, so printing "$0.43" shipped 13k tickers.
|
|
7
|
+
//
|
|
8
|
+
// symbols.ts display symbols for the majors dataset-free
|
|
9
|
+
// usd.ts usd / usdIntlOptions / usdDecimals dataset-free (guaranteed)
|
|
10
|
+
// percent.ts percentage/bps arithmetic dataset-free
|
|
11
|
+
// classify.ts isCrypto/isFiat/normalize/… THE dataset importer
|
|
12
|
+
// decimals.ts getOptimalDecimals dataset via classify
|
|
13
|
+
// money.ts money/btc/eth dataset via decimals
|
|
14
|
+
export * from "./classify.js";
|
|
15
|
+
export * from "./decimals.js";
|
|
16
|
+
export * from "./money.js";
|
|
17
|
+
export * from "./percent.js";
|
|
18
|
+
export * from "./symbols.js";
|
|
19
|
+
export * from "./usd.js";
|
|
20
|
+
import { areEquivalent, getVariations, isCrypto, isFiat, isStablecoin, normalize, } from "./classify.js";
|
|
21
|
+
import { getOptimalDecimals } from "./decimals.js";
|
|
22
|
+
import { btc, eth, money } from "./money.js";
|
|
23
|
+
import { basisPointsToPercent, formatBasisPoints, percentageChange, percentageDiff, percentageOf, percentToBasisPoints, } from "./percent.js";
|
|
24
|
+
import { CurrencySymbols, getSymbol } from "./symbols.js";
|
|
25
|
+
import { usd, usdIntlOptions } from "./usd.js";
|
|
26
|
+
// Namespace convenience — importing it opts into EVERYTHING (dataset
|
|
27
|
+
// included); prefer named imports in bundle-sensitive code.
|
|
318
28
|
export const currency = {
|
|
319
29
|
getSymbol,
|
|
320
30
|
getOptimalDecimals,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/universal/currency/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/universal/currency/index.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,mEAAmE;AACnE,wEAAwE;AACxE,6DAA6D;AAC7D,yEAAyE;AACzE,qEAAqE;AACrE,EAAE;AACF,oEAAoE;AACpE,iFAAiF;AACjF,oEAAoE;AACpE,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAE5E,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AAEzB,OAAO,EACN,aAAa,EACb,aAAa,EACb,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,SAAS,GACT,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EACN,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,oBAAoB,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,qEAAqE;AACrE,4DAA4D;AAC5D,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB,SAAS;IACT,kBAAkB;IAClB,SAAS;IACT,aAAa;IACb,aAAa;IACb,QAAQ;IACR,YAAY;IACZ,MAAM;IACN,YAAY;IACZ,gBAAgB;IAChB,cAAc;IACd,oBAAoB;IACpB,oBAAoB;IACpB,iBAAiB;IACjB,GAAG;IACH,cAAc;IACd,GAAG;IACH,GAAG;IACH,KAAK;IACL,OAAO,EAAE,eAAe;CACxB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Numberish } from "../format.js";
|
|
2
|
+
/** Bitcoin with optimal decimals: 0.00001234 ₿ */
|
|
3
|
+
export declare function btc(value: Numberish): string;
|
|
4
|
+
/** Ethereum with optimal decimals: 0.123 Ξ */
|
|
5
|
+
export declare function eth(value: Numberish): string;
|
|
6
|
+
/**
|
|
7
|
+
* Format a value in any currency: symbol before for fiat/stablecoins
|
|
8
|
+
* (`$12.34`), after for crypto (`0.5 ₿`), optimal decimals + thousands
|
|
9
|
+
* grouping either way (en-pinned — SSR-hydration-safe).
|
|
10
|
+
*/
|
|
11
|
+
export declare function money(value: Numberish, currencyCode: string): string;
|
|
12
|
+
//# sourceMappingURL=money.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money.d.ts","sourceRoot":"","sources":["../../../src/universal/currency/money.ts"],"names":[],"mappings":"AAKA,OAAO,EAAW,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAKvD,kDAAkD;AAClD,wBAAgB,GAAG,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAG5C;AAED,8CAA8C;AAC9C,wBAAgB,GAAG,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAG5C;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAYpE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Symbol-aware money formatting. Reaches the dataset only through
|
|
2
|
+
// getOptimalDecimals' unknown-ticker fallback and isFiat/isStablecoin —
|
|
3
|
+
// callers passing arbitrary codes accept that; USD-only rendering belongs
|
|
4
|
+
// to ./usd.ts.
|
|
5
|
+
import { NO_DATA } from "../format.js";
|
|
6
|
+
import { isFiat, isStablecoin } from "./classify.js";
|
|
7
|
+
import { getOptimalDecimals } from "./decimals.js";
|
|
8
|
+
import { getSymbol } from "./symbols.js";
|
|
9
|
+
/** Bitcoin with optimal decimals: 0.00001234 ₿ */
|
|
10
|
+
export function btc(value) {
|
|
11
|
+
if (value == null)
|
|
12
|
+
return NO_DATA;
|
|
13
|
+
return `${value.toFixed(getOptimalDecimals(value, "BTC"))} ₿`;
|
|
14
|
+
}
|
|
15
|
+
/** Ethereum with optimal decimals: 0.123 Ξ */
|
|
16
|
+
export function eth(value) {
|
|
17
|
+
if (value == null)
|
|
18
|
+
return NO_DATA;
|
|
19
|
+
return `${value.toFixed(getOptimalDecimals(value, "ETH"))} Ξ`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Format a value in any currency: symbol before for fiat/stablecoins
|
|
23
|
+
* (`$12.34`), after for crypto (`0.5 ₿`), optimal decimals + thousands
|
|
24
|
+
* grouping either way (en-pinned — SSR-hydration-safe).
|
|
25
|
+
*/
|
|
26
|
+
export function money(value, currencyCode) {
|
|
27
|
+
if (value == null)
|
|
28
|
+
return NO_DATA;
|
|
29
|
+
const decimals = getOptimalDecimals(value, currencyCode);
|
|
30
|
+
const symbol = getSymbol(currencyCode);
|
|
31
|
+
const formatted = new Intl.NumberFormat("en-US", {
|
|
32
|
+
minimumFractionDigits: decimals,
|
|
33
|
+
maximumFractionDigits: decimals,
|
|
34
|
+
}).format(Math.abs(value));
|
|
35
|
+
if (isFiat(currencyCode) || isStablecoin(currencyCode)) {
|
|
36
|
+
return value < 0 ? `-${symbol}${formatted}` : `${symbol}${formatted}`;
|
|
37
|
+
}
|
|
38
|
+
return value < 0 ? `-${formatted} ${symbol}` : `${formatted} ${symbol}`;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=money.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money.js","sourceRoot":"","sources":["../../../src/universal/currency/money.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,wEAAwE;AACxE,0EAA0E;AAC1E,eAAe;AAEf,OAAO,EAAE,OAAO,EAAkB,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,kDAAkD;AAClD,MAAM,UAAU,GAAG,CAAC,KAAgB;IACnC,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,OAAO,CAAC;IAClC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC;AAC/D,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,GAAG,CAAC,KAAgB;IACnC,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,OAAO,CAAC;IAClC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC;AAC/D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAC,KAAgB,EAAE,YAAoB;IAC3D,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,OAAO,CAAC;IAClC,MAAM,QAAQ,GAAG,kBAAkB,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;IACvC,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;QAChD,qBAAqB,EAAE,QAAQ;QAC/B,qBAAqB,EAAE,QAAQ;KAC/B,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3B,IAAI,MAAM,CAAC,YAAY,CAAC,IAAI,YAAY,CAAC,YAAY,CAAC,EAAE,CAAC;QACxD,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,GAAG,SAAS,EAAE,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,SAAS,EAAE,CAAC;IACvE,CAAC;IACD,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,GAAG,SAAS,IAAI,MAAM,EAAE,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function percentageOf(value: number, total: number): number;
|
|
2
|
+
export declare function percentageChange(oldValue: number, newValue: number): number;
|
|
3
|
+
export declare function percentageDiff(a: number, b: number): number;
|
|
4
|
+
export declare function basisPointsToPercent(bps: number): number;
|
|
5
|
+
export declare function percentToBasisPoints(percent: number): number;
|
|
6
|
+
export declare function formatBasisPoints(bps: number): string;
|
|
7
|
+
//# sourceMappingURL=percent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"percent.d.ts","sourceRoot":"","sources":["../../../src/universal/currency/percent.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAGjE;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAM3E;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAK3D;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAErD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Percentage / basis-point arithmetic. Pure math, dataset-free.
|
|
2
|
+
export function percentageOf(value, total) {
|
|
3
|
+
if (total === 0)
|
|
4
|
+
return 0;
|
|
5
|
+
return (value / total) * 100;
|
|
6
|
+
}
|
|
7
|
+
export function percentageChange(oldValue, newValue) {
|
|
8
|
+
if (oldValue === 0) {
|
|
9
|
+
if (newValue === 0)
|
|
10
|
+
return 0;
|
|
11
|
+
return newValue > 0 ? 100 : -100;
|
|
12
|
+
}
|
|
13
|
+
return ((newValue - oldValue) / Math.abs(oldValue)) * 100;
|
|
14
|
+
}
|
|
15
|
+
export function percentageDiff(a, b) {
|
|
16
|
+
if (a === 0 && b === 0)
|
|
17
|
+
return 0;
|
|
18
|
+
const avg = (Math.abs(a) + Math.abs(b)) / 2;
|
|
19
|
+
if (avg === 0)
|
|
20
|
+
return 0;
|
|
21
|
+
return (Math.abs(a - b) / avg) * 100;
|
|
22
|
+
}
|
|
23
|
+
export function basisPointsToPercent(bps) {
|
|
24
|
+
return bps / 100.0;
|
|
25
|
+
}
|
|
26
|
+
export function percentToBasisPoints(percent) {
|
|
27
|
+
return Math.round(percent * 100);
|
|
28
|
+
}
|
|
29
|
+
export function formatBasisPoints(bps) {
|
|
30
|
+
return `${bps} bps`;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=percent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"percent.js","sourceRoot":"","sources":["../../../src/universal/currency/percent.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,KAAa;IACxD,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAC1B,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,QAAgB,EAAE,QAAgB;IAClE,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACpB,IAAI,QAAQ,KAAK,CAAC;YAAE,OAAO,CAAC,CAAC;QAC7B,OAAO,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAClC,CAAC;IACD,OAAO,CAAC,CAAC,QAAQ,GAAG,QAAQ,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,GAAG,GAAG,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,CAAS,EAAE,CAAS;IAClD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IACjC,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC5C,IAAI,GAAG,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IACxB,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,GAAW;IAC/C,OAAO,GAAG,GAAG,KAAK,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,OAAe;IACnD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,GAAW;IAC5C,OAAO,GAAG,GAAG,MAAM,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare const CurrencySymbols: {
|
|
2
|
+
readonly BTC: "₿";
|
|
3
|
+
readonly XBT: "₿";
|
|
4
|
+
readonly ETH: "Ξ";
|
|
5
|
+
readonly USD: "$";
|
|
6
|
+
readonly EUR: "€";
|
|
7
|
+
readonly GBP: "£";
|
|
8
|
+
readonly JPY: "¥";
|
|
9
|
+
readonly CNY: "¥";
|
|
10
|
+
readonly KRW: "₩";
|
|
11
|
+
readonly INR: "₹";
|
|
12
|
+
readonly RUB: "₽";
|
|
13
|
+
readonly TRY: "₺";
|
|
14
|
+
readonly AUD: "A$";
|
|
15
|
+
readonly CAD: "C$";
|
|
16
|
+
readonly CHF: "Fr";
|
|
17
|
+
readonly HKD: "HK$";
|
|
18
|
+
readonly SGD: "S$";
|
|
19
|
+
readonly NZD: "NZ$";
|
|
20
|
+
readonly SEK: "kr";
|
|
21
|
+
readonly NOK: "kr";
|
|
22
|
+
readonly DKK: "kr";
|
|
23
|
+
readonly PLN: "zł";
|
|
24
|
+
readonly THB: "฿";
|
|
25
|
+
readonly USDT: "₮";
|
|
26
|
+
readonly USDC: "$";
|
|
27
|
+
readonly DAI: "$";
|
|
28
|
+
readonly BUSD: "$";
|
|
29
|
+
};
|
|
30
|
+
export type CurrencyCode = keyof typeof CurrencySymbols | string;
|
|
31
|
+
export declare function getSymbol(code: string): string;
|
|
32
|
+
//# sourceMappingURL=symbols.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"symbols.d.ts","sourceRoot":"","sources":["../../../src/universal/currency/symbols.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BlB,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,MAAM,OAAO,eAAe,GAAG,MAAM,CAAC;AAEjE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Display symbols for the majors. Tiny and dataset-free — classification of
|
|
2
|
+
// the 13k-ticker long tail lives in ./classify.ts, the ONLY module that
|
|
3
|
+
// imports the crypto-symbol dataset.
|
|
4
|
+
export const CurrencySymbols = {
|
|
5
|
+
BTC: "₿",
|
|
6
|
+
XBT: "₿",
|
|
7
|
+
ETH: "Ξ",
|
|
8
|
+
USD: "$",
|
|
9
|
+
EUR: "€",
|
|
10
|
+
GBP: "£",
|
|
11
|
+
JPY: "¥",
|
|
12
|
+
CNY: "¥",
|
|
13
|
+
KRW: "₩",
|
|
14
|
+
INR: "₹",
|
|
15
|
+
RUB: "₽",
|
|
16
|
+
TRY: "₺",
|
|
17
|
+
AUD: "A$",
|
|
18
|
+
CAD: "C$",
|
|
19
|
+
CHF: "Fr",
|
|
20
|
+
HKD: "HK$",
|
|
21
|
+
SGD: "S$",
|
|
22
|
+
NZD: "NZ$",
|
|
23
|
+
SEK: "kr",
|
|
24
|
+
NOK: "kr",
|
|
25
|
+
DKK: "kr",
|
|
26
|
+
PLN: "zł",
|
|
27
|
+
THB: "฿",
|
|
28
|
+
USDT: "₮",
|
|
29
|
+
USDC: "$",
|
|
30
|
+
DAI: "$",
|
|
31
|
+
BUSD: "$",
|
|
32
|
+
};
|
|
33
|
+
export function getSymbol(code) {
|
|
34
|
+
return CurrencySymbols[code] || code;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=symbols.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"symbols.js","sourceRoot":"","sources":["../../../src/universal/currency/symbols.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,wEAAwE;AACxE,qCAAqC;AAErC,MAAM,CAAC,MAAM,eAAe,GAAG;IAC9B,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,GAAG;IACR,IAAI,EAAE,GAAG;IACT,IAAI,EAAE,GAAG;IACT,GAAG,EAAE,GAAG;IACR,IAAI,EAAE,GAAG;CACA,CAAC;AAIX,MAAM,UAAU,SAAS,CAAC,IAAY;IACrC,OAAO,eAAe,CAAC,IAAoC,CAAC,IAAI,IAAI,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Numberish } from "../format.js";
|
|
2
|
+
/** The USD decimals policy: 2 for dollars, more as the value shrinks, significant-digit floor below a cent. */
|
|
3
|
+
export declare function usdDecimals(value: number): number;
|
|
4
|
+
export interface UsdOptions {
|
|
5
|
+
/** Fixed decimal places, overriding the optimal-decimals policy. */
|
|
6
|
+
decimals?: number;
|
|
7
|
+
/** Compact notation for market-cap-scale money: $60.9M. */
|
|
8
|
+
compact?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The USD decimals POLICY as Intl.NumberFormatOptions, for consumers that
|
|
12
|
+
* format internally — animated numbers (NumberFlow), chart axes, table cell
|
|
13
|
+
* renderers. One policy serves strings and widgets alike; `usd()` below is
|
|
14
|
+
* just this policy applied. Value-dependent: recompute when the value moves.
|
|
15
|
+
*/
|
|
16
|
+
export declare function usdIntlOptions(value: number, opts?: UsdOptions): Intl.NumberFormatOptions;
|
|
17
|
+
/**
|
|
18
|
+
* $1,234.56 with optimal decimals (grouped, en-pinned — SSR-hydration-safe);
|
|
19
|
+
* sub-cent values keep 2 significant digits ($0.00000043) instead of rounding
|
|
20
|
+
* to $0.000000. `{compact: true}` → $60.9M; `{decimals}` overrides the policy.
|
|
21
|
+
*/
|
|
22
|
+
export declare function usd(value: Numberish, opts?: UsdOptions): string;
|
|
23
|
+
//# sourceMappingURL=usd.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usd.d.ts","sourceRoot":"","sources":["../../../src/universal/currency/usd.ts"],"names":[],"mappings":"AAOA,OAAO,EAAW,KAAK,SAAS,EAAe,MAAM,cAAc,CAAC;AAEpE,+GAA+G;AAC/G,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOjD;AAED,MAAM,WAAW,UAAU;IAC1B,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC7B,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,UAAe,GACnB,IAAI,CAAC,mBAAmB,CAgB1B;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,GAAE,UAAe,GAAG,MAAM,CAKnE"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// USD formatting — deliberately dataset-free. Printing dollars needs no
|
|
2
|
+
// symbol lookup and no crypto classification, so this module must never
|
|
3
|
+
// import ./classify.ts: it is the module a client bundle pulls to render a
|
|
4
|
+
// price, and the 133KB ticker dataset has no business riding along.
|
|
5
|
+
// getOptimalDecimals (./decimals.ts) delegates its USD/stables case to
|
|
6
|
+
// usdDecimals, so the policy has exactly one home.
|
|
7
|
+
import { NO_DATA, sigDecimals } from "../format.js";
|
|
8
|
+
/** The USD decimals policy: 2 for dollars, more as the value shrinks, significant-digit floor below a cent. */
|
|
9
|
+
export function usdDecimals(value) {
|
|
10
|
+
if (value === 0)
|
|
11
|
+
return 2;
|
|
12
|
+
const absValue = Math.abs(value);
|
|
13
|
+
if (absValue < 0.01)
|
|
14
|
+
return sigDecimals(absValue);
|
|
15
|
+
if (absValue < 0.1)
|
|
16
|
+
return 4;
|
|
17
|
+
if (absValue < 1)
|
|
18
|
+
return 3;
|
|
19
|
+
return 2;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The USD decimals POLICY as Intl.NumberFormatOptions, for consumers that
|
|
23
|
+
* format internally — animated numbers (NumberFlow), chart axes, table cell
|
|
24
|
+
* renderers. One policy serves strings and widgets alike; `usd()` below is
|
|
25
|
+
* just this policy applied. Value-dependent: recompute when the value moves.
|
|
26
|
+
*/
|
|
27
|
+
export function usdIntlOptions(value, opts = {}) {
|
|
28
|
+
if (opts.compact) {
|
|
29
|
+
return {
|
|
30
|
+
style: "currency",
|
|
31
|
+
currency: "USD",
|
|
32
|
+
notation: "compact",
|
|
33
|
+
maximumFractionDigits: 1,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const decimals = opts.decimals ?? usdDecimals(value);
|
|
37
|
+
return {
|
|
38
|
+
style: "currency",
|
|
39
|
+
currency: "USD",
|
|
40
|
+
minimumFractionDigits: decimals,
|
|
41
|
+
maximumFractionDigits: decimals,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* $1,234.56 with optimal decimals (grouped, en-pinned — SSR-hydration-safe);
|
|
46
|
+
* sub-cent values keep 2 significant digits ($0.00000043) instead of rounding
|
|
47
|
+
* to $0.000000. `{compact: true}` → $60.9M; `{decimals}` overrides the policy.
|
|
48
|
+
*/
|
|
49
|
+
export function usd(value, opts = {}) {
|
|
50
|
+
if (value == null)
|
|
51
|
+
return NO_DATA;
|
|
52
|
+
return new Intl.NumberFormat("en-US", usdIntlOptions(value, opts)).format(value);
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=usd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usd.js","sourceRoot":"","sources":["../../../src/universal/currency/usd.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,wEAAwE;AACxE,2EAA2E;AAC3E,oEAAoE;AACpE,uEAAuE;AACvE,mDAAmD;AAEnD,OAAO,EAAE,OAAO,EAAkB,WAAW,EAAE,MAAM,cAAc,CAAC;AAEpE,+GAA+G;AAC/G,MAAM,UAAU,WAAW,CAAC,KAAa;IACxC,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAC1B,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACjC,IAAI,QAAQ,GAAG,IAAI;QAAE,OAAO,WAAW,CAAC,QAAQ,CAAC,CAAC;IAClD,IAAI,QAAQ,GAAG,GAAG;QAAE,OAAO,CAAC,CAAC;IAC7B,IAAI,QAAQ,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;IAC3B,OAAO,CAAC,CAAC;AACV,CAAC;AASD;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC7B,KAAa,EACb,OAAmB,EAAE;IAErB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QAClB,OAAO;YACN,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,KAAK;YACf,QAAQ,EAAE,SAAS;YACnB,qBAAqB,EAAE,CAAC;SACxB,CAAC;IACH,CAAC;IACD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC;IACrD,OAAO;QACN,KAAK,EAAE,UAAU;QACjB,QAAQ,EAAE,KAAK;QACf,qBAAqB,EAAE,QAAQ;QAC/B,qBAAqB,EAAE,QAAQ;KAC/B,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,GAAG,CAAC,KAAgB,EAAE,OAAmB,EAAE;IAC1D,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,OAAO,CAAC;IAClC,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CACxE,KAAK,CACL,CAAC;AACH,CAAC"}
|