@w3ux/utils 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/index.d.cts +269 -5
- package/index.d.ts +269 -5
- package/package.json +1 -1
- package/base.cjs +0 -194
- package/base.d.cts +0 -114
- package/base.d.ts +0 -114
- package/base.js +0 -153
- package/convert.cjs +0 -40
- package/convert.d.cts +0 -9
- package/convert.d.ts +0 -9
- package/convert.js +0 -15
- package/types.cjs +0 -20
- package/types.d.cts +0 -3
- package/types.d.ts +0 -3
- package/types.js +0 -2
- package/unit.cjs +0 -282
- package/unit.d.cts +0 -147
- package/unit.d.ts +0 -147
- package/unit.js +0 -236
package/index.d.cts
CHANGED
|
@@ -1,5 +1,269 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Ensures a number has at least the specified number of decimal places, retaining commas in the output if they are present in the input.
|
|
5
|
+
*
|
|
6
|
+
* @function minDecimalPlaces
|
|
7
|
+
* @param {string | number | BigInt} val - The input number, which can be a `string` with or without commas, a `number`, or a `BigInt`.
|
|
8
|
+
* @param {number} minDecimals - The minimum number of decimal places to enforce.
|
|
9
|
+
* @returns {string} The formatted number as a string, padded with zeros if needed to meet `minDecimals`, retaining commas if originally provided.
|
|
10
|
+
* If `val` is invalid, returns "0".
|
|
11
|
+
* @example
|
|
12
|
+
* // Pads "1,234.5" to have at least 3 decimal places, with commas
|
|
13
|
+
* minDecimalPlaces("1,234.5", 3); // returns "1,234.500"
|
|
14
|
+
*
|
|
15
|
+
* // Returns "1234.56" unchanged
|
|
16
|
+
* minDecimalPlaces(1234.56, 2); // returns "1234.56"
|
|
17
|
+
*
|
|
18
|
+
* // Pads BigInt 1234 with 2 decimals
|
|
19
|
+
* minDecimalPlaces(BigInt(1234), 2); // returns "1234.00"
|
|
20
|
+
*/
|
|
21
|
+
declare const minDecimalPlaces: (val: string | number | bigint, minDecimals: number) => string;
|
|
22
|
+
/**
|
|
23
|
+
* @name camelize
|
|
24
|
+
* @summary Converts a string of text to camelCase.
|
|
25
|
+
*/
|
|
26
|
+
declare const camelize: (str: string) => string;
|
|
27
|
+
/**
|
|
28
|
+
* @name ellipsisFn
|
|
29
|
+
* @summary Receives an address and creates ellipsis on the given string, based on parameters.
|
|
30
|
+
* @param str - The string to apply the ellipsis on
|
|
31
|
+
* @param amount - The amount of characters that the ellipsis will be
|
|
32
|
+
* @param position - where the ellipsis will apply; if center the amount of character is the
|
|
33
|
+
* same for beginning and end; if "start" or "end" then its only once the amount; defaults to "start"
|
|
34
|
+
*/
|
|
35
|
+
declare const ellipsisFn: (str: string, amount?: number, position?: "start" | "end" | "center") => string;
|
|
36
|
+
/**
|
|
37
|
+
* @name pageFromUri
|
|
38
|
+
* @summary Use url variables to load the default components upon the first page visit.
|
|
39
|
+
*/
|
|
40
|
+
declare const pageFromUri: (pathname: string, fallback: string) => string;
|
|
41
|
+
/**
|
|
42
|
+
* @name rmCommas
|
|
43
|
+
* @summary Removes the commas from a string.
|
|
44
|
+
*/
|
|
45
|
+
declare const rmCommas: (val: string) => string;
|
|
46
|
+
/**
|
|
47
|
+
* @name rmDecimals
|
|
48
|
+
* @summary Removes the decimal point and decimals from a string.
|
|
49
|
+
*/
|
|
50
|
+
declare const rmDecimals: (str: string) => string;
|
|
51
|
+
/**
|
|
52
|
+
* @name shuffle
|
|
53
|
+
* @summary Shuffle a set of objects.
|
|
54
|
+
*/
|
|
55
|
+
declare const shuffle: <T>(array: T[]) => T[];
|
|
56
|
+
/**
|
|
57
|
+
* @name withTimeout
|
|
58
|
+
* @summary Timeout a promise after a specified number of milliseconds.
|
|
59
|
+
*/
|
|
60
|
+
declare const withTimeout: (ms: number, promise: Promise<unknown>, options?: {
|
|
61
|
+
onTimeout?: () => void;
|
|
62
|
+
}) => Promise<unknown>;
|
|
63
|
+
/**
|
|
64
|
+
* @name withTimeoutThrow
|
|
65
|
+
* @summary Timeout a promise after a specified number of milliseconds by throwing an error
|
|
66
|
+
*/
|
|
67
|
+
declare const withTimeoutThrow: <T>(ms: number, promise: Promise<T>, options?: {
|
|
68
|
+
onTimeout?: () => void;
|
|
69
|
+
}) => Promise<unknown>;
|
|
70
|
+
/**
|
|
71
|
+
* @name appendOrEmpty
|
|
72
|
+
* @summary Returns ` value` if a condition is truthy, or an empty string otherwise.
|
|
73
|
+
*/
|
|
74
|
+
declare const appendOrEmpty: (condition: boolean | string | undefined, value: string) => string;
|
|
75
|
+
/**
|
|
76
|
+
* @name appendOr
|
|
77
|
+
* @summary Returns ` value` if condition is truthy, or ` fallback` otherwise.
|
|
78
|
+
*/
|
|
79
|
+
declare const appendOr: (condition: boolean | string | undefined, value: string, fallback: string) => string;
|
|
80
|
+
/**
|
|
81
|
+
* @name formatAccountSs58
|
|
82
|
+
* @summary Formats an address with the supplied ss58 prefix, or returns null if invalid.
|
|
83
|
+
*/
|
|
84
|
+
declare const formatAccountSs58: (address: string, ss58Prefix: number) => string | null;
|
|
85
|
+
/**
|
|
86
|
+
* @name removeHexPrefix
|
|
87
|
+
* @summary Takes a string str as input and returns a new string with the "0x" prefix removed if it
|
|
88
|
+
* exists at the beginning of the input string.
|
|
89
|
+
*/
|
|
90
|
+
declare const removeHexPrefix: (str: string) => string;
|
|
91
|
+
declare const eqSet: (xs: Set<any>, ys: Set<any>) => boolean;
|
|
92
|
+
declare const isSuperset: (set: Set<any>, subset: Set<any>) => boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Finds the maximum value among a list of BigInt values.
|
|
95
|
+
*
|
|
96
|
+
* @function maxBigInt
|
|
97
|
+
* @param {...bigint} values - A list of BigInt values to compare.
|
|
98
|
+
* @returns {bigint} The largest BigInt value in the provided list.
|
|
99
|
+
* @example
|
|
100
|
+
* // Returns the maximum BigInt value
|
|
101
|
+
* maxBigInt(10n, 50n, 30n, 100n, 20n); // 100n
|
|
102
|
+
*/
|
|
103
|
+
declare const maxBigInt: (...values: bigint[]) => bigint;
|
|
104
|
+
/**
|
|
105
|
+
* Finds the minimum value among a list of BigInt values.
|
|
106
|
+
*
|
|
107
|
+
* @function minBigInt
|
|
108
|
+
* @param {...bigint} values - A list of BigInt values to compare.
|
|
109
|
+
* @returns {bigint} The smallest BigInt value in the provided list.
|
|
110
|
+
* @example
|
|
111
|
+
* // Returns the minimum BigInt value
|
|
112
|
+
* minBigInt(10n, 50n, 30n, 100n, 20n); // 10n
|
|
113
|
+
*/
|
|
114
|
+
declare const minBigInt: (...values: bigint[]) => bigint;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Concatenates multiple Uint8Array instances into a single Uint8Array.
|
|
118
|
+
*
|
|
119
|
+
* @param {Uint8Array[]} u8as - An array of Uint8Array instances to concatenate.
|
|
120
|
+
* @returns {Uint8Array} A new Uint8Array containing all the input arrays concatenated.
|
|
121
|
+
*/
|
|
122
|
+
declare const u8aConcat: (...u8as: Uint8Array[]) => Uint8Array;
|
|
123
|
+
|
|
124
|
+
type AnyObject = any;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Converts an on-chain balance value from planck to a decimal value in token units.
|
|
128
|
+
*
|
|
129
|
+
* @function planckToUnit
|
|
130
|
+
* @param {number | BigInt | string} val - The balance value in planck. Accepts a `number`, `BigInt`, or `string`.
|
|
131
|
+
* @param {number} units - The number of decimal places in the token unit (10^units planck per 1 token).
|
|
132
|
+
* @returns {string} The equivalent token unit value as a decimal string.
|
|
133
|
+
* @example
|
|
134
|
+
* // Convert 1500000000000 planck to tokens with 12 decimal places
|
|
135
|
+
* planckToUnit("1500000000000", 12); // returns "1.5"
|
|
136
|
+
*/
|
|
137
|
+
declare const planckToUnit: (val: number | bigint | string, units: number) => string;
|
|
138
|
+
/**
|
|
139
|
+
* Converts a token unit value to an integer value in planck.
|
|
140
|
+
*
|
|
141
|
+
* @function unitToPlanck
|
|
142
|
+
* @param {string | number | BigInt} val - The token unit value to convert. Accepts a string, number, or BigInt.
|
|
143
|
+
* @param {number} units - The number of decimal places for conversion (10^units planck per 1 token).
|
|
144
|
+
* @returns {BigInt} The equivalent value in planck as a BigInt.
|
|
145
|
+
* @example
|
|
146
|
+
* // Convert "1.5" tokens to planck with 12 decimal places
|
|
147
|
+
* unitToPlanck("1.5", 12); // returns BigInt("1500000000000")
|
|
148
|
+
*/
|
|
149
|
+
declare const unitToPlanck: (val: string | number | bigint, units: number) => bigint;
|
|
150
|
+
/**
|
|
151
|
+
* @name remToUnit
|
|
152
|
+
* @summary Converts a rem string to a number.
|
|
153
|
+
*/
|
|
154
|
+
declare const remToUnit: (rem: string) => number;
|
|
155
|
+
/**
|
|
156
|
+
* @name capitalizeFirstLetter
|
|
157
|
+
* @summary Capitalize the first letter of a string.
|
|
158
|
+
*/
|
|
159
|
+
declare const capitalizeFirstLetter: (string: string) => string;
|
|
160
|
+
/**
|
|
161
|
+
* @name snakeToCamel
|
|
162
|
+
* @summary converts a string from snake / kebab-case to camel-case.
|
|
163
|
+
*/
|
|
164
|
+
declare const snakeToCamel: (str: string) => string;
|
|
165
|
+
/**
|
|
166
|
+
* @name setStateWithRef
|
|
167
|
+
* @summary Synchronize React state and its reference with the provided value.
|
|
168
|
+
*/
|
|
169
|
+
declare const setStateWithRef: <T>(value: T, setState: (_state: T) => void, ref: RefObject<T>) => void;
|
|
170
|
+
/**
|
|
171
|
+
* @name localStorageOrDefault
|
|
172
|
+
* @summary Retrieve the local stroage value with the key, return defult value if it is not
|
|
173
|
+
* found.
|
|
174
|
+
*/
|
|
175
|
+
declare const localStorageOrDefault: <T>(key: string, _default: T, parse?: boolean) => T | string;
|
|
176
|
+
/**
|
|
177
|
+
* @name isValidAddress
|
|
178
|
+
* @summary Return whether an address is valid Substrate address.
|
|
179
|
+
*/
|
|
180
|
+
declare const isValidAddress: (address: string) => boolean;
|
|
181
|
+
/**
|
|
182
|
+
* @name extractUrlValue
|
|
183
|
+
* @summary Extracts a URL value from a URL string.
|
|
184
|
+
*/
|
|
185
|
+
declare const extractUrlValue: (key: string, url?: string) => string | null;
|
|
186
|
+
/**
|
|
187
|
+
* @name varToUrlHash
|
|
188
|
+
* @summary Puts a variable into the URL hash as a param.
|
|
189
|
+
* @description
|
|
190
|
+
* Since url variables are added to the hash and are not treated as URL params, the params are split
|
|
191
|
+
* and parsed into a `URLSearchParams`.
|
|
192
|
+
*/
|
|
193
|
+
declare const varToUrlHash: (key: string, val: string, addIfMissing: boolean) => void;
|
|
194
|
+
/**
|
|
195
|
+
* @name removeVarFromUrlHash
|
|
196
|
+
* @summary
|
|
197
|
+
* Removes a variable `key` from the URL hash if it exists. Removes dangling `?` if no URL variables
|
|
198
|
+
* exist.
|
|
199
|
+
*/
|
|
200
|
+
declare const removeVarFromUrlHash: (key: string) => void;
|
|
201
|
+
/**
|
|
202
|
+
* @name sortWithNull
|
|
203
|
+
* @summary Sorts an array with nulls last.
|
|
204
|
+
*/
|
|
205
|
+
declare const sortWithNull: (ascending: boolean) => (a: unknown, b: unknown) => 0 | 1 | -1;
|
|
206
|
+
/**
|
|
207
|
+
* @name applyWidthAsPadding
|
|
208
|
+
* @summary Applies width of subject to paddingRight of container.
|
|
209
|
+
*/
|
|
210
|
+
declare const applyWidthAsPadding: (subjectRef: RefObject<HTMLDivElement | null>, containerRef: RefObject<HTMLDivElement | null>) => void;
|
|
211
|
+
/**
|
|
212
|
+
* @name unescape
|
|
213
|
+
* @summary Replaces \” with “
|
|
214
|
+
*/
|
|
215
|
+
declare const unescape: (val: string) => string;
|
|
216
|
+
/**
|
|
217
|
+
* @name inChrome
|
|
218
|
+
* @summary Whether the application is rendering in Chrome.
|
|
219
|
+
*/
|
|
220
|
+
declare const inChrome: () => boolean;
|
|
221
|
+
/**
|
|
222
|
+
* @name addedTo
|
|
223
|
+
* @summary Given 2 objects and some keys, return items in the fresh object that do not exist in the
|
|
224
|
+
* stale object by matching the given common key values of both objects.
|
|
225
|
+
*/
|
|
226
|
+
declare const addedTo: (fresh: AnyObject[], stale: AnyObject[], keys: string[]) => AnyObject[];
|
|
227
|
+
/**
|
|
228
|
+
* @name removedFrom
|
|
229
|
+
* @summary Given 2 objects and some keys, return items in the stale object that do not exist in the
|
|
230
|
+
* fresh object by matching the given common key values of both objects.
|
|
231
|
+
*/
|
|
232
|
+
declare const removedFrom: (fresh: AnyObject[], stale: AnyObject[], keys: string[]) => AnyObject[];
|
|
233
|
+
/**
|
|
234
|
+
* @name matchedProperties
|
|
235
|
+
* @summary Given 2 objects and some keys, return items in object 1 that also exist in object 2 by
|
|
236
|
+
* matching the given common key values of both objects.
|
|
237
|
+
*/
|
|
238
|
+
declare const matchedProperties: (objX: AnyObject[], objY: AnyObject[], keys: string[]) => AnyObject[];
|
|
239
|
+
/**
|
|
240
|
+
* @name isValidHttpUrl
|
|
241
|
+
* @summary Give a string, return whether it is a valid http URL.
|
|
242
|
+
* @param string - The string to check.
|
|
243
|
+
*/
|
|
244
|
+
declare const isValidHttpUrl: (string: string) => boolean;
|
|
245
|
+
/**
|
|
246
|
+
* @name makeCancelable
|
|
247
|
+
* @summary Makes a promise cancellable.
|
|
248
|
+
* @param promise - The promise to make cancellable.
|
|
249
|
+
*/
|
|
250
|
+
declare const makeCancelable: (promise: Promise<AnyObject>) => {
|
|
251
|
+
promise: Promise<unknown>;
|
|
252
|
+
cancel: () => void;
|
|
253
|
+
};
|
|
254
|
+
/**
|
|
255
|
+
* @name unimplemented
|
|
256
|
+
* @summary A placeholder function to signal a deliberate unimplementation.
|
|
257
|
+
* Consumes an arbitrary number of props.
|
|
258
|
+
*/
|
|
259
|
+
declare const unimplemented: ({ ...props }: {
|
|
260
|
+
[x: string]: any;
|
|
261
|
+
}) => void;
|
|
262
|
+
/**
|
|
263
|
+
* Deep merge two objects.
|
|
264
|
+
* @param target
|
|
265
|
+
* @param ...sources
|
|
266
|
+
*/
|
|
267
|
+
declare const mergeDeep: (target: AnyObject, ...sources: AnyObject[]) => AnyObject;
|
|
268
|
+
|
|
269
|
+
export { addedTo, appendOr, appendOrEmpty, applyWidthAsPadding, camelize, capitalizeFirstLetter, ellipsisFn, eqSet, extractUrlValue, formatAccountSs58, inChrome, isSuperset, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, maxBigInt, mergeDeep, minBigInt, minDecimalPlaces, pageFromUri, planckToUnit, remToUnit, removeHexPrefix, removeVarFromUrlHash, removedFrom, rmCommas, rmDecimals, setStateWithRef, shuffle, snakeToCamel, sortWithNull, u8aConcat, unescape, unimplemented, unitToPlanck, varToUrlHash, withTimeout, withTimeoutThrow };
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,269 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Ensures a number has at least the specified number of decimal places, retaining commas in the output if they are present in the input.
|
|
5
|
+
*
|
|
6
|
+
* @function minDecimalPlaces
|
|
7
|
+
* @param {string | number | BigInt} val - The input number, which can be a `string` with or without commas, a `number`, or a `BigInt`.
|
|
8
|
+
* @param {number} minDecimals - The minimum number of decimal places to enforce.
|
|
9
|
+
* @returns {string} The formatted number as a string, padded with zeros if needed to meet `minDecimals`, retaining commas if originally provided.
|
|
10
|
+
* If `val` is invalid, returns "0".
|
|
11
|
+
* @example
|
|
12
|
+
* // Pads "1,234.5" to have at least 3 decimal places, with commas
|
|
13
|
+
* minDecimalPlaces("1,234.5", 3); // returns "1,234.500"
|
|
14
|
+
*
|
|
15
|
+
* // Returns "1234.56" unchanged
|
|
16
|
+
* minDecimalPlaces(1234.56, 2); // returns "1234.56"
|
|
17
|
+
*
|
|
18
|
+
* // Pads BigInt 1234 with 2 decimals
|
|
19
|
+
* minDecimalPlaces(BigInt(1234), 2); // returns "1234.00"
|
|
20
|
+
*/
|
|
21
|
+
declare const minDecimalPlaces: (val: string | number | bigint, minDecimals: number) => string;
|
|
22
|
+
/**
|
|
23
|
+
* @name camelize
|
|
24
|
+
* @summary Converts a string of text to camelCase.
|
|
25
|
+
*/
|
|
26
|
+
declare const camelize: (str: string) => string;
|
|
27
|
+
/**
|
|
28
|
+
* @name ellipsisFn
|
|
29
|
+
* @summary Receives an address and creates ellipsis on the given string, based on parameters.
|
|
30
|
+
* @param str - The string to apply the ellipsis on
|
|
31
|
+
* @param amount - The amount of characters that the ellipsis will be
|
|
32
|
+
* @param position - where the ellipsis will apply; if center the amount of character is the
|
|
33
|
+
* same for beginning and end; if "start" or "end" then its only once the amount; defaults to "start"
|
|
34
|
+
*/
|
|
35
|
+
declare const ellipsisFn: (str: string, amount?: number, position?: "start" | "end" | "center") => string;
|
|
36
|
+
/**
|
|
37
|
+
* @name pageFromUri
|
|
38
|
+
* @summary Use url variables to load the default components upon the first page visit.
|
|
39
|
+
*/
|
|
40
|
+
declare const pageFromUri: (pathname: string, fallback: string) => string;
|
|
41
|
+
/**
|
|
42
|
+
* @name rmCommas
|
|
43
|
+
* @summary Removes the commas from a string.
|
|
44
|
+
*/
|
|
45
|
+
declare const rmCommas: (val: string) => string;
|
|
46
|
+
/**
|
|
47
|
+
* @name rmDecimals
|
|
48
|
+
* @summary Removes the decimal point and decimals from a string.
|
|
49
|
+
*/
|
|
50
|
+
declare const rmDecimals: (str: string) => string;
|
|
51
|
+
/**
|
|
52
|
+
* @name shuffle
|
|
53
|
+
* @summary Shuffle a set of objects.
|
|
54
|
+
*/
|
|
55
|
+
declare const shuffle: <T>(array: T[]) => T[];
|
|
56
|
+
/**
|
|
57
|
+
* @name withTimeout
|
|
58
|
+
* @summary Timeout a promise after a specified number of milliseconds.
|
|
59
|
+
*/
|
|
60
|
+
declare const withTimeout: (ms: number, promise: Promise<unknown>, options?: {
|
|
61
|
+
onTimeout?: () => void;
|
|
62
|
+
}) => Promise<unknown>;
|
|
63
|
+
/**
|
|
64
|
+
* @name withTimeoutThrow
|
|
65
|
+
* @summary Timeout a promise after a specified number of milliseconds by throwing an error
|
|
66
|
+
*/
|
|
67
|
+
declare const withTimeoutThrow: <T>(ms: number, promise: Promise<T>, options?: {
|
|
68
|
+
onTimeout?: () => void;
|
|
69
|
+
}) => Promise<unknown>;
|
|
70
|
+
/**
|
|
71
|
+
* @name appendOrEmpty
|
|
72
|
+
* @summary Returns ` value` if a condition is truthy, or an empty string otherwise.
|
|
73
|
+
*/
|
|
74
|
+
declare const appendOrEmpty: (condition: boolean | string | undefined, value: string) => string;
|
|
75
|
+
/**
|
|
76
|
+
* @name appendOr
|
|
77
|
+
* @summary Returns ` value` if condition is truthy, or ` fallback` otherwise.
|
|
78
|
+
*/
|
|
79
|
+
declare const appendOr: (condition: boolean | string | undefined, value: string, fallback: string) => string;
|
|
80
|
+
/**
|
|
81
|
+
* @name formatAccountSs58
|
|
82
|
+
* @summary Formats an address with the supplied ss58 prefix, or returns null if invalid.
|
|
83
|
+
*/
|
|
84
|
+
declare const formatAccountSs58: (address: string, ss58Prefix: number) => string | null;
|
|
85
|
+
/**
|
|
86
|
+
* @name removeHexPrefix
|
|
87
|
+
* @summary Takes a string str as input and returns a new string with the "0x" prefix removed if it
|
|
88
|
+
* exists at the beginning of the input string.
|
|
89
|
+
*/
|
|
90
|
+
declare const removeHexPrefix: (str: string) => string;
|
|
91
|
+
declare const eqSet: (xs: Set<any>, ys: Set<any>) => boolean;
|
|
92
|
+
declare const isSuperset: (set: Set<any>, subset: Set<any>) => boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Finds the maximum value among a list of BigInt values.
|
|
95
|
+
*
|
|
96
|
+
* @function maxBigInt
|
|
97
|
+
* @param {...bigint} values - A list of BigInt values to compare.
|
|
98
|
+
* @returns {bigint} The largest BigInt value in the provided list.
|
|
99
|
+
* @example
|
|
100
|
+
* // Returns the maximum BigInt value
|
|
101
|
+
* maxBigInt(10n, 50n, 30n, 100n, 20n); // 100n
|
|
102
|
+
*/
|
|
103
|
+
declare const maxBigInt: (...values: bigint[]) => bigint;
|
|
104
|
+
/**
|
|
105
|
+
* Finds the minimum value among a list of BigInt values.
|
|
106
|
+
*
|
|
107
|
+
* @function minBigInt
|
|
108
|
+
* @param {...bigint} values - A list of BigInt values to compare.
|
|
109
|
+
* @returns {bigint} The smallest BigInt value in the provided list.
|
|
110
|
+
* @example
|
|
111
|
+
* // Returns the minimum BigInt value
|
|
112
|
+
* minBigInt(10n, 50n, 30n, 100n, 20n); // 10n
|
|
113
|
+
*/
|
|
114
|
+
declare const minBigInt: (...values: bigint[]) => bigint;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Concatenates multiple Uint8Array instances into a single Uint8Array.
|
|
118
|
+
*
|
|
119
|
+
* @param {Uint8Array[]} u8as - An array of Uint8Array instances to concatenate.
|
|
120
|
+
* @returns {Uint8Array} A new Uint8Array containing all the input arrays concatenated.
|
|
121
|
+
*/
|
|
122
|
+
declare const u8aConcat: (...u8as: Uint8Array[]) => Uint8Array;
|
|
123
|
+
|
|
124
|
+
type AnyObject = any;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Converts an on-chain balance value from planck to a decimal value in token units.
|
|
128
|
+
*
|
|
129
|
+
* @function planckToUnit
|
|
130
|
+
* @param {number | BigInt | string} val - The balance value in planck. Accepts a `number`, `BigInt`, or `string`.
|
|
131
|
+
* @param {number} units - The number of decimal places in the token unit (10^units planck per 1 token).
|
|
132
|
+
* @returns {string} The equivalent token unit value as a decimal string.
|
|
133
|
+
* @example
|
|
134
|
+
* // Convert 1500000000000 planck to tokens with 12 decimal places
|
|
135
|
+
* planckToUnit("1500000000000", 12); // returns "1.5"
|
|
136
|
+
*/
|
|
137
|
+
declare const planckToUnit: (val: number | bigint | string, units: number) => string;
|
|
138
|
+
/**
|
|
139
|
+
* Converts a token unit value to an integer value in planck.
|
|
140
|
+
*
|
|
141
|
+
* @function unitToPlanck
|
|
142
|
+
* @param {string | number | BigInt} val - The token unit value to convert. Accepts a string, number, or BigInt.
|
|
143
|
+
* @param {number} units - The number of decimal places for conversion (10^units planck per 1 token).
|
|
144
|
+
* @returns {BigInt} The equivalent value in planck as a BigInt.
|
|
145
|
+
* @example
|
|
146
|
+
* // Convert "1.5" tokens to planck with 12 decimal places
|
|
147
|
+
* unitToPlanck("1.5", 12); // returns BigInt("1500000000000")
|
|
148
|
+
*/
|
|
149
|
+
declare const unitToPlanck: (val: string | number | bigint, units: number) => bigint;
|
|
150
|
+
/**
|
|
151
|
+
* @name remToUnit
|
|
152
|
+
* @summary Converts a rem string to a number.
|
|
153
|
+
*/
|
|
154
|
+
declare const remToUnit: (rem: string) => number;
|
|
155
|
+
/**
|
|
156
|
+
* @name capitalizeFirstLetter
|
|
157
|
+
* @summary Capitalize the first letter of a string.
|
|
158
|
+
*/
|
|
159
|
+
declare const capitalizeFirstLetter: (string: string) => string;
|
|
160
|
+
/**
|
|
161
|
+
* @name snakeToCamel
|
|
162
|
+
* @summary converts a string from snake / kebab-case to camel-case.
|
|
163
|
+
*/
|
|
164
|
+
declare const snakeToCamel: (str: string) => string;
|
|
165
|
+
/**
|
|
166
|
+
* @name setStateWithRef
|
|
167
|
+
* @summary Synchronize React state and its reference with the provided value.
|
|
168
|
+
*/
|
|
169
|
+
declare const setStateWithRef: <T>(value: T, setState: (_state: T) => void, ref: RefObject<T>) => void;
|
|
170
|
+
/**
|
|
171
|
+
* @name localStorageOrDefault
|
|
172
|
+
* @summary Retrieve the local stroage value with the key, return defult value if it is not
|
|
173
|
+
* found.
|
|
174
|
+
*/
|
|
175
|
+
declare const localStorageOrDefault: <T>(key: string, _default: T, parse?: boolean) => T | string;
|
|
176
|
+
/**
|
|
177
|
+
* @name isValidAddress
|
|
178
|
+
* @summary Return whether an address is valid Substrate address.
|
|
179
|
+
*/
|
|
180
|
+
declare const isValidAddress: (address: string) => boolean;
|
|
181
|
+
/**
|
|
182
|
+
* @name extractUrlValue
|
|
183
|
+
* @summary Extracts a URL value from a URL string.
|
|
184
|
+
*/
|
|
185
|
+
declare const extractUrlValue: (key: string, url?: string) => string | null;
|
|
186
|
+
/**
|
|
187
|
+
* @name varToUrlHash
|
|
188
|
+
* @summary Puts a variable into the URL hash as a param.
|
|
189
|
+
* @description
|
|
190
|
+
* Since url variables are added to the hash and are not treated as URL params, the params are split
|
|
191
|
+
* and parsed into a `URLSearchParams`.
|
|
192
|
+
*/
|
|
193
|
+
declare const varToUrlHash: (key: string, val: string, addIfMissing: boolean) => void;
|
|
194
|
+
/**
|
|
195
|
+
* @name removeVarFromUrlHash
|
|
196
|
+
* @summary
|
|
197
|
+
* Removes a variable `key` from the URL hash if it exists. Removes dangling `?` if no URL variables
|
|
198
|
+
* exist.
|
|
199
|
+
*/
|
|
200
|
+
declare const removeVarFromUrlHash: (key: string) => void;
|
|
201
|
+
/**
|
|
202
|
+
* @name sortWithNull
|
|
203
|
+
* @summary Sorts an array with nulls last.
|
|
204
|
+
*/
|
|
205
|
+
declare const sortWithNull: (ascending: boolean) => (a: unknown, b: unknown) => 0 | 1 | -1;
|
|
206
|
+
/**
|
|
207
|
+
* @name applyWidthAsPadding
|
|
208
|
+
* @summary Applies width of subject to paddingRight of container.
|
|
209
|
+
*/
|
|
210
|
+
declare const applyWidthAsPadding: (subjectRef: RefObject<HTMLDivElement | null>, containerRef: RefObject<HTMLDivElement | null>) => void;
|
|
211
|
+
/**
|
|
212
|
+
* @name unescape
|
|
213
|
+
* @summary Replaces \” with “
|
|
214
|
+
*/
|
|
215
|
+
declare const unescape: (val: string) => string;
|
|
216
|
+
/**
|
|
217
|
+
* @name inChrome
|
|
218
|
+
* @summary Whether the application is rendering in Chrome.
|
|
219
|
+
*/
|
|
220
|
+
declare const inChrome: () => boolean;
|
|
221
|
+
/**
|
|
222
|
+
* @name addedTo
|
|
223
|
+
* @summary Given 2 objects and some keys, return items in the fresh object that do not exist in the
|
|
224
|
+
* stale object by matching the given common key values of both objects.
|
|
225
|
+
*/
|
|
226
|
+
declare const addedTo: (fresh: AnyObject[], stale: AnyObject[], keys: string[]) => AnyObject[];
|
|
227
|
+
/**
|
|
228
|
+
* @name removedFrom
|
|
229
|
+
* @summary Given 2 objects and some keys, return items in the stale object that do not exist in the
|
|
230
|
+
* fresh object by matching the given common key values of both objects.
|
|
231
|
+
*/
|
|
232
|
+
declare const removedFrom: (fresh: AnyObject[], stale: AnyObject[], keys: string[]) => AnyObject[];
|
|
233
|
+
/**
|
|
234
|
+
* @name matchedProperties
|
|
235
|
+
* @summary Given 2 objects and some keys, return items in object 1 that also exist in object 2 by
|
|
236
|
+
* matching the given common key values of both objects.
|
|
237
|
+
*/
|
|
238
|
+
declare const matchedProperties: (objX: AnyObject[], objY: AnyObject[], keys: string[]) => AnyObject[];
|
|
239
|
+
/**
|
|
240
|
+
* @name isValidHttpUrl
|
|
241
|
+
* @summary Give a string, return whether it is a valid http URL.
|
|
242
|
+
* @param string - The string to check.
|
|
243
|
+
*/
|
|
244
|
+
declare const isValidHttpUrl: (string: string) => boolean;
|
|
245
|
+
/**
|
|
246
|
+
* @name makeCancelable
|
|
247
|
+
* @summary Makes a promise cancellable.
|
|
248
|
+
* @param promise - The promise to make cancellable.
|
|
249
|
+
*/
|
|
250
|
+
declare const makeCancelable: (promise: Promise<AnyObject>) => {
|
|
251
|
+
promise: Promise<unknown>;
|
|
252
|
+
cancel: () => void;
|
|
253
|
+
};
|
|
254
|
+
/**
|
|
255
|
+
* @name unimplemented
|
|
256
|
+
* @summary A placeholder function to signal a deliberate unimplementation.
|
|
257
|
+
* Consumes an arbitrary number of props.
|
|
258
|
+
*/
|
|
259
|
+
declare const unimplemented: ({ ...props }: {
|
|
260
|
+
[x: string]: any;
|
|
261
|
+
}) => void;
|
|
262
|
+
/**
|
|
263
|
+
* Deep merge two objects.
|
|
264
|
+
* @param target
|
|
265
|
+
* @param ...sources
|
|
266
|
+
*/
|
|
267
|
+
declare const mergeDeep: (target: AnyObject, ...sources: AnyObject[]) => AnyObject;
|
|
268
|
+
|
|
269
|
+
export { addedTo, appendOr, appendOrEmpty, applyWidthAsPadding, camelize, capitalizeFirstLetter, ellipsisFn, eqSet, extractUrlValue, formatAccountSs58, inChrome, isSuperset, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, maxBigInt, mergeDeep, minBigInt, minDecimalPlaces, pageFromUri, planckToUnit, remToUnit, removeHexPrefix, removeVarFromUrlHash, removedFrom, rmCommas, rmDecimals, setStateWithRef, shuffle, snakeToCamel, sortWithNull, u8aConcat, unescape, unimplemented, unitToPlanck, varToUrlHash, withTimeout, withTimeoutThrow };
|