@talismn/util 2.1.0 → 2.2.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/dist/index.d.mts +17 -88
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +17 -88
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +159 -98
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +155 -97
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
// \0rolldown/runtime.js
|
|
3
3
|
var __create = Object.create;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -20,22 +20,19 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
20
20
|
value: mod,
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
|
23
|
-
//#endregion
|
|
24
23
|
let bignumber_js = require("bignumber.js");
|
|
25
24
|
bignumber_js = __toESM(bignumber_js);
|
|
26
25
|
let lodash_es = require("lodash-es");
|
|
27
26
|
let rxjs = require("rxjs");
|
|
28
|
-
|
|
27
|
+
// src/configureBigNumber.ts
|
|
29
28
|
bignumber_js.default.set({ STRICT: false });
|
|
30
29
|
var configureBigNumber_default = bignumber_js.default;
|
|
31
|
-
|
|
32
|
-
//#region src/addTrailingSlash.ts
|
|
30
|
+
// src/addTrailingSlash.ts
|
|
33
31
|
const addTrailingSlash = (url) => {
|
|
34
32
|
if (url.endsWith("/")) return url;
|
|
35
33
|
return `${url}/`;
|
|
36
34
|
};
|
|
37
|
-
|
|
38
|
-
//#region src/assert.ts
|
|
35
|
+
// src/assert.ts
|
|
39
36
|
/**
|
|
40
37
|
* @name assert
|
|
41
38
|
* @description Throws an Error with the given message if the condition is falsy.
|
|
@@ -46,8 +43,7 @@ function assert(condition, message) {
|
|
|
46
43
|
if (condition) return;
|
|
47
44
|
throw new Error(typeof message === "function" ? message() : message);
|
|
48
45
|
}
|
|
49
|
-
|
|
50
|
-
//#region src/BigMath.ts
|
|
46
|
+
// src/BigMath.ts
|
|
51
47
|
/**
|
|
52
48
|
* Javascript's `Math` library for `BigInt`.
|
|
53
49
|
* Taken from https://stackoverflow.com/questions/51867270/is-there-a-library-similar-to-math-that-supports-javascript-bigint/64953280#64953280
|
|
@@ -69,14 +65,12 @@ const BigMath = {
|
|
|
69
65
|
return value;
|
|
70
66
|
}
|
|
71
67
|
};
|
|
72
|
-
|
|
73
|
-
//#region src/isHexString.ts
|
|
68
|
+
// src/isHexString.ts
|
|
74
69
|
const REGEX_HEX_STRING = /^0x[0-9a-fA-F]*$/;
|
|
75
70
|
const isHexString = (value) => {
|
|
76
71
|
return typeof value === "string" && REGEX_HEX_STRING.test(value);
|
|
77
72
|
};
|
|
78
|
-
|
|
79
|
-
//#region src/bytes.ts
|
|
73
|
+
// src/bytes.ts
|
|
80
74
|
/**
|
|
81
75
|
* Byte / hex primitives, drop-in equivalents of the `@polkadot/util` helpers we used to depend on.
|
|
82
76
|
* Semantics intentionally match polkadot-js for migration safety.
|
|
@@ -89,10 +83,11 @@ const hexToU8a = (hex) => {
|
|
|
89
83
|
for (let i = 0; i < result.length; i++) result[i] = parseInt(padded.substring(i * 2, i * 2 + 2), 16);
|
|
90
84
|
return result;
|
|
91
85
|
};
|
|
86
|
+
const HEX_BYTES = Array.from({ length: 256 }, (_, byte) => byte.toString(16).padStart(2, "0"));
|
|
92
87
|
const u8aToHex = (value) => {
|
|
93
88
|
if (!value?.length) return "0x";
|
|
94
89
|
let hex = "";
|
|
95
|
-
for (const byte of value) hex += byte
|
|
90
|
+
for (const byte of value) hex += HEX_BYTES[byte];
|
|
96
91
|
return `0x${hex}`;
|
|
97
92
|
};
|
|
98
93
|
const stringToU8a = (value) => value ? new TextEncoder().encode(value) : /* @__PURE__ */ new Uint8Array();
|
|
@@ -157,15 +152,15 @@ const u8aUnwrapBytes = (value) => {
|
|
|
157
152
|
const u8a = u8aToU8a(value);
|
|
158
153
|
return u8aIsWrapped(u8a) ? u8a.subarray(U8A_WRAP_PREFIX.length, u8a.length - U8A_WRAP_POSTFIX.length) : u8a;
|
|
159
154
|
};
|
|
160
|
-
|
|
161
|
-
//#region src/jsActivityHook.ts
|
|
155
|
+
// src/jsActivityHook.ts
|
|
162
156
|
const reportJsActivity = (label, durationMs) => {
|
|
163
157
|
const record = globalThis.__recordJsActivity;
|
|
164
158
|
if (record) record(label, durationMs);
|
|
165
159
|
};
|
|
166
|
-
|
|
167
|
-
//#region src/yieldToEventLoop.ts
|
|
160
|
+
// src/yieldToEventLoop.ts
|
|
168
161
|
const yieldToEventLoop = () => {
|
|
162
|
+
const { scheduler } = globalThis;
|
|
163
|
+
if (typeof scheduler?.postTask === "function") return scheduler.postTask(() => {}, { priority: "background" });
|
|
169
164
|
if (typeof MessageChannel !== "undefined") return new Promise((resolve) => {
|
|
170
165
|
const channel = new MessageChannel();
|
|
171
166
|
const port1 = channel.port1;
|
|
@@ -179,8 +174,7 @@ const yieldToEventLoop = () => {
|
|
|
179
174
|
});
|
|
180
175
|
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
181
176
|
};
|
|
182
|
-
|
|
183
|
-
//#region src/timeSlicer.ts
|
|
177
|
+
// src/timeSlicer.ts
|
|
184
178
|
/**
|
|
185
179
|
* Default CPU budget for a single synchronous slice of chunked work.
|
|
186
180
|
* ~50-60% of a 60fps frame, leaving the rest for the host (user interactions, rendering).
|
|
@@ -223,8 +217,7 @@ const createTimeSlicer = ({ budgetMs = 10, signal, now = defaultNow, label } = {
|
|
|
223
217
|
throwIfAborted
|
|
224
218
|
};
|
|
225
219
|
};
|
|
226
|
-
|
|
227
|
-
//#region src/chunkedArray.ts
|
|
220
|
+
// src/chunkedArray.ts
|
|
228
221
|
const getSlicer = (options) => options?.slicer ?? createTimeSlicer({
|
|
229
222
|
budgetMs: options?.budgetMs,
|
|
230
223
|
signal: options?.signal,
|
|
@@ -277,8 +270,7 @@ const arrayItemsEqualWithYield = async (a, b, options) => {
|
|
|
277
270
|
}
|
|
278
271
|
return true;
|
|
279
272
|
};
|
|
280
|
-
|
|
281
|
-
//#region src/deferred.ts
|
|
273
|
+
// src/deferred.ts
|
|
282
274
|
/**
|
|
283
275
|
* In TypeScript, a deferred promise refers to a pattern that involves creating a promise that can be
|
|
284
276
|
* resolved or rejected at a later point in time, typically by code outside of the current function scope.
|
|
@@ -312,8 +304,7 @@ function Deferred() {
|
|
|
312
304
|
isRejected: () => isRejected
|
|
313
305
|
};
|
|
314
306
|
}
|
|
315
|
-
|
|
316
|
-
//#region src/firstThenDebounce.ts
|
|
307
|
+
// src/firstThenDebounce.ts
|
|
317
308
|
/**
|
|
318
309
|
* An rxjs operator which:
|
|
319
310
|
*
|
|
@@ -321,8 +312,90 @@ function Deferred() {
|
|
|
321
312
|
* 2. Debounces any future values by `timeout` ms.
|
|
322
313
|
*/
|
|
323
314
|
const firstThenDebounce = (timeout) => (source) => (0, rxjs.concat)(source.pipe((0, rxjs.take)(1)), source.pipe((0, rxjs.skip)(1)).pipe((0, rxjs.debounceTime)(timeout)));
|
|
324
|
-
|
|
325
|
-
|
|
315
|
+
// src/formatCurrency.ts
|
|
316
|
+
const INTL_CURRENCY_OVERRIDES = {
|
|
317
|
+
btc: {
|
|
318
|
+
symbol: "₿",
|
|
319
|
+
fractionDigits: 6
|
|
320
|
+
},
|
|
321
|
+
eth: {
|
|
322
|
+
symbol: "Ξ",
|
|
323
|
+
fractionDigits: 5
|
|
324
|
+
},
|
|
325
|
+
tao: {
|
|
326
|
+
symbol: "τ",
|
|
327
|
+
fractionDigits: 4
|
|
328
|
+
},
|
|
329
|
+
idr: { fractionDigits: 0 }
|
|
330
|
+
};
|
|
331
|
+
const INTL_MAX_FRACTION_DIGITS = 20;
|
|
332
|
+
const clampFractionDigits = (digits) => digits === void 0 ? void 0 : Math.min(digits, INTL_MAX_FRACTION_DIGITS);
|
|
333
|
+
const fractionDigitsByCurrency = /* @__PURE__ */ new Map();
|
|
334
|
+
const getCurrencyFractionDigits = (currency) => {
|
|
335
|
+
const currencyId = currency.toLowerCase();
|
|
336
|
+
const cached = fractionDigitsByCurrency.get(currencyId);
|
|
337
|
+
if (cached !== void 0) return cached;
|
|
338
|
+
const { maximumFractionDigits: intlFractionDigits = 2 } = new Intl.NumberFormat(void 0, {
|
|
339
|
+
style: "currency",
|
|
340
|
+
currency
|
|
341
|
+
}).resolvedOptions();
|
|
342
|
+
const fractionDigits = INTL_CURRENCY_OVERRIDES[currencyId]?.fractionDigits ?? intlFractionDigits;
|
|
343
|
+
fractionDigitsByCurrency.set(currencyId, fractionDigits);
|
|
344
|
+
return fractionDigits;
|
|
345
|
+
};
|
|
346
|
+
const getDefaultFractionDigits = (currencyId, options) => {
|
|
347
|
+
if ([
|
|
348
|
+
options.minimumFractionDigits,
|
|
349
|
+
options.maximumFractionDigits,
|
|
350
|
+
options.minimumSignificantDigits,
|
|
351
|
+
options.maximumSignificantDigits
|
|
352
|
+
].some((digits) => digits !== void 0) || options.notation === "compact") return void 0;
|
|
353
|
+
return INTL_CURRENCY_OVERRIDES[currencyId]?.fractionDigits;
|
|
354
|
+
};
|
|
355
|
+
const isSpacing = (part) => part?.type === "literal" && part.value.trim() === "";
|
|
356
|
+
const withTrailingCode = (parts, code) => {
|
|
357
|
+
const currencyIndex = parts.findIndex((part) => part.type === "currency");
|
|
358
|
+
const number = parts.filter((part, index) => index !== currencyIndex && !(isSpacing(part) && Math.abs(index - currencyIndex) === 1));
|
|
359
|
+
while (isSpacing(number[0])) number.shift();
|
|
360
|
+
while (isSpacing(number.at(-1))) number.pop();
|
|
361
|
+
return [
|
|
362
|
+
...number,
|
|
363
|
+
{
|
|
364
|
+
type: "literal",
|
|
365
|
+
value: " "
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
type: "currency",
|
|
369
|
+
value: code
|
|
370
|
+
}
|
|
371
|
+
];
|
|
372
|
+
};
|
|
373
|
+
const formatCurrencyToParts = (amount, currency, options = {}) => {
|
|
374
|
+
const currencyId = currency.toLowerCase();
|
|
375
|
+
const currencyDisplay = options.currencyDisplay ?? (currencyId === "usd" ? "narrowSymbol" : "symbol");
|
|
376
|
+
const defaultFractionDigits = getDefaultFractionDigits(currencyId, options);
|
|
377
|
+
const intlOptions = {
|
|
378
|
+
...options,
|
|
379
|
+
style: "currency",
|
|
380
|
+
currency,
|
|
381
|
+
currencyDisplay,
|
|
382
|
+
minimumFractionDigits: clampFractionDigits(options.minimumFractionDigits ?? defaultFractionDigits),
|
|
383
|
+
maximumFractionDigits: clampFractionDigits(options.maximumFractionDigits ?? defaultFractionDigits)
|
|
384
|
+
};
|
|
385
|
+
if (currencyDisplay === "code") return withTrailingCode(new Intl.NumberFormat(void 0, intlOptions).formatToParts(amount), currency.toUpperCase());
|
|
386
|
+
const symbol = currencyDisplay === "name" ? void 0 : INTL_CURRENCY_OVERRIDES[currencyId]?.symbol;
|
|
387
|
+
if (!symbol) return new Intl.NumberFormat(void 0, intlOptions).formatToParts(amount);
|
|
388
|
+
return new Intl.NumberFormat(void 0, {
|
|
389
|
+
...intlOptions,
|
|
390
|
+
currency: "USD",
|
|
391
|
+
currencyDisplay: "narrowSymbol"
|
|
392
|
+
}).formatToParts(amount).map((part) => part.type === "currency" ? {
|
|
393
|
+
...part,
|
|
394
|
+
value: symbol
|
|
395
|
+
} : part);
|
|
396
|
+
};
|
|
397
|
+
const formatCurrency = (amount, currency, options = {}) => formatCurrencyToParts(amount, currency, options).map((part) => part.value).join("");
|
|
398
|
+
// src/formatDecimals.ts
|
|
326
399
|
const MIN_DIGITS = 4;
|
|
327
400
|
const MAX_DECIMALS_FORMAT = 12;
|
|
328
401
|
/**
|
|
@@ -354,28 +427,39 @@ const formatDecimals = (num, digits = MIN_DIGITS, options = {}, locale = "en-US"
|
|
|
354
427
|
...options
|
|
355
428
|
}).format(truncatedValue.toNumber());
|
|
356
429
|
};
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
430
|
+
// src/formatPrice.ts
|
|
431
|
+
const getPriceOptions = (price, compact) => ({
|
|
432
|
+
minimumSignificantDigits: 3,
|
|
433
|
+
maximumSignificantDigits: compact ? price < 1 ? 3 : 4 : void 0,
|
|
434
|
+
roundingPriority: compact ? "auto" : "morePrecision",
|
|
435
|
+
notation: compact ? "compact" : "standard"
|
|
436
|
+
});
|
|
437
|
+
const formatPrice = (price, currency, compact) => formatCurrency(price, currency, getPriceOptions(price, compact));
|
|
438
|
+
const MIN_COLLAPSED_ZEROS = 4;
|
|
439
|
+
const formatCompactPrice = (price, currency) => {
|
|
440
|
+
const parts = formatCurrencyToParts(price, currency, getPriceOptions(price, true));
|
|
441
|
+
const joinParts = (from, to) => parts.slice(from, to).map((part) => part.value).join("");
|
|
442
|
+
const fractionIndex = parts.findIndex((part) => part.type === "fraction");
|
|
443
|
+
const integer = parts.find((part) => part.type === "integer")?.value;
|
|
444
|
+
const match = /^(0+)([1-9]\d*?)0*$/.exec(parts[fractionIndex]?.value ?? "");
|
|
445
|
+
if (integer !== "0" || !match || match[1].length < MIN_COLLAPSED_ZEROS) return {
|
|
446
|
+
kind: "plain",
|
|
447
|
+
text: joinParts(0)
|
|
448
|
+
};
|
|
449
|
+
return {
|
|
450
|
+
kind: "collapsedZeros",
|
|
451
|
+
head: joinParts(0, fractionIndex),
|
|
452
|
+
zeroCount: match[1].length,
|
|
453
|
+
tail: match[2] + joinParts(fractionIndex + 1)
|
|
454
|
+
};
|
|
455
|
+
};
|
|
456
|
+
// src/getErrorMessage.ts
|
|
372
457
|
const getErrorMessage = (error, fallback = "Unknown error") => {
|
|
373
458
|
if (typeof error === "string") return error || fallback;
|
|
374
459
|
if (error && typeof error === "object" && "message" in error && typeof error.message === "string") return error.message || fallback;
|
|
375
460
|
return fallback;
|
|
376
461
|
};
|
|
377
|
-
|
|
378
|
-
//#region src/getLoadable.ts
|
|
462
|
+
// src/getLoadable.ts
|
|
379
463
|
function getLoadable$(factory, options = {}) {
|
|
380
464
|
const { getError, refreshInterval } = options;
|
|
381
465
|
const createLoadableStream = () => (0, rxjs.from)(factory()).pipe((0, rxjs.map)((data) => ({
|
|
@@ -391,8 +475,7 @@ const getGenericError = (error) => ({
|
|
|
391
475
|
name: "Error",
|
|
392
476
|
message: getErrorMessage(error)
|
|
393
477
|
});
|
|
394
|
-
|
|
395
|
-
//#region src/getSharedObservable.ts
|
|
478
|
+
// src/getSharedObservable.ts
|
|
396
479
|
const CACHE = /* @__PURE__ */ new Map();
|
|
397
480
|
/**
|
|
398
481
|
* How long an entry survives with no subscribers before being dropped. Long enough
|
|
@@ -452,8 +535,7 @@ const getSharedObservable = (namespace, args, createObservable, serializer = (ar
|
|
|
452
535
|
scheduleCleanup(entry);
|
|
453
536
|
return entry.observable;
|
|
454
537
|
};
|
|
455
|
-
|
|
456
|
-
//#region src/getQuery.ts
|
|
538
|
+
// src/getQuery.ts
|
|
457
539
|
/**
|
|
458
540
|
* Creates a shared observable for executing queries with caching, loading states, and automatic refresh capabilities.
|
|
459
541
|
*
|
|
@@ -518,8 +600,7 @@ const getQuery$ = ({ namespace, args, queryFn, defaultValue, refreshInterval, se
|
|
|
518
600
|
bufferSize: 1
|
|
519
601
|
})), serializer);
|
|
520
602
|
};
|
|
521
|
-
|
|
522
|
-
//#region src/getLoadableQuery.ts
|
|
603
|
+
// src/getLoadableQuery.ts
|
|
523
604
|
/**
|
|
524
605
|
* Thin wrapper around getQuery$ that returns Loadable<T> and optionally
|
|
525
606
|
* primes the stream with a loading state using the provided default value.
|
|
@@ -554,38 +635,31 @@ const getLoadableQuery$ = (params) => {
|
|
|
554
635
|
}
|
|
555
636
|
}), (0, rxjs.startWith)(...initial));
|
|
556
637
|
};
|
|
557
|
-
|
|
558
|
-
//#region src/hasOwnProperty.ts
|
|
638
|
+
// src/hasOwnProperty.ts
|
|
559
639
|
function hasOwnProperty(obj, prop) {
|
|
560
640
|
if (typeof obj !== "object") return false;
|
|
561
641
|
if (obj === null) return false;
|
|
562
642
|
return prop in obj;
|
|
563
643
|
}
|
|
564
|
-
|
|
565
|
-
//#region src/isAbortError.ts
|
|
644
|
+
// src/isAbortError.ts
|
|
566
645
|
const isAbortError = (error) => {
|
|
567
646
|
return error instanceof Error && error.name === "AbortError";
|
|
568
647
|
};
|
|
569
|
-
|
|
570
|
-
//#region src/isArrayOf.ts
|
|
648
|
+
// src/isArrayOf.ts
|
|
571
649
|
function isArrayOf(array, func) {
|
|
572
650
|
if (array.length > 0 && array[0] instanceof func) return true;
|
|
573
651
|
return false;
|
|
574
652
|
}
|
|
575
|
-
|
|
576
|
-
//#region src/isAscii.ts
|
|
653
|
+
// src/isAscii.ts
|
|
577
654
|
const isAscii = (str) => {
|
|
578
655
|
return [...str].every((char) => char.charCodeAt(0) <= 127);
|
|
579
656
|
};
|
|
580
|
-
|
|
581
|
-
//#region src/isBigInt.ts
|
|
657
|
+
// src/isBigInt.ts
|
|
582
658
|
const isBigInt = (value) => typeof value === "bigint";
|
|
583
|
-
|
|
584
|
-
//#region src/isBooleanTrue.ts
|
|
659
|
+
// src/isBooleanTrue.ts
|
|
585
660
|
/** @deprecated use isTruthy instead */
|
|
586
661
|
const isBooleanTrue = (x) => !!x;
|
|
587
|
-
|
|
588
|
-
//#region src/isErrorOfName.ts
|
|
662
|
+
// src/isErrorOfName.ts
|
|
589
663
|
/**
|
|
590
664
|
* Robust replacement for `error instanceof SomeErrorClass` when the class comes from a
|
|
591
665
|
* package that gets bundled into multiple chunks/contexts (e.g. viem, @solana/web3.js).
|
|
@@ -598,8 +672,7 @@ const isBooleanTrue = (x) => !!x;
|
|
|
598
672
|
* duck-type the shape instead.
|
|
599
673
|
*/
|
|
600
674
|
const isErrorOfName = (error, ...names) => error instanceof Error && names.includes(error.name);
|
|
601
|
-
|
|
602
|
-
//#region src/isNotNil.ts
|
|
675
|
+
// src/isNotNil.ts
|
|
603
676
|
/**
|
|
604
677
|
* WARNING: This function only checks against null or undefined, it does not coerce the value.
|
|
605
678
|
* ie: false and 0 are considered not nil
|
|
@@ -609,11 +682,9 @@ const isErrorOfName = (error, ...names) => error instanceof Error && names.inclu
|
|
|
609
682
|
* @returns whether the value is neither null nor undefined
|
|
610
683
|
*/
|
|
611
684
|
const isNotNil = (value) => value !== null && value !== void 0;
|
|
612
|
-
|
|
613
|
-
//#region src/isPromise.ts
|
|
685
|
+
// src/isPromise.ts
|
|
614
686
|
const isPromise = (value) => !!value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
615
|
-
|
|
616
|
-
//#region src/isSubject.ts
|
|
687
|
+
// src/isSubject.ts
|
|
617
688
|
/**
|
|
618
689
|
* Tests to see if an object is an RxJS {@link Subject}.
|
|
619
690
|
*/
|
|
@@ -634,11 +705,9 @@ function isFn(value) {
|
|
|
634
705
|
function isBool(value) {
|
|
635
706
|
return typeof value === "boolean";
|
|
636
707
|
}
|
|
637
|
-
|
|
638
|
-
//#region src/isTruthy.ts
|
|
708
|
+
// src/isTruthy.ts
|
|
639
709
|
const isTruthy = (value) => Boolean(value);
|
|
640
|
-
|
|
641
|
-
//#region src/keepAlive.ts
|
|
710
|
+
// src/keepAlive.ts
|
|
642
711
|
/**
|
|
643
712
|
* An RxJS operator that keeps the source observable alive for a specified duration
|
|
644
713
|
* after all subscribers have unsubscribed. This prevents expensive re-subscriptions
|
|
@@ -672,8 +741,7 @@ const keepSourceSubscribed = (observable, ms) => {
|
|
|
672
741
|
const sub = observable.subscribe();
|
|
673
742
|
return () => setTimeout(() => sub.unsubscribe(), ms);
|
|
674
743
|
};
|
|
675
|
-
|
|
676
|
-
//#region src/lruMap.ts
|
|
744
|
+
// src/lruMap.ts
|
|
677
745
|
/**
|
|
678
746
|
* A Map with a maximum size and least-recently-used eviction.
|
|
679
747
|
*
|
|
@@ -717,8 +785,7 @@ var LruMap = class {
|
|
|
717
785
|
return this.#map.size;
|
|
718
786
|
}
|
|
719
787
|
};
|
|
720
|
-
|
|
721
|
-
//#region src/mapChunked.ts
|
|
788
|
+
// src/mapChunked.ts
|
|
722
789
|
const runChunkedProject = (project, options, value, index) => new rxjs.Observable((subscriber) => {
|
|
723
790
|
const controller = new AbortController();
|
|
724
791
|
project(value, {
|
|
@@ -755,15 +822,13 @@ const switchMapChunked = (project, options) => (0, rxjs.switchMap)((value, index
|
|
|
755
822
|
* still aborts it).
|
|
756
823
|
*/
|
|
757
824
|
const concatMapChunked = (project, options) => (0, rxjs.concatMap)((value, index) => runChunkedProject(project, options, value, index));
|
|
758
|
-
|
|
759
|
-
//#region src/planckToTokens.ts
|
|
825
|
+
// src/planckToTokens.ts
|
|
760
826
|
function planckToTokens(planck, tokenDecimals) {
|
|
761
827
|
if (typeof planck !== "string" || typeof tokenDecimals !== "number") return;
|
|
762
828
|
const multiplier = 10 ** (-1 * tokenDecimals);
|
|
763
829
|
return new configureBigNumber_default(planck).multipliedBy(multiplier).toString(10);
|
|
764
830
|
}
|
|
765
|
-
|
|
766
|
-
//#region src/replaySubjectFrom.ts
|
|
831
|
+
// src/replaySubjectFrom.ts
|
|
767
832
|
/**
|
|
768
833
|
* Turns a value into a {@link ReplaySubject} of size 1.
|
|
769
834
|
*
|
|
@@ -784,14 +849,12 @@ const replaySubjectFrom = (initialValue) => {
|
|
|
784
849
|
subject.next(initialValue);
|
|
785
850
|
return subject;
|
|
786
851
|
};
|
|
787
|
-
|
|
788
|
-
//#region src/sleep.ts
|
|
852
|
+
// src/sleep.ts
|
|
789
853
|
const sleep = (ms) => new Promise((resolve) => {
|
|
790
854
|
if (process.env.NODE_ENV === "test") resolve();
|
|
791
855
|
else setTimeout(resolve, ms);
|
|
792
856
|
});
|
|
793
|
-
|
|
794
|
-
//#region src/splitSubject.ts
|
|
857
|
+
// src/splitSubject.ts
|
|
795
858
|
/**
|
|
796
859
|
* Takes a subject and splits it into two parts:
|
|
797
860
|
*
|
|
@@ -805,8 +868,7 @@ function splitSubject(subject) {
|
|
|
805
868
|
const next = (value) => subject.next(value);
|
|
806
869
|
return [next, subject.asObservable()];
|
|
807
870
|
}
|
|
808
|
-
|
|
809
|
-
//#region src/stripHexPrefix.ts
|
|
871
|
+
// src/stripHexPrefix.ts
|
|
810
872
|
/**
|
|
811
873
|
* @name stripHexPrefix
|
|
812
874
|
* @description Removes a leading `0x` prefix from a string, if present.
|
|
@@ -817,18 +879,15 @@ function splitSubject(subject) {
|
|
|
817
879
|
* stripHexPrefix("1234") // "1234"
|
|
818
880
|
**/
|
|
819
881
|
const stripHexPrefix = (str) => str.startsWith("0x") ? str.slice(2) : str;
|
|
820
|
-
|
|
821
|
-
//#region src/throwAfter.ts
|
|
882
|
+
// src/throwAfter.ts
|
|
822
883
|
const throwAfter = (ms, reason) => new Promise((_, reject) => setTimeout(() => reject(new Error(reason)), ms));
|
|
823
|
-
|
|
824
|
-
//#region src/tokensToPlanck.ts
|
|
884
|
+
// src/tokensToPlanck.ts
|
|
825
885
|
function tokensToPlanck(tokens, tokenDecimals) {
|
|
826
886
|
if (typeof tokens !== "string" || typeof tokenDecimals !== "number") return;
|
|
827
887
|
const multiplier = 10 ** tokenDecimals;
|
|
828
888
|
return new configureBigNumber_default(tokens).multipliedBy(multiplier).toString(10);
|
|
829
889
|
}
|
|
830
|
-
|
|
831
|
-
//#region src/validateArrayWithYield.ts
|
|
890
|
+
// src/validateArrayWithYield.ts
|
|
832
891
|
/**
|
|
833
892
|
* Validates every item of an array within a cooperative time budget, yielding the thread
|
|
834
893
|
* to the host event loop whenever the budget for the current slice is exhausted.
|
|
@@ -856,8 +915,7 @@ const validateArrayWithYield = async (items, parseItem, options) => {
|
|
|
856
915
|
data
|
|
857
916
|
};
|
|
858
917
|
};
|
|
859
|
-
|
|
860
|
-
//#region src/validateHexString.ts
|
|
918
|
+
// src/validateHexString.ts
|
|
861
919
|
/**
|
|
862
920
|
* @name validateHexString
|
|
863
921
|
* @description Checks if a string is a hex string. Required to account for type differences between different polkadot libraries
|
|
@@ -873,7 +931,6 @@ const validateHexString = (str) => {
|
|
|
873
931
|
if (str.startsWith("0x")) return str;
|
|
874
932
|
throw new Error("Expected a hex string");
|
|
875
933
|
};
|
|
876
|
-
//#endregion
|
|
877
934
|
exports.BigMath = BigMath;
|
|
878
935
|
exports.DEFAULT_TIME_SLICE_BUDGET_MS = DEFAULT_TIME_SLICE_BUDGET_MS;
|
|
879
936
|
exports.Deferred = Deferred;
|
|
@@ -887,8 +944,12 @@ exports.concatMapChunked = concatMapChunked;
|
|
|
887
944
|
exports.createTimeSlicer = createTimeSlicer;
|
|
888
945
|
exports.firstThenDebounce = firstThenDebounce;
|
|
889
946
|
exports.forEachWithYield = forEachWithYield;
|
|
947
|
+
exports.formatCompactPrice = formatCompactPrice;
|
|
948
|
+
exports.formatCurrency = formatCurrency;
|
|
949
|
+
exports.formatCurrencyToParts = formatCurrencyToParts;
|
|
890
950
|
exports.formatDecimals = formatDecimals;
|
|
891
951
|
exports.formatPrice = formatPrice;
|
|
952
|
+
exports.getCurrencyFractionDigits = getCurrencyFractionDigits;
|
|
892
953
|
exports.getErrorMessage = getErrorMessage;
|
|
893
954
|
exports.getLoadable$ = getLoadable$;
|
|
894
955
|
exports.getLoadableQuery$ = getLoadableQuery$;
|