@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.mjs
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
2
|
import { isEqual } from "lodash-es";
|
|
3
3
|
import { BehaviorSubject, Observable, ReplaySubject, Subject, catchError, concat, concatMap, debounceTime, distinctUntilChanged, from, map, of, shareReplay, skip, startWith, switchMap, take, tap, timer } from "rxjs";
|
|
4
|
-
|
|
4
|
+
// src/configureBigNumber.ts
|
|
5
5
|
BigNumber.set({ STRICT: false });
|
|
6
6
|
var configureBigNumber_default = BigNumber;
|
|
7
|
-
|
|
8
|
-
//#region src/addTrailingSlash.ts
|
|
7
|
+
// src/addTrailingSlash.ts
|
|
9
8
|
const addTrailingSlash = (url) => {
|
|
10
9
|
if (url.endsWith("/")) return url;
|
|
11
10
|
return `${url}/`;
|
|
12
11
|
};
|
|
13
|
-
|
|
14
|
-
//#region src/assert.ts
|
|
12
|
+
// src/assert.ts
|
|
15
13
|
/**
|
|
16
14
|
* @name assert
|
|
17
15
|
* @description Throws an Error with the given message if the condition is falsy.
|
|
@@ -22,8 +20,7 @@ function assert(condition, message) {
|
|
|
22
20
|
if (condition) return;
|
|
23
21
|
throw new Error(typeof message === "function" ? message() : message);
|
|
24
22
|
}
|
|
25
|
-
|
|
26
|
-
//#region src/BigMath.ts
|
|
23
|
+
// src/BigMath.ts
|
|
27
24
|
/**
|
|
28
25
|
* Javascript's `Math` library for `BigInt`.
|
|
29
26
|
* Taken from https://stackoverflow.com/questions/51867270/is-there-a-library-similar-to-math-that-supports-javascript-bigint/64953280#64953280
|
|
@@ -45,14 +42,12 @@ const BigMath = {
|
|
|
45
42
|
return value;
|
|
46
43
|
}
|
|
47
44
|
};
|
|
48
|
-
|
|
49
|
-
//#region src/isHexString.ts
|
|
45
|
+
// src/isHexString.ts
|
|
50
46
|
const REGEX_HEX_STRING = /^0x[0-9a-fA-F]*$/;
|
|
51
47
|
const isHexString = (value) => {
|
|
52
48
|
return typeof value === "string" && REGEX_HEX_STRING.test(value);
|
|
53
49
|
};
|
|
54
|
-
|
|
55
|
-
//#region src/bytes.ts
|
|
50
|
+
// src/bytes.ts
|
|
56
51
|
/**
|
|
57
52
|
* Byte / hex primitives, drop-in equivalents of the `@polkadot/util` helpers we used to depend on.
|
|
58
53
|
* Semantics intentionally match polkadot-js for migration safety.
|
|
@@ -65,10 +60,11 @@ const hexToU8a = (hex) => {
|
|
|
65
60
|
for (let i = 0; i < result.length; i++) result[i] = parseInt(padded.substring(i * 2, i * 2 + 2), 16);
|
|
66
61
|
return result;
|
|
67
62
|
};
|
|
63
|
+
const HEX_BYTES = Array.from({ length: 256 }, (_, byte) => byte.toString(16).padStart(2, "0"));
|
|
68
64
|
const u8aToHex = (value) => {
|
|
69
65
|
if (!value?.length) return "0x";
|
|
70
66
|
let hex = "";
|
|
71
|
-
for (const byte of value) hex += byte
|
|
67
|
+
for (const byte of value) hex += HEX_BYTES[byte];
|
|
72
68
|
return `0x${hex}`;
|
|
73
69
|
};
|
|
74
70
|
const stringToU8a = (value) => value ? new TextEncoder().encode(value) : /* @__PURE__ */ new Uint8Array();
|
|
@@ -133,15 +129,15 @@ const u8aUnwrapBytes = (value) => {
|
|
|
133
129
|
const u8a = u8aToU8a(value);
|
|
134
130
|
return u8aIsWrapped(u8a) ? u8a.subarray(U8A_WRAP_PREFIX.length, u8a.length - U8A_WRAP_POSTFIX.length) : u8a;
|
|
135
131
|
};
|
|
136
|
-
|
|
137
|
-
//#region src/jsActivityHook.ts
|
|
132
|
+
// src/jsActivityHook.ts
|
|
138
133
|
const reportJsActivity = (label, durationMs) => {
|
|
139
134
|
const record = globalThis.__recordJsActivity;
|
|
140
135
|
if (record) record(label, durationMs);
|
|
141
136
|
};
|
|
142
|
-
|
|
143
|
-
//#region src/yieldToEventLoop.ts
|
|
137
|
+
// src/yieldToEventLoop.ts
|
|
144
138
|
const yieldToEventLoop = () => {
|
|
139
|
+
const { scheduler } = globalThis;
|
|
140
|
+
if (typeof scheduler?.postTask === "function") return scheduler.postTask(() => {}, { priority: "background" });
|
|
145
141
|
if (typeof MessageChannel !== "undefined") return new Promise((resolve) => {
|
|
146
142
|
const channel = new MessageChannel();
|
|
147
143
|
const port1 = channel.port1;
|
|
@@ -155,8 +151,7 @@ const yieldToEventLoop = () => {
|
|
|
155
151
|
});
|
|
156
152
|
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
157
153
|
};
|
|
158
|
-
|
|
159
|
-
//#region src/timeSlicer.ts
|
|
154
|
+
// src/timeSlicer.ts
|
|
160
155
|
/**
|
|
161
156
|
* Default CPU budget for a single synchronous slice of chunked work.
|
|
162
157
|
* ~50-60% of a 60fps frame, leaving the rest for the host (user interactions, rendering).
|
|
@@ -199,8 +194,7 @@ const createTimeSlicer = ({ budgetMs = 10, signal, now = defaultNow, label } = {
|
|
|
199
194
|
throwIfAborted
|
|
200
195
|
};
|
|
201
196
|
};
|
|
202
|
-
|
|
203
|
-
//#region src/chunkedArray.ts
|
|
197
|
+
// src/chunkedArray.ts
|
|
204
198
|
const getSlicer = (options) => options?.slicer ?? createTimeSlicer({
|
|
205
199
|
budgetMs: options?.budgetMs,
|
|
206
200
|
signal: options?.signal,
|
|
@@ -253,8 +247,7 @@ const arrayItemsEqualWithYield = async (a, b, options) => {
|
|
|
253
247
|
}
|
|
254
248
|
return true;
|
|
255
249
|
};
|
|
256
|
-
|
|
257
|
-
//#region src/deferred.ts
|
|
250
|
+
// src/deferred.ts
|
|
258
251
|
/**
|
|
259
252
|
* In TypeScript, a deferred promise refers to a pattern that involves creating a promise that can be
|
|
260
253
|
* resolved or rejected at a later point in time, typically by code outside of the current function scope.
|
|
@@ -288,8 +281,7 @@ function Deferred() {
|
|
|
288
281
|
isRejected: () => isRejected
|
|
289
282
|
};
|
|
290
283
|
}
|
|
291
|
-
|
|
292
|
-
//#region src/firstThenDebounce.ts
|
|
284
|
+
// src/firstThenDebounce.ts
|
|
293
285
|
/**
|
|
294
286
|
* An rxjs operator which:
|
|
295
287
|
*
|
|
@@ -297,8 +289,90 @@ function Deferred() {
|
|
|
297
289
|
* 2. Debounces any future values by `timeout` ms.
|
|
298
290
|
*/
|
|
299
291
|
const firstThenDebounce = (timeout) => (source) => concat(source.pipe(take(1)), source.pipe(skip(1)).pipe(debounceTime(timeout)));
|
|
300
|
-
|
|
301
|
-
|
|
292
|
+
// src/formatCurrency.ts
|
|
293
|
+
const INTL_CURRENCY_OVERRIDES = {
|
|
294
|
+
btc: {
|
|
295
|
+
symbol: "₿",
|
|
296
|
+
fractionDigits: 6
|
|
297
|
+
},
|
|
298
|
+
eth: {
|
|
299
|
+
symbol: "Ξ",
|
|
300
|
+
fractionDigits: 5
|
|
301
|
+
},
|
|
302
|
+
tao: {
|
|
303
|
+
symbol: "τ",
|
|
304
|
+
fractionDigits: 4
|
|
305
|
+
},
|
|
306
|
+
idr: { fractionDigits: 0 }
|
|
307
|
+
};
|
|
308
|
+
const INTL_MAX_FRACTION_DIGITS = 20;
|
|
309
|
+
const clampFractionDigits = (digits) => digits === void 0 ? void 0 : Math.min(digits, INTL_MAX_FRACTION_DIGITS);
|
|
310
|
+
const fractionDigitsByCurrency = /* @__PURE__ */ new Map();
|
|
311
|
+
const getCurrencyFractionDigits = (currency) => {
|
|
312
|
+
const currencyId = currency.toLowerCase();
|
|
313
|
+
const cached = fractionDigitsByCurrency.get(currencyId);
|
|
314
|
+
if (cached !== void 0) return cached;
|
|
315
|
+
const { maximumFractionDigits: intlFractionDigits = 2 } = new Intl.NumberFormat(void 0, {
|
|
316
|
+
style: "currency",
|
|
317
|
+
currency
|
|
318
|
+
}).resolvedOptions();
|
|
319
|
+
const fractionDigits = INTL_CURRENCY_OVERRIDES[currencyId]?.fractionDigits ?? intlFractionDigits;
|
|
320
|
+
fractionDigitsByCurrency.set(currencyId, fractionDigits);
|
|
321
|
+
return fractionDigits;
|
|
322
|
+
};
|
|
323
|
+
const getDefaultFractionDigits = (currencyId, options) => {
|
|
324
|
+
if ([
|
|
325
|
+
options.minimumFractionDigits,
|
|
326
|
+
options.maximumFractionDigits,
|
|
327
|
+
options.minimumSignificantDigits,
|
|
328
|
+
options.maximumSignificantDigits
|
|
329
|
+
].some((digits) => digits !== void 0) || options.notation === "compact") return void 0;
|
|
330
|
+
return INTL_CURRENCY_OVERRIDES[currencyId]?.fractionDigits;
|
|
331
|
+
};
|
|
332
|
+
const isSpacing = (part) => part?.type === "literal" && part.value.trim() === "";
|
|
333
|
+
const withTrailingCode = (parts, code) => {
|
|
334
|
+
const currencyIndex = parts.findIndex((part) => part.type === "currency");
|
|
335
|
+
const number = parts.filter((part, index) => index !== currencyIndex && !(isSpacing(part) && Math.abs(index - currencyIndex) === 1));
|
|
336
|
+
while (isSpacing(number[0])) number.shift();
|
|
337
|
+
while (isSpacing(number.at(-1))) number.pop();
|
|
338
|
+
return [
|
|
339
|
+
...number,
|
|
340
|
+
{
|
|
341
|
+
type: "literal",
|
|
342
|
+
value: " "
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
type: "currency",
|
|
346
|
+
value: code
|
|
347
|
+
}
|
|
348
|
+
];
|
|
349
|
+
};
|
|
350
|
+
const formatCurrencyToParts = (amount, currency, options = {}) => {
|
|
351
|
+
const currencyId = currency.toLowerCase();
|
|
352
|
+
const currencyDisplay = options.currencyDisplay ?? (currencyId === "usd" ? "narrowSymbol" : "symbol");
|
|
353
|
+
const defaultFractionDigits = getDefaultFractionDigits(currencyId, options);
|
|
354
|
+
const intlOptions = {
|
|
355
|
+
...options,
|
|
356
|
+
style: "currency",
|
|
357
|
+
currency,
|
|
358
|
+
currencyDisplay,
|
|
359
|
+
minimumFractionDigits: clampFractionDigits(options.minimumFractionDigits ?? defaultFractionDigits),
|
|
360
|
+
maximumFractionDigits: clampFractionDigits(options.maximumFractionDigits ?? defaultFractionDigits)
|
|
361
|
+
};
|
|
362
|
+
if (currencyDisplay === "code") return withTrailingCode(new Intl.NumberFormat(void 0, intlOptions).formatToParts(amount), currency.toUpperCase());
|
|
363
|
+
const symbol = currencyDisplay === "name" ? void 0 : INTL_CURRENCY_OVERRIDES[currencyId]?.symbol;
|
|
364
|
+
if (!symbol) return new Intl.NumberFormat(void 0, intlOptions).formatToParts(amount);
|
|
365
|
+
return new Intl.NumberFormat(void 0, {
|
|
366
|
+
...intlOptions,
|
|
367
|
+
currency: "USD",
|
|
368
|
+
currencyDisplay: "narrowSymbol"
|
|
369
|
+
}).formatToParts(amount).map((part) => part.type === "currency" ? {
|
|
370
|
+
...part,
|
|
371
|
+
value: symbol
|
|
372
|
+
} : part);
|
|
373
|
+
};
|
|
374
|
+
const formatCurrency = (amount, currency, options = {}) => formatCurrencyToParts(amount, currency, options).map((part) => part.value).join("");
|
|
375
|
+
// src/formatDecimals.ts
|
|
302
376
|
const MIN_DIGITS = 4;
|
|
303
377
|
const MAX_DECIMALS_FORMAT = 12;
|
|
304
378
|
/**
|
|
@@ -330,28 +404,39 @@ const formatDecimals = (num, digits = MIN_DIGITS, options = {}, locale = "en-US"
|
|
|
330
404
|
...options
|
|
331
405
|
}).format(truncatedValue.toNumber());
|
|
332
406
|
};
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
407
|
+
// src/formatPrice.ts
|
|
408
|
+
const getPriceOptions = (price, compact) => ({
|
|
409
|
+
minimumSignificantDigits: 3,
|
|
410
|
+
maximumSignificantDigits: compact ? price < 1 ? 3 : 4 : void 0,
|
|
411
|
+
roundingPriority: compact ? "auto" : "morePrecision",
|
|
412
|
+
notation: compact ? "compact" : "standard"
|
|
413
|
+
});
|
|
414
|
+
const formatPrice = (price, currency, compact) => formatCurrency(price, currency, getPriceOptions(price, compact));
|
|
415
|
+
const MIN_COLLAPSED_ZEROS = 4;
|
|
416
|
+
const formatCompactPrice = (price, currency) => {
|
|
417
|
+
const parts = formatCurrencyToParts(price, currency, getPriceOptions(price, true));
|
|
418
|
+
const joinParts = (from, to) => parts.slice(from, to).map((part) => part.value).join("");
|
|
419
|
+
const fractionIndex = parts.findIndex((part) => part.type === "fraction");
|
|
420
|
+
const integer = parts.find((part) => part.type === "integer")?.value;
|
|
421
|
+
const match = /^(0+)([1-9]\d*?)0*$/.exec(parts[fractionIndex]?.value ?? "");
|
|
422
|
+
if (integer !== "0" || !match || match[1].length < MIN_COLLAPSED_ZEROS) return {
|
|
423
|
+
kind: "plain",
|
|
424
|
+
text: joinParts(0)
|
|
425
|
+
};
|
|
426
|
+
return {
|
|
427
|
+
kind: "collapsedZeros",
|
|
428
|
+
head: joinParts(0, fractionIndex),
|
|
429
|
+
zeroCount: match[1].length,
|
|
430
|
+
tail: match[2] + joinParts(fractionIndex + 1)
|
|
431
|
+
};
|
|
432
|
+
};
|
|
433
|
+
// src/getErrorMessage.ts
|
|
348
434
|
const getErrorMessage = (error, fallback = "Unknown error") => {
|
|
349
435
|
if (typeof error === "string") return error || fallback;
|
|
350
436
|
if (error && typeof error === "object" && "message" in error && typeof error.message === "string") return error.message || fallback;
|
|
351
437
|
return fallback;
|
|
352
438
|
};
|
|
353
|
-
|
|
354
|
-
//#region src/getLoadable.ts
|
|
439
|
+
// src/getLoadable.ts
|
|
355
440
|
function getLoadable$(factory, options = {}) {
|
|
356
441
|
const { getError, refreshInterval } = options;
|
|
357
442
|
const createLoadableStream = () => from(factory()).pipe(map((data) => ({
|
|
@@ -367,8 +452,7 @@ const getGenericError = (error) => ({
|
|
|
367
452
|
name: "Error",
|
|
368
453
|
message: getErrorMessage(error)
|
|
369
454
|
});
|
|
370
|
-
|
|
371
|
-
//#region src/getSharedObservable.ts
|
|
455
|
+
// src/getSharedObservable.ts
|
|
372
456
|
const CACHE = /* @__PURE__ */ new Map();
|
|
373
457
|
/**
|
|
374
458
|
* How long an entry survives with no subscribers before being dropped. Long enough
|
|
@@ -428,8 +512,7 @@ const getSharedObservable = (namespace, args, createObservable, serializer = (ar
|
|
|
428
512
|
scheduleCleanup(entry);
|
|
429
513
|
return entry.observable;
|
|
430
514
|
};
|
|
431
|
-
|
|
432
|
-
//#region src/getQuery.ts
|
|
515
|
+
// src/getQuery.ts
|
|
433
516
|
/**
|
|
434
517
|
* Creates a shared observable for executing queries with caching, loading states, and automatic refresh capabilities.
|
|
435
518
|
*
|
|
@@ -494,8 +577,7 @@ const getQuery$ = ({ namespace, args, queryFn, defaultValue, refreshInterval, se
|
|
|
494
577
|
bufferSize: 1
|
|
495
578
|
})), serializer);
|
|
496
579
|
};
|
|
497
|
-
|
|
498
|
-
//#region src/getLoadableQuery.ts
|
|
580
|
+
// src/getLoadableQuery.ts
|
|
499
581
|
/**
|
|
500
582
|
* Thin wrapper around getQuery$ that returns Loadable<T> and optionally
|
|
501
583
|
* primes the stream with a loading state using the provided default value.
|
|
@@ -530,38 +612,31 @@ const getLoadableQuery$ = (params) => {
|
|
|
530
612
|
}
|
|
531
613
|
}), startWith(...initial));
|
|
532
614
|
};
|
|
533
|
-
|
|
534
|
-
//#region src/hasOwnProperty.ts
|
|
615
|
+
// src/hasOwnProperty.ts
|
|
535
616
|
function hasOwnProperty(obj, prop) {
|
|
536
617
|
if (typeof obj !== "object") return false;
|
|
537
618
|
if (obj === null) return false;
|
|
538
619
|
return prop in obj;
|
|
539
620
|
}
|
|
540
|
-
|
|
541
|
-
//#region src/isAbortError.ts
|
|
621
|
+
// src/isAbortError.ts
|
|
542
622
|
const isAbortError = (error) => {
|
|
543
623
|
return error instanceof Error && error.name === "AbortError";
|
|
544
624
|
};
|
|
545
|
-
|
|
546
|
-
//#region src/isArrayOf.ts
|
|
625
|
+
// src/isArrayOf.ts
|
|
547
626
|
function isArrayOf(array, func) {
|
|
548
627
|
if (array.length > 0 && array[0] instanceof func) return true;
|
|
549
628
|
return false;
|
|
550
629
|
}
|
|
551
|
-
|
|
552
|
-
//#region src/isAscii.ts
|
|
630
|
+
// src/isAscii.ts
|
|
553
631
|
const isAscii = (str) => {
|
|
554
632
|
return [...str].every((char) => char.charCodeAt(0) <= 127);
|
|
555
633
|
};
|
|
556
|
-
|
|
557
|
-
//#region src/isBigInt.ts
|
|
634
|
+
// src/isBigInt.ts
|
|
558
635
|
const isBigInt = (value) => typeof value === "bigint";
|
|
559
|
-
|
|
560
|
-
//#region src/isBooleanTrue.ts
|
|
636
|
+
// src/isBooleanTrue.ts
|
|
561
637
|
/** @deprecated use isTruthy instead */
|
|
562
638
|
const isBooleanTrue = (x) => !!x;
|
|
563
|
-
|
|
564
|
-
//#region src/isErrorOfName.ts
|
|
639
|
+
// src/isErrorOfName.ts
|
|
565
640
|
/**
|
|
566
641
|
* Robust replacement for `error instanceof SomeErrorClass` when the class comes from a
|
|
567
642
|
* package that gets bundled into multiple chunks/contexts (e.g. viem, @solana/web3.js).
|
|
@@ -574,8 +649,7 @@ const isBooleanTrue = (x) => !!x;
|
|
|
574
649
|
* duck-type the shape instead.
|
|
575
650
|
*/
|
|
576
651
|
const isErrorOfName = (error, ...names) => error instanceof Error && names.includes(error.name);
|
|
577
|
-
|
|
578
|
-
//#region src/isNotNil.ts
|
|
652
|
+
// src/isNotNil.ts
|
|
579
653
|
/**
|
|
580
654
|
* WARNING: This function only checks against null or undefined, it does not coerce the value.
|
|
581
655
|
* ie: false and 0 are considered not nil
|
|
@@ -585,11 +659,9 @@ const isErrorOfName = (error, ...names) => error instanceof Error && names.inclu
|
|
|
585
659
|
* @returns whether the value is neither null nor undefined
|
|
586
660
|
*/
|
|
587
661
|
const isNotNil = (value) => value !== null && value !== void 0;
|
|
588
|
-
|
|
589
|
-
//#region src/isPromise.ts
|
|
662
|
+
// src/isPromise.ts
|
|
590
663
|
const isPromise = (value) => !!value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
591
|
-
|
|
592
|
-
//#region src/isSubject.ts
|
|
664
|
+
// src/isSubject.ts
|
|
593
665
|
/**
|
|
594
666
|
* Tests to see if an object is an RxJS {@link Subject}.
|
|
595
667
|
*/
|
|
@@ -610,11 +682,9 @@ function isFn(value) {
|
|
|
610
682
|
function isBool(value) {
|
|
611
683
|
return typeof value === "boolean";
|
|
612
684
|
}
|
|
613
|
-
|
|
614
|
-
//#region src/isTruthy.ts
|
|
685
|
+
// src/isTruthy.ts
|
|
615
686
|
const isTruthy = (value) => Boolean(value);
|
|
616
|
-
|
|
617
|
-
//#region src/keepAlive.ts
|
|
687
|
+
// src/keepAlive.ts
|
|
618
688
|
/**
|
|
619
689
|
* An RxJS operator that keeps the source observable alive for a specified duration
|
|
620
690
|
* after all subscribers have unsubscribed. This prevents expensive re-subscriptions
|
|
@@ -648,8 +718,7 @@ const keepSourceSubscribed = (observable, ms) => {
|
|
|
648
718
|
const sub = observable.subscribe();
|
|
649
719
|
return () => setTimeout(() => sub.unsubscribe(), ms);
|
|
650
720
|
};
|
|
651
|
-
|
|
652
|
-
//#region src/lruMap.ts
|
|
721
|
+
// src/lruMap.ts
|
|
653
722
|
/**
|
|
654
723
|
* A Map with a maximum size and least-recently-used eviction.
|
|
655
724
|
*
|
|
@@ -693,8 +762,7 @@ var LruMap = class {
|
|
|
693
762
|
return this.#map.size;
|
|
694
763
|
}
|
|
695
764
|
};
|
|
696
|
-
|
|
697
|
-
//#region src/mapChunked.ts
|
|
765
|
+
// src/mapChunked.ts
|
|
698
766
|
const runChunkedProject = (project, options, value, index) => new Observable((subscriber) => {
|
|
699
767
|
const controller = new AbortController();
|
|
700
768
|
project(value, {
|
|
@@ -731,15 +799,13 @@ const switchMapChunked = (project, options) => switchMap((value, index) => runCh
|
|
|
731
799
|
* still aborts it).
|
|
732
800
|
*/
|
|
733
801
|
const concatMapChunked = (project, options) => concatMap((value, index) => runChunkedProject(project, options, value, index));
|
|
734
|
-
|
|
735
|
-
//#region src/planckToTokens.ts
|
|
802
|
+
// src/planckToTokens.ts
|
|
736
803
|
function planckToTokens(planck, tokenDecimals) {
|
|
737
804
|
if (typeof planck !== "string" || typeof tokenDecimals !== "number") return;
|
|
738
805
|
const multiplier = 10 ** (-1 * tokenDecimals);
|
|
739
806
|
return new configureBigNumber_default(planck).multipliedBy(multiplier).toString(10);
|
|
740
807
|
}
|
|
741
|
-
|
|
742
|
-
//#region src/replaySubjectFrom.ts
|
|
808
|
+
// src/replaySubjectFrom.ts
|
|
743
809
|
/**
|
|
744
810
|
* Turns a value into a {@link ReplaySubject} of size 1.
|
|
745
811
|
*
|
|
@@ -760,14 +826,12 @@ const replaySubjectFrom = (initialValue) => {
|
|
|
760
826
|
subject.next(initialValue);
|
|
761
827
|
return subject;
|
|
762
828
|
};
|
|
763
|
-
|
|
764
|
-
//#region src/sleep.ts
|
|
829
|
+
// src/sleep.ts
|
|
765
830
|
const sleep = (ms) => new Promise((resolve) => {
|
|
766
831
|
if (process.env.NODE_ENV === "test") resolve();
|
|
767
832
|
else setTimeout(resolve, ms);
|
|
768
833
|
});
|
|
769
|
-
|
|
770
|
-
//#region src/splitSubject.ts
|
|
834
|
+
// src/splitSubject.ts
|
|
771
835
|
/**
|
|
772
836
|
* Takes a subject and splits it into two parts:
|
|
773
837
|
*
|
|
@@ -781,8 +845,7 @@ function splitSubject(subject) {
|
|
|
781
845
|
const next = (value) => subject.next(value);
|
|
782
846
|
return [next, subject.asObservable()];
|
|
783
847
|
}
|
|
784
|
-
|
|
785
|
-
//#region src/stripHexPrefix.ts
|
|
848
|
+
// src/stripHexPrefix.ts
|
|
786
849
|
/**
|
|
787
850
|
* @name stripHexPrefix
|
|
788
851
|
* @description Removes a leading `0x` prefix from a string, if present.
|
|
@@ -793,18 +856,15 @@ function splitSubject(subject) {
|
|
|
793
856
|
* stripHexPrefix("1234") // "1234"
|
|
794
857
|
**/
|
|
795
858
|
const stripHexPrefix = (str) => str.startsWith("0x") ? str.slice(2) : str;
|
|
796
|
-
|
|
797
|
-
//#region src/throwAfter.ts
|
|
859
|
+
// src/throwAfter.ts
|
|
798
860
|
const throwAfter = (ms, reason) => new Promise((_, reject) => setTimeout(() => reject(new Error(reason)), ms));
|
|
799
|
-
|
|
800
|
-
//#region src/tokensToPlanck.ts
|
|
861
|
+
// src/tokensToPlanck.ts
|
|
801
862
|
function tokensToPlanck(tokens, tokenDecimals) {
|
|
802
863
|
if (typeof tokens !== "string" || typeof tokenDecimals !== "number") return;
|
|
803
864
|
const multiplier = 10 ** tokenDecimals;
|
|
804
865
|
return new configureBigNumber_default(tokens).multipliedBy(multiplier).toString(10);
|
|
805
866
|
}
|
|
806
|
-
|
|
807
|
-
//#region src/validateArrayWithYield.ts
|
|
867
|
+
// src/validateArrayWithYield.ts
|
|
808
868
|
/**
|
|
809
869
|
* Validates every item of an array within a cooperative time budget, yielding the thread
|
|
810
870
|
* to the host event loop whenever the budget for the current slice is exhausted.
|
|
@@ -832,8 +892,7 @@ const validateArrayWithYield = async (items, parseItem, options) => {
|
|
|
832
892
|
data
|
|
833
893
|
};
|
|
834
894
|
};
|
|
835
|
-
|
|
836
|
-
//#region src/validateHexString.ts
|
|
895
|
+
// src/validateHexString.ts
|
|
837
896
|
/**
|
|
838
897
|
* @name validateHexString
|
|
839
898
|
* @description Checks if a string is a hex string. Required to account for type differences between different polkadot libraries
|
|
@@ -849,7 +908,6 @@ const validateHexString = (str) => {
|
|
|
849
908
|
if (str.startsWith("0x")) return str;
|
|
850
909
|
throw new Error("Expected a hex string");
|
|
851
910
|
};
|
|
852
|
-
|
|
853
|
-
export { BigMath, DEFAULT_TIME_SLICE_BUDGET_MS, Deferred, LruMap, MAX_DECIMALS_FORMAT, REGEX_HEX_STRING, addTrailingSlash, arrayItemsEqualWithYield, assert, concatMapChunked, createTimeSlicer, firstThenDebounce, forEachWithYield, formatDecimals, formatPrice, getErrorMessage, getLoadable$, getLoadableQuery$, getQuery$, getSharedObservable, hasOwnProperty, hexToNumber, hexToString, hexToU8a, isAbortError, isArrayOf, isAscii, isAsciiPrintable, isBigInt, isBooleanTrue, isErrorOfName, isHexString, isNotNil, isPromise, isSubject, isTruthy, keepAlive, keyByWithYield, mapWithYield, newAbortError, numberToU8a, planckToTokens, replaySubjectFrom, reportJsActivity, sleep, splitSubject, stringToU8a, stripHexPrefix, switchMapChunked, throwAfter, tokensToPlanck, u8aCmp, u8aConcat, u8aEq, u8aToHex, u8aToString, u8aToU8a, u8aUnwrapBytes, u8aWrapBytes, validateArrayWithYield, validateHexString, yieldToEventLoop };
|
|
911
|
+
export { BigMath, DEFAULT_TIME_SLICE_BUDGET_MS, Deferred, LruMap, MAX_DECIMALS_FORMAT, REGEX_HEX_STRING, addTrailingSlash, arrayItemsEqualWithYield, assert, concatMapChunked, createTimeSlicer, firstThenDebounce, forEachWithYield, formatCompactPrice, formatCurrency, formatCurrencyToParts, formatDecimals, formatPrice, getCurrencyFractionDigits, getErrorMessage, getLoadable$, getLoadableQuery$, getQuery$, getSharedObservable, hasOwnProperty, hexToNumber, hexToString, hexToU8a, isAbortError, isArrayOf, isAscii, isAsciiPrintable, isBigInt, isBooleanTrue, isErrorOfName, isHexString, isNotNil, isPromise, isSubject, isTruthy, keepAlive, keyByWithYield, mapWithYield, newAbortError, numberToU8a, planckToTokens, replaySubjectFrom, reportJsActivity, sleep, splitSubject, stringToU8a, stripHexPrefix, switchMapChunked, throwAfter, tokensToPlanck, u8aCmp, u8aConcat, u8aEq, u8aToHex, u8aToString, u8aToU8a, u8aUnwrapBytes, u8aWrapBytes, validateArrayWithYield, validateHexString, yieldToEventLoop };
|
|
854
912
|
|
|
855
913
|
//# sourceMappingURL=index.mjs.map
|