@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/unit.cjs
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/unit.ts
|
|
21
|
-
var unit_exports = {};
|
|
22
|
-
__export(unit_exports, {
|
|
23
|
-
addedTo: () => addedTo,
|
|
24
|
-
applyWidthAsPadding: () => applyWidthAsPadding,
|
|
25
|
-
capitalizeFirstLetter: () => capitalizeFirstLetter,
|
|
26
|
-
extractUrlValue: () => extractUrlValue,
|
|
27
|
-
inChrome: () => inChrome,
|
|
28
|
-
isValidAddress: () => isValidAddress,
|
|
29
|
-
isValidHttpUrl: () => isValidHttpUrl,
|
|
30
|
-
localStorageOrDefault: () => localStorageOrDefault,
|
|
31
|
-
makeCancelable: () => makeCancelable,
|
|
32
|
-
matchedProperties: () => matchedProperties,
|
|
33
|
-
mergeDeep: () => mergeDeep,
|
|
34
|
-
planckToUnit: () => planckToUnit,
|
|
35
|
-
remToUnit: () => remToUnit,
|
|
36
|
-
removeVarFromUrlHash: () => removeVarFromUrlHash,
|
|
37
|
-
removedFrom: () => removedFrom,
|
|
38
|
-
setStateWithRef: () => setStateWithRef,
|
|
39
|
-
snakeToCamel: () => snakeToCamel,
|
|
40
|
-
sortWithNull: () => sortWithNull,
|
|
41
|
-
unescape: () => unescape,
|
|
42
|
-
unimplemented: () => unimplemented,
|
|
43
|
-
unitToPlanck: () => unitToPlanck,
|
|
44
|
-
varToUrlHash: () => varToUrlHash
|
|
45
|
-
});
|
|
46
|
-
module.exports = __toCommonJS(unit_exports);
|
|
47
|
-
var import_utils2 = require("dedot/utils");
|
|
48
|
-
|
|
49
|
-
// src/base.ts
|
|
50
|
-
var import_utils = require("dedot/utils");
|
|
51
|
-
var rmCommas = (val) => val.replace(/,/g, "");
|
|
52
|
-
var rmDecimals = (str) => str.split(".")[0];
|
|
53
|
-
|
|
54
|
-
// src/unit.ts
|
|
55
|
-
var planckToUnit = (val, units) => {
|
|
56
|
-
try {
|
|
57
|
-
units = Math.max(Math.round(units), 0);
|
|
58
|
-
const bigIntVal = typeof val === "bigint" ? val : BigInt(
|
|
59
|
-
typeof val === "number" ? Math.floor(val).toString() : rmDecimals(rmCommas(val))
|
|
60
|
-
);
|
|
61
|
-
const divisor = units === 0 ? 1n : BigInt(10) ** BigInt(units);
|
|
62
|
-
const integerPart = bigIntVal / divisor;
|
|
63
|
-
const fractionalPart = bigIntVal % divisor;
|
|
64
|
-
const fractionalStr = units > 0 ? `.${fractionalPart.toString().padStart(units, "0")}` : ``;
|
|
65
|
-
return `${integerPart}${fractionalStr}`;
|
|
66
|
-
} catch (e) {
|
|
67
|
-
return "0";
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
var unitToPlanck = (val, units) => {
|
|
71
|
-
try {
|
|
72
|
-
units = Math.max(Math.round(units), 0);
|
|
73
|
-
const strVal = (typeof val === "string" ? rmCommas(val) : val.toString()) || "0";
|
|
74
|
-
const [integerPart, fractionalPart = ""] = strVal.split(".");
|
|
75
|
-
let bigIntValue = BigInt(integerPart) * BigInt(10) ** BigInt(units);
|
|
76
|
-
if (fractionalPart) {
|
|
77
|
-
let fractionalValue;
|
|
78
|
-
if (fractionalPart.length > units) {
|
|
79
|
-
fractionalValue = BigInt(fractionalPart.slice(0, units));
|
|
80
|
-
} else {
|
|
81
|
-
fractionalValue = BigInt(fractionalPart.padEnd(units, "0"));
|
|
82
|
-
}
|
|
83
|
-
bigIntValue += fractionalValue;
|
|
84
|
-
}
|
|
85
|
-
return bigIntValue;
|
|
86
|
-
} catch (e) {
|
|
87
|
-
return BigInt(0);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
var remToUnit = (rem) => Number(rem.slice(0, rem.length - 3)) * parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
91
|
-
var capitalizeFirstLetter = (string) => string.charAt(0).toUpperCase() + string.slice(1);
|
|
92
|
-
var snakeToCamel = (str) => str.toLowerCase().replace(
|
|
93
|
-
/([-_][a-z])/g,
|
|
94
|
-
(group) => group.toUpperCase().replace("-", "").replace("_", "")
|
|
95
|
-
);
|
|
96
|
-
var setStateWithRef = (value, setState, ref) => {
|
|
97
|
-
setState(value);
|
|
98
|
-
ref.current = value;
|
|
99
|
-
};
|
|
100
|
-
var localStorageOrDefault = (key, _default, parse = false) => {
|
|
101
|
-
const val = localStorage.getItem(key);
|
|
102
|
-
if (val === null) {
|
|
103
|
-
return _default;
|
|
104
|
-
}
|
|
105
|
-
if (parse) {
|
|
106
|
-
return JSON.parse(val);
|
|
107
|
-
}
|
|
108
|
-
return val;
|
|
109
|
-
};
|
|
110
|
-
var isValidAddress = (address) => {
|
|
111
|
-
try {
|
|
112
|
-
(0, import_utils2.decodeAddress)(address);
|
|
113
|
-
return true;
|
|
114
|
-
} catch (e) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
var extractUrlValue = (key, url) => {
|
|
119
|
-
if (typeof url === "undefined") {
|
|
120
|
-
url = window.location.href;
|
|
121
|
-
}
|
|
122
|
-
const match = url.match(`[?&]${key}=([^&]+)`);
|
|
123
|
-
return match ? match[1] : null;
|
|
124
|
-
};
|
|
125
|
-
var varToUrlHash = (key, val, addIfMissing) => {
|
|
126
|
-
const hash = window.location.hash;
|
|
127
|
-
const [page, params] = hash.split("?");
|
|
128
|
-
const searchParams = new URLSearchParams(params);
|
|
129
|
-
if (searchParams.get(key) === null && !addIfMissing) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
searchParams.set(key, val);
|
|
133
|
-
window.location.hash = `${page}?${searchParams.toString()}`;
|
|
134
|
-
};
|
|
135
|
-
var removeVarFromUrlHash = (key) => {
|
|
136
|
-
const hash = window.location.hash;
|
|
137
|
-
const [page, params] = hash.split("?");
|
|
138
|
-
const searchParams = new URLSearchParams(params);
|
|
139
|
-
if (searchParams.get(key) === null) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
searchParams.delete(key);
|
|
143
|
-
const paramsAsStr = searchParams.toString();
|
|
144
|
-
window.location.hash = `${page}${paramsAsStr ? `?${paramsAsStr}` : ``}`;
|
|
145
|
-
};
|
|
146
|
-
var sortWithNull = (ascending) => (a, b) => {
|
|
147
|
-
if (typeof a === "undefined" && typeof b === "undefined") {
|
|
148
|
-
return 0;
|
|
149
|
-
}
|
|
150
|
-
if (typeof a === "undefined" || typeof b === "undefined") {
|
|
151
|
-
return typeof a === "undefined" ? 1 : -1;
|
|
152
|
-
}
|
|
153
|
-
if (a === b) {
|
|
154
|
-
return 0;
|
|
155
|
-
}
|
|
156
|
-
if (a === null) {
|
|
157
|
-
return 1;
|
|
158
|
-
}
|
|
159
|
-
if (b === null) {
|
|
160
|
-
return -1;
|
|
161
|
-
}
|
|
162
|
-
if (ascending) {
|
|
163
|
-
return a < b ? -1 : 1;
|
|
164
|
-
}
|
|
165
|
-
return a < b ? 1 : -1;
|
|
166
|
-
};
|
|
167
|
-
var applyWidthAsPadding = (subjectRef, containerRef) => {
|
|
168
|
-
if (containerRef.current && subjectRef.current) {
|
|
169
|
-
containerRef.current.style.paddingRight = `${subjectRef.current.offsetWidth + remToUnit("1rem")}px`;
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
var unescape = (val) => val.replace(/\\"/g, '"');
|
|
173
|
-
var inChrome = () => {
|
|
174
|
-
const isChromium = window?.chrome || null;
|
|
175
|
-
const winNav = window?.navigator || null;
|
|
176
|
-
const isOpera = typeof window?.opr !== "undefined";
|
|
177
|
-
const isIEedge = winNav?.userAgent.indexOf("Edg") > -1 || false;
|
|
178
|
-
const isIOSChrome = winNav?.userAgent.match("CriOS") || false;
|
|
179
|
-
if (isIOSChrome) {
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
if (isChromium !== null && typeof isChromium !== "undefined" && isOpera === false && isIEedge === false) {
|
|
183
|
-
return true;
|
|
184
|
-
}
|
|
185
|
-
return false;
|
|
186
|
-
};
|
|
187
|
-
var addedTo = (fresh, stale, keys) => typeof fresh !== "object" || typeof stale !== "object" || !keys.length ? [] : fresh.filter(
|
|
188
|
-
(freshItem) => !stale.find(
|
|
189
|
-
(staleItem) => keys.every(
|
|
190
|
-
(key) => !(key in staleItem) || !(key in freshItem) ? false : staleItem[key] === freshItem[key]
|
|
191
|
-
)
|
|
192
|
-
)
|
|
193
|
-
);
|
|
194
|
-
var removedFrom = (fresh, stale, keys) => typeof fresh !== "object" || typeof stale !== "object" || !keys.length ? [] : stale.filter(
|
|
195
|
-
(staleItem) => !fresh.find(
|
|
196
|
-
(freshItem) => keys.every(
|
|
197
|
-
(key) => !(key in staleItem) || !(key in freshItem) ? false : freshItem[key] === staleItem[key]
|
|
198
|
-
)
|
|
199
|
-
)
|
|
200
|
-
);
|
|
201
|
-
var matchedProperties = (objX, objY, keys) => typeof objX !== "object" || typeof objY !== "object" || !keys.length ? [] : objY.filter(
|
|
202
|
-
(x) => objX.find(
|
|
203
|
-
(y) => keys.every(
|
|
204
|
-
(key) => !(key in x) || !(key in y) ? false : y[key] === x[key]
|
|
205
|
-
)
|
|
206
|
-
)
|
|
207
|
-
);
|
|
208
|
-
var isValidHttpUrl = (string) => {
|
|
209
|
-
let url;
|
|
210
|
-
try {
|
|
211
|
-
url = new URL(string);
|
|
212
|
-
} catch (_) {
|
|
213
|
-
return false;
|
|
214
|
-
}
|
|
215
|
-
return url.protocol === "http:" || url.protocol === "https:";
|
|
216
|
-
};
|
|
217
|
-
var makeCancelable = (promise) => {
|
|
218
|
-
let hasCanceled = false;
|
|
219
|
-
const wrappedPromise = new Promise((resolve, reject) => {
|
|
220
|
-
promise.then(
|
|
221
|
-
(val) => hasCanceled ? reject(Error("Cancelled")) : resolve(val)
|
|
222
|
-
);
|
|
223
|
-
promise.catch(
|
|
224
|
-
(error) => hasCanceled ? reject(Error("Cancelled")) : reject(error)
|
|
225
|
-
);
|
|
226
|
-
});
|
|
227
|
-
return {
|
|
228
|
-
promise: wrappedPromise,
|
|
229
|
-
cancel: () => {
|
|
230
|
-
hasCanceled = true;
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
};
|
|
234
|
-
var unimplemented = ({ ...props }) => {
|
|
235
|
-
};
|
|
236
|
-
var mergeDeep = (target, ...sources) => {
|
|
237
|
-
if (!sources.length) {
|
|
238
|
-
return target;
|
|
239
|
-
}
|
|
240
|
-
const isObject = (item) => item && typeof item === "object" && !Array.isArray(item);
|
|
241
|
-
const source = sources.shift();
|
|
242
|
-
if (isObject(target) && isObject(source)) {
|
|
243
|
-
for (const key in source) {
|
|
244
|
-
if (isObject(source[key])) {
|
|
245
|
-
if (!target[key]) {
|
|
246
|
-
Object.assign(target, { [key]: {} });
|
|
247
|
-
}
|
|
248
|
-
mergeDeep(target[key], source[key]);
|
|
249
|
-
} else {
|
|
250
|
-
Object.assign(target, { [key]: source[key] });
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return mergeDeep(target, ...sources);
|
|
255
|
-
};
|
|
256
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
257
|
-
0 && (module.exports = {
|
|
258
|
-
addedTo,
|
|
259
|
-
applyWidthAsPadding,
|
|
260
|
-
capitalizeFirstLetter,
|
|
261
|
-
extractUrlValue,
|
|
262
|
-
inChrome,
|
|
263
|
-
isValidAddress,
|
|
264
|
-
isValidHttpUrl,
|
|
265
|
-
localStorageOrDefault,
|
|
266
|
-
makeCancelable,
|
|
267
|
-
matchedProperties,
|
|
268
|
-
mergeDeep,
|
|
269
|
-
planckToUnit,
|
|
270
|
-
remToUnit,
|
|
271
|
-
removeVarFromUrlHash,
|
|
272
|
-
removedFrom,
|
|
273
|
-
setStateWithRef,
|
|
274
|
-
snakeToCamel,
|
|
275
|
-
sortWithNull,
|
|
276
|
-
unescape,
|
|
277
|
-
unimplemented,
|
|
278
|
-
unitToPlanck,
|
|
279
|
-
varToUrlHash
|
|
280
|
-
});
|
|
281
|
-
/* @license Copyright 2024 w3ux authors & contributors
|
|
282
|
-
SPDX-License-Identifier: GPL-3.0-only */
|
package/unit.d.cts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
2
|
-
import { AnyObject } from './types.cjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Converts an on-chain balance value from planck to a decimal value in token units.
|
|
6
|
-
*
|
|
7
|
-
* @function planckToUnit
|
|
8
|
-
* @param {number | BigInt | string} val - The balance value in planck. Accepts a `number`, `BigInt`, or `string`.
|
|
9
|
-
* @param {number} units - The number of decimal places in the token unit (10^units planck per 1 token).
|
|
10
|
-
* @returns {string} The equivalent token unit value as a decimal string.
|
|
11
|
-
* @example
|
|
12
|
-
* // Convert 1500000000000 planck to tokens with 12 decimal places
|
|
13
|
-
* planckToUnit("1500000000000", 12); // returns "1.5"
|
|
14
|
-
*/
|
|
15
|
-
declare const planckToUnit: (val: number | bigint | string, units: number) => string;
|
|
16
|
-
/**
|
|
17
|
-
* Converts a token unit value to an integer value in planck.
|
|
18
|
-
*
|
|
19
|
-
* @function unitToPlanck
|
|
20
|
-
* @param {string | number | BigInt} val - The token unit value to convert. Accepts a string, number, or BigInt.
|
|
21
|
-
* @param {number} units - The number of decimal places for conversion (10^units planck per 1 token).
|
|
22
|
-
* @returns {BigInt} The equivalent value in planck as a BigInt.
|
|
23
|
-
* @example
|
|
24
|
-
* // Convert "1.5" tokens to planck with 12 decimal places
|
|
25
|
-
* unitToPlanck("1.5", 12); // returns BigInt("1500000000000")
|
|
26
|
-
*/
|
|
27
|
-
declare const unitToPlanck: (val: string | number | bigint, units: number) => bigint;
|
|
28
|
-
/**
|
|
29
|
-
* @name remToUnit
|
|
30
|
-
* @summary Converts a rem string to a number.
|
|
31
|
-
*/
|
|
32
|
-
declare const remToUnit: (rem: string) => number;
|
|
33
|
-
/**
|
|
34
|
-
* @name capitalizeFirstLetter
|
|
35
|
-
* @summary Capitalize the first letter of a string.
|
|
36
|
-
*/
|
|
37
|
-
declare const capitalizeFirstLetter: (string: string) => string;
|
|
38
|
-
/**
|
|
39
|
-
* @name snakeToCamel
|
|
40
|
-
* @summary converts a string from snake / kebab-case to camel-case.
|
|
41
|
-
*/
|
|
42
|
-
declare const snakeToCamel: (str: string) => string;
|
|
43
|
-
/**
|
|
44
|
-
* @name setStateWithRef
|
|
45
|
-
* @summary Synchronize React state and its reference with the provided value.
|
|
46
|
-
*/
|
|
47
|
-
declare const setStateWithRef: <T>(value: T, setState: (_state: T) => void, ref: RefObject<T>) => void;
|
|
48
|
-
/**
|
|
49
|
-
* @name localStorageOrDefault
|
|
50
|
-
* @summary Retrieve the local stroage value with the key, return defult value if it is not
|
|
51
|
-
* found.
|
|
52
|
-
*/
|
|
53
|
-
declare const localStorageOrDefault: <T>(key: string, _default: T, parse?: boolean) => T | string;
|
|
54
|
-
/**
|
|
55
|
-
* @name isValidAddress
|
|
56
|
-
* @summary Return whether an address is valid Substrate address.
|
|
57
|
-
*/
|
|
58
|
-
declare const isValidAddress: (address: string) => boolean;
|
|
59
|
-
/**
|
|
60
|
-
* @name extractUrlValue
|
|
61
|
-
* @summary Extracts a URL value from a URL string.
|
|
62
|
-
*/
|
|
63
|
-
declare const extractUrlValue: (key: string, url?: string) => string | null;
|
|
64
|
-
/**
|
|
65
|
-
* @name varToUrlHash
|
|
66
|
-
* @summary Puts a variable into the URL hash as a param.
|
|
67
|
-
* @description
|
|
68
|
-
* Since url variables are added to the hash and are not treated as URL params, the params are split
|
|
69
|
-
* and parsed into a `URLSearchParams`.
|
|
70
|
-
*/
|
|
71
|
-
declare const varToUrlHash: (key: string, val: string, addIfMissing: boolean) => void;
|
|
72
|
-
/**
|
|
73
|
-
* @name removeVarFromUrlHash
|
|
74
|
-
* @summary
|
|
75
|
-
* Removes a variable `key` from the URL hash if it exists. Removes dangling `?` if no URL variables
|
|
76
|
-
* exist.
|
|
77
|
-
*/
|
|
78
|
-
declare const removeVarFromUrlHash: (key: string) => void;
|
|
79
|
-
/**
|
|
80
|
-
* @name sortWithNull
|
|
81
|
-
* @summary Sorts an array with nulls last.
|
|
82
|
-
*/
|
|
83
|
-
declare const sortWithNull: (ascending: boolean) => (a: unknown, b: unknown) => 0 | 1 | -1;
|
|
84
|
-
/**
|
|
85
|
-
* @name applyWidthAsPadding
|
|
86
|
-
* @summary Applies width of subject to paddingRight of container.
|
|
87
|
-
*/
|
|
88
|
-
declare const applyWidthAsPadding: (subjectRef: RefObject<HTMLDivElement | null>, containerRef: RefObject<HTMLDivElement | null>) => void;
|
|
89
|
-
/**
|
|
90
|
-
* @name unescape
|
|
91
|
-
* @summary Replaces \” with “
|
|
92
|
-
*/
|
|
93
|
-
declare const unescape: (val: string) => string;
|
|
94
|
-
/**
|
|
95
|
-
* @name inChrome
|
|
96
|
-
* @summary Whether the application is rendering in Chrome.
|
|
97
|
-
*/
|
|
98
|
-
declare const inChrome: () => boolean;
|
|
99
|
-
/**
|
|
100
|
-
* @name addedTo
|
|
101
|
-
* @summary Given 2 objects and some keys, return items in the fresh object that do not exist in the
|
|
102
|
-
* stale object by matching the given common key values of both objects.
|
|
103
|
-
*/
|
|
104
|
-
declare const addedTo: (fresh: AnyObject[], stale: AnyObject[], keys: string[]) => AnyObject[];
|
|
105
|
-
/**
|
|
106
|
-
* @name removedFrom
|
|
107
|
-
* @summary Given 2 objects and some keys, return items in the stale object that do not exist in the
|
|
108
|
-
* fresh object by matching the given common key values of both objects.
|
|
109
|
-
*/
|
|
110
|
-
declare const removedFrom: (fresh: AnyObject[], stale: AnyObject[], keys: string[]) => AnyObject[];
|
|
111
|
-
/**
|
|
112
|
-
* @name matchedProperties
|
|
113
|
-
* @summary Given 2 objects and some keys, return items in object 1 that also exist in object 2 by
|
|
114
|
-
* matching the given common key values of both objects.
|
|
115
|
-
*/
|
|
116
|
-
declare const matchedProperties: (objX: AnyObject[], objY: AnyObject[], keys: string[]) => AnyObject[];
|
|
117
|
-
/**
|
|
118
|
-
* @name isValidHttpUrl
|
|
119
|
-
* @summary Give a string, return whether it is a valid http URL.
|
|
120
|
-
* @param string - The string to check.
|
|
121
|
-
*/
|
|
122
|
-
declare const isValidHttpUrl: (string: string) => boolean;
|
|
123
|
-
/**
|
|
124
|
-
* @name makeCancelable
|
|
125
|
-
* @summary Makes a promise cancellable.
|
|
126
|
-
* @param promise - The promise to make cancellable.
|
|
127
|
-
*/
|
|
128
|
-
declare const makeCancelable: (promise: Promise<AnyObject>) => {
|
|
129
|
-
promise: Promise<unknown>;
|
|
130
|
-
cancel: () => void;
|
|
131
|
-
};
|
|
132
|
-
/**
|
|
133
|
-
* @name unimplemented
|
|
134
|
-
* @summary A placeholder function to signal a deliberate unimplementation.
|
|
135
|
-
* Consumes an arbitrary number of props.
|
|
136
|
-
*/
|
|
137
|
-
declare const unimplemented: ({ ...props }: {
|
|
138
|
-
[x: string]: any;
|
|
139
|
-
}) => void;
|
|
140
|
-
/**
|
|
141
|
-
* Deep merge two objects.
|
|
142
|
-
* @param target
|
|
143
|
-
* @param ...sources
|
|
144
|
-
*/
|
|
145
|
-
declare const mergeDeep: (target: AnyObject, ...sources: AnyObject[]) => AnyObject;
|
|
146
|
-
|
|
147
|
-
export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, unescape, unimplemented, unitToPlanck, varToUrlHash };
|
package/unit.d.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
2
|
-
import { AnyObject } from './types.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Converts an on-chain balance value from planck to a decimal value in token units.
|
|
6
|
-
*
|
|
7
|
-
* @function planckToUnit
|
|
8
|
-
* @param {number | BigInt | string} val - The balance value in planck. Accepts a `number`, `BigInt`, or `string`.
|
|
9
|
-
* @param {number} units - The number of decimal places in the token unit (10^units planck per 1 token).
|
|
10
|
-
* @returns {string} The equivalent token unit value as a decimal string.
|
|
11
|
-
* @example
|
|
12
|
-
* // Convert 1500000000000 planck to tokens with 12 decimal places
|
|
13
|
-
* planckToUnit("1500000000000", 12); // returns "1.5"
|
|
14
|
-
*/
|
|
15
|
-
declare const planckToUnit: (val: number | bigint | string, units: number) => string;
|
|
16
|
-
/**
|
|
17
|
-
* Converts a token unit value to an integer value in planck.
|
|
18
|
-
*
|
|
19
|
-
* @function unitToPlanck
|
|
20
|
-
* @param {string | number | BigInt} val - The token unit value to convert. Accepts a string, number, or BigInt.
|
|
21
|
-
* @param {number} units - The number of decimal places for conversion (10^units planck per 1 token).
|
|
22
|
-
* @returns {BigInt} The equivalent value in planck as a BigInt.
|
|
23
|
-
* @example
|
|
24
|
-
* // Convert "1.5" tokens to planck with 12 decimal places
|
|
25
|
-
* unitToPlanck("1.5", 12); // returns BigInt("1500000000000")
|
|
26
|
-
*/
|
|
27
|
-
declare const unitToPlanck: (val: string | number | bigint, units: number) => bigint;
|
|
28
|
-
/**
|
|
29
|
-
* @name remToUnit
|
|
30
|
-
* @summary Converts a rem string to a number.
|
|
31
|
-
*/
|
|
32
|
-
declare const remToUnit: (rem: string) => number;
|
|
33
|
-
/**
|
|
34
|
-
* @name capitalizeFirstLetter
|
|
35
|
-
* @summary Capitalize the first letter of a string.
|
|
36
|
-
*/
|
|
37
|
-
declare const capitalizeFirstLetter: (string: string) => string;
|
|
38
|
-
/**
|
|
39
|
-
* @name snakeToCamel
|
|
40
|
-
* @summary converts a string from snake / kebab-case to camel-case.
|
|
41
|
-
*/
|
|
42
|
-
declare const snakeToCamel: (str: string) => string;
|
|
43
|
-
/**
|
|
44
|
-
* @name setStateWithRef
|
|
45
|
-
* @summary Synchronize React state and its reference with the provided value.
|
|
46
|
-
*/
|
|
47
|
-
declare const setStateWithRef: <T>(value: T, setState: (_state: T) => void, ref: RefObject<T>) => void;
|
|
48
|
-
/**
|
|
49
|
-
* @name localStorageOrDefault
|
|
50
|
-
* @summary Retrieve the local stroage value with the key, return defult value if it is not
|
|
51
|
-
* found.
|
|
52
|
-
*/
|
|
53
|
-
declare const localStorageOrDefault: <T>(key: string, _default: T, parse?: boolean) => T | string;
|
|
54
|
-
/**
|
|
55
|
-
* @name isValidAddress
|
|
56
|
-
* @summary Return whether an address is valid Substrate address.
|
|
57
|
-
*/
|
|
58
|
-
declare const isValidAddress: (address: string) => boolean;
|
|
59
|
-
/**
|
|
60
|
-
* @name extractUrlValue
|
|
61
|
-
* @summary Extracts a URL value from a URL string.
|
|
62
|
-
*/
|
|
63
|
-
declare const extractUrlValue: (key: string, url?: string) => string | null;
|
|
64
|
-
/**
|
|
65
|
-
* @name varToUrlHash
|
|
66
|
-
* @summary Puts a variable into the URL hash as a param.
|
|
67
|
-
* @description
|
|
68
|
-
* Since url variables are added to the hash and are not treated as URL params, the params are split
|
|
69
|
-
* and parsed into a `URLSearchParams`.
|
|
70
|
-
*/
|
|
71
|
-
declare const varToUrlHash: (key: string, val: string, addIfMissing: boolean) => void;
|
|
72
|
-
/**
|
|
73
|
-
* @name removeVarFromUrlHash
|
|
74
|
-
* @summary
|
|
75
|
-
* Removes a variable `key` from the URL hash if it exists. Removes dangling `?` if no URL variables
|
|
76
|
-
* exist.
|
|
77
|
-
*/
|
|
78
|
-
declare const removeVarFromUrlHash: (key: string) => void;
|
|
79
|
-
/**
|
|
80
|
-
* @name sortWithNull
|
|
81
|
-
* @summary Sorts an array with nulls last.
|
|
82
|
-
*/
|
|
83
|
-
declare const sortWithNull: (ascending: boolean) => (a: unknown, b: unknown) => 0 | 1 | -1;
|
|
84
|
-
/**
|
|
85
|
-
* @name applyWidthAsPadding
|
|
86
|
-
* @summary Applies width of subject to paddingRight of container.
|
|
87
|
-
*/
|
|
88
|
-
declare const applyWidthAsPadding: (subjectRef: RefObject<HTMLDivElement | null>, containerRef: RefObject<HTMLDivElement | null>) => void;
|
|
89
|
-
/**
|
|
90
|
-
* @name unescape
|
|
91
|
-
* @summary Replaces \” with “
|
|
92
|
-
*/
|
|
93
|
-
declare const unescape: (val: string) => string;
|
|
94
|
-
/**
|
|
95
|
-
* @name inChrome
|
|
96
|
-
* @summary Whether the application is rendering in Chrome.
|
|
97
|
-
*/
|
|
98
|
-
declare const inChrome: () => boolean;
|
|
99
|
-
/**
|
|
100
|
-
* @name addedTo
|
|
101
|
-
* @summary Given 2 objects and some keys, return items in the fresh object that do not exist in the
|
|
102
|
-
* stale object by matching the given common key values of both objects.
|
|
103
|
-
*/
|
|
104
|
-
declare const addedTo: (fresh: AnyObject[], stale: AnyObject[], keys: string[]) => AnyObject[];
|
|
105
|
-
/**
|
|
106
|
-
* @name removedFrom
|
|
107
|
-
* @summary Given 2 objects and some keys, return items in the stale object that do not exist in the
|
|
108
|
-
* fresh object by matching the given common key values of both objects.
|
|
109
|
-
*/
|
|
110
|
-
declare const removedFrom: (fresh: AnyObject[], stale: AnyObject[], keys: string[]) => AnyObject[];
|
|
111
|
-
/**
|
|
112
|
-
* @name matchedProperties
|
|
113
|
-
* @summary Given 2 objects and some keys, return items in object 1 that also exist in object 2 by
|
|
114
|
-
* matching the given common key values of both objects.
|
|
115
|
-
*/
|
|
116
|
-
declare const matchedProperties: (objX: AnyObject[], objY: AnyObject[], keys: string[]) => AnyObject[];
|
|
117
|
-
/**
|
|
118
|
-
* @name isValidHttpUrl
|
|
119
|
-
* @summary Give a string, return whether it is a valid http URL.
|
|
120
|
-
* @param string - The string to check.
|
|
121
|
-
*/
|
|
122
|
-
declare const isValidHttpUrl: (string: string) => boolean;
|
|
123
|
-
/**
|
|
124
|
-
* @name makeCancelable
|
|
125
|
-
* @summary Makes a promise cancellable.
|
|
126
|
-
* @param promise - The promise to make cancellable.
|
|
127
|
-
*/
|
|
128
|
-
declare const makeCancelable: (promise: Promise<AnyObject>) => {
|
|
129
|
-
promise: Promise<unknown>;
|
|
130
|
-
cancel: () => void;
|
|
131
|
-
};
|
|
132
|
-
/**
|
|
133
|
-
* @name unimplemented
|
|
134
|
-
* @summary A placeholder function to signal a deliberate unimplementation.
|
|
135
|
-
* Consumes an arbitrary number of props.
|
|
136
|
-
*/
|
|
137
|
-
declare const unimplemented: ({ ...props }: {
|
|
138
|
-
[x: string]: any;
|
|
139
|
-
}) => void;
|
|
140
|
-
/**
|
|
141
|
-
* Deep merge two objects.
|
|
142
|
-
* @param target
|
|
143
|
-
* @param ...sources
|
|
144
|
-
*/
|
|
145
|
-
declare const mergeDeep: (target: AnyObject, ...sources: AnyObject[]) => AnyObject;
|
|
146
|
-
|
|
147
|
-
export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, unescape, unimplemented, unitToPlanck, varToUrlHash };
|