@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/base.cjs
DELETED
|
@@ -1,194 +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/base.ts
|
|
21
|
-
var base_exports = {};
|
|
22
|
-
__export(base_exports, {
|
|
23
|
-
appendOr: () => appendOr,
|
|
24
|
-
appendOrEmpty: () => appendOrEmpty,
|
|
25
|
-
camelize: () => camelize,
|
|
26
|
-
ellipsisFn: () => ellipsisFn,
|
|
27
|
-
eqSet: () => eqSet,
|
|
28
|
-
formatAccountSs58: () => formatAccountSs58,
|
|
29
|
-
isSuperset: () => isSuperset,
|
|
30
|
-
maxBigInt: () => maxBigInt,
|
|
31
|
-
minBigInt: () => minBigInt,
|
|
32
|
-
minDecimalPlaces: () => minDecimalPlaces,
|
|
33
|
-
pageFromUri: () => pageFromUri,
|
|
34
|
-
removeHexPrefix: () => removeHexPrefix,
|
|
35
|
-
rmCommas: () => rmCommas,
|
|
36
|
-
rmDecimals: () => rmDecimals,
|
|
37
|
-
shuffle: () => shuffle,
|
|
38
|
-
withTimeout: () => withTimeout,
|
|
39
|
-
withTimeoutThrow: () => withTimeoutThrow
|
|
40
|
-
});
|
|
41
|
-
module.exports = __toCommonJS(base_exports);
|
|
42
|
-
var import_utils = require("dedot/utils");
|
|
43
|
-
var minDecimalPlaces = (val, minDecimals) => {
|
|
44
|
-
try {
|
|
45
|
-
const retainCommas = typeof val === "string" && val.includes(",");
|
|
46
|
-
const strVal = typeof val === "string" ? val.replace(/,/g, "") : val.toString();
|
|
47
|
-
const [integerPart, fractionalPart = ""] = strVal.split(".");
|
|
48
|
-
const whole = BigInt(integerPart || "0");
|
|
49
|
-
const missingDecimals = minDecimals - fractionalPart.length;
|
|
50
|
-
const formattedWhole = retainCommas ? Intl.NumberFormat("en-US").format(whole) : whole.toString();
|
|
51
|
-
return missingDecimals > 0 ? `${formattedWhole}.${fractionalPart}${"0".repeat(missingDecimals)}` : `${formattedWhole}.${fractionalPart}`;
|
|
52
|
-
} catch (e) {
|
|
53
|
-
return "0";
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
var camelize = (str) => {
|
|
57
|
-
const convertToString = (string) => {
|
|
58
|
-
if (string) {
|
|
59
|
-
if (typeof string === "string") {
|
|
60
|
-
return string;
|
|
61
|
-
}
|
|
62
|
-
return String(string);
|
|
63
|
-
}
|
|
64
|
-
return "";
|
|
65
|
-
};
|
|
66
|
-
const toWords = (inp) => convertToString(inp).match(
|
|
67
|
-
/[A-Z\xC0-\xD6\xD8-\xDE]?[a-z\xDF-\xF6\xF8-\xFF]+|[A-Z\xC0-\xD6\xD8-\xDE]+(?![a-z\xDF-\xF6\xF8-\xFF])|\d+/g
|
|
68
|
-
);
|
|
69
|
-
const simpleCamelCase = (inp) => {
|
|
70
|
-
let result = "";
|
|
71
|
-
for (let i = 0; i < inp?.length; i++) {
|
|
72
|
-
const currString = inp[i];
|
|
73
|
-
let tmpStr = currString.toLowerCase();
|
|
74
|
-
if (i != 0) {
|
|
75
|
-
tmpStr = tmpStr.slice(0, 1).toUpperCase() + tmpStr.slice(1, tmpStr.length);
|
|
76
|
-
}
|
|
77
|
-
result += tmpStr;
|
|
78
|
-
}
|
|
79
|
-
return result;
|
|
80
|
-
};
|
|
81
|
-
const w = toWords(str)?.map((a) => a.toLowerCase());
|
|
82
|
-
return simpleCamelCase(w || []);
|
|
83
|
-
};
|
|
84
|
-
var ellipsisFn = (str, amount = 6, position = "center") => {
|
|
85
|
-
const half = str.length / 2;
|
|
86
|
-
if (amount <= 4) {
|
|
87
|
-
if (position === "center") {
|
|
88
|
-
return str.slice(0, 4) + "..." + str.slice(-4);
|
|
89
|
-
}
|
|
90
|
-
if (position === "end") {
|
|
91
|
-
return str.slice(0, 4) + "...";
|
|
92
|
-
}
|
|
93
|
-
return "..." + str.slice(-4);
|
|
94
|
-
}
|
|
95
|
-
if (position === "center") {
|
|
96
|
-
return amount >= (str.length - 2) / 2 ? str.slice(0, half - 3) + "..." + str.slice(-(half - 3)) : str.slice(0, amount) + "..." + str.slice(-amount);
|
|
97
|
-
}
|
|
98
|
-
if (amount >= str.length) {
|
|
99
|
-
if (position === "end") {
|
|
100
|
-
return str.slice(0, str.length - 3) + "...";
|
|
101
|
-
}
|
|
102
|
-
return "..." + str.slice(-(str.length - 3));
|
|
103
|
-
} else {
|
|
104
|
-
if (position === "end") {
|
|
105
|
-
return str.slice(0, amount) + "...";
|
|
106
|
-
}
|
|
107
|
-
return "..." + str.slice(amount);
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
var pageFromUri = (pathname, fallback) => {
|
|
111
|
-
const lastUriItem = pathname.substring(pathname.lastIndexOf("/") + 1);
|
|
112
|
-
const page = lastUriItem.trim() === "" ? fallback : lastUriItem;
|
|
113
|
-
return page.trim();
|
|
114
|
-
};
|
|
115
|
-
var rmCommas = (val) => val.replace(/,/g, "");
|
|
116
|
-
var rmDecimals = (str) => str.split(".")[0];
|
|
117
|
-
var shuffle = (array) => {
|
|
118
|
-
let currentIndex = array.length;
|
|
119
|
-
let randomIndex;
|
|
120
|
-
while (currentIndex !== 0) {
|
|
121
|
-
randomIndex = Math.floor(Math.random() * currentIndex);
|
|
122
|
-
currentIndex--;
|
|
123
|
-
[array[currentIndex], array[randomIndex]] = [
|
|
124
|
-
array[randomIndex],
|
|
125
|
-
array[currentIndex]
|
|
126
|
-
];
|
|
127
|
-
}
|
|
128
|
-
return array;
|
|
129
|
-
};
|
|
130
|
-
var withTimeout = (ms, promise, options) => {
|
|
131
|
-
const timeout = new Promise(
|
|
132
|
-
(resolve) => setTimeout(async () => {
|
|
133
|
-
if (typeof options?.onTimeout === "function") {
|
|
134
|
-
options.onTimeout();
|
|
135
|
-
}
|
|
136
|
-
resolve(void 0);
|
|
137
|
-
}, ms)
|
|
138
|
-
);
|
|
139
|
-
return Promise.race([promise, timeout]);
|
|
140
|
-
};
|
|
141
|
-
var withTimeoutThrow = (ms, promise, options) => {
|
|
142
|
-
const timeout = new Promise(
|
|
143
|
-
(reject) => setTimeout(async () => {
|
|
144
|
-
if (typeof options?.onTimeout === "function") {
|
|
145
|
-
options.onTimeout();
|
|
146
|
-
}
|
|
147
|
-
reject("Function timeout");
|
|
148
|
-
}, ms)
|
|
149
|
-
);
|
|
150
|
-
return Promise.race([promise, timeout]);
|
|
151
|
-
};
|
|
152
|
-
var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
|
|
153
|
-
var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
|
|
154
|
-
var formatAccountSs58 = (address, ss58Prefix) => {
|
|
155
|
-
try {
|
|
156
|
-
return (0, import_utils.encodeAddress)(address, ss58Prefix);
|
|
157
|
-
} catch (e) {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
var removeHexPrefix = (str) => str.replace(/^0x/, "");
|
|
162
|
-
var eqSet = (xs, ys) => xs.size === ys.size && [...xs].every((x) => ys.has(x));
|
|
163
|
-
var isSuperset = (set, subset) => {
|
|
164
|
-
for (const elem of subset) {
|
|
165
|
-
if (!set.has(elem)) {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return true;
|
|
170
|
-
};
|
|
171
|
-
var maxBigInt = (...values) => values.reduce((max, current) => current > max ? current : max);
|
|
172
|
-
var minBigInt = (...values) => values.reduce((min, current) => current < min ? current : min);
|
|
173
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
174
|
-
0 && (module.exports = {
|
|
175
|
-
appendOr,
|
|
176
|
-
appendOrEmpty,
|
|
177
|
-
camelize,
|
|
178
|
-
ellipsisFn,
|
|
179
|
-
eqSet,
|
|
180
|
-
formatAccountSs58,
|
|
181
|
-
isSuperset,
|
|
182
|
-
maxBigInt,
|
|
183
|
-
minBigInt,
|
|
184
|
-
minDecimalPlaces,
|
|
185
|
-
pageFromUri,
|
|
186
|
-
removeHexPrefix,
|
|
187
|
-
rmCommas,
|
|
188
|
-
rmDecimals,
|
|
189
|
-
shuffle,
|
|
190
|
-
withTimeout,
|
|
191
|
-
withTimeoutThrow
|
|
192
|
-
});
|
|
193
|
-
/* @license Copyright 2024 w3ux authors & contributors
|
|
194
|
-
SPDX-License-Identifier: GPL-3.0-only */
|
package/base.d.cts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ensures a number has at least the specified number of decimal places, retaining commas in the output if they are present in the input.
|
|
3
|
-
*
|
|
4
|
-
* @function minDecimalPlaces
|
|
5
|
-
* @param {string | number | BigInt} val - The input number, which can be a `string` with or without commas, a `number`, or a `BigInt`.
|
|
6
|
-
* @param {number} minDecimals - The minimum number of decimal places to enforce.
|
|
7
|
-
* @returns {string} The formatted number as a string, padded with zeros if needed to meet `minDecimals`, retaining commas if originally provided.
|
|
8
|
-
* If `val` is invalid, returns "0".
|
|
9
|
-
* @example
|
|
10
|
-
* // Pads "1,234.5" to have at least 3 decimal places, with commas
|
|
11
|
-
* minDecimalPlaces("1,234.5", 3); // returns "1,234.500"
|
|
12
|
-
*
|
|
13
|
-
* // Returns "1234.56" unchanged
|
|
14
|
-
* minDecimalPlaces(1234.56, 2); // returns "1234.56"
|
|
15
|
-
*
|
|
16
|
-
* // Pads BigInt 1234 with 2 decimals
|
|
17
|
-
* minDecimalPlaces(BigInt(1234), 2); // returns "1234.00"
|
|
18
|
-
*/
|
|
19
|
-
declare const minDecimalPlaces: (val: string | number | bigint, minDecimals: number) => string;
|
|
20
|
-
/**
|
|
21
|
-
* @name camelize
|
|
22
|
-
* @summary Converts a string of text to camelCase.
|
|
23
|
-
*/
|
|
24
|
-
declare const camelize: (str: string) => string;
|
|
25
|
-
/**
|
|
26
|
-
* @name ellipsisFn
|
|
27
|
-
* @summary Receives an address and creates ellipsis on the given string, based on parameters.
|
|
28
|
-
* @param str - The string to apply the ellipsis on
|
|
29
|
-
* @param amount - The amount of characters that the ellipsis will be
|
|
30
|
-
* @param position - where the ellipsis will apply; if center the amount of character is the
|
|
31
|
-
* same for beginning and end; if "start" or "end" then its only once the amount; defaults to "start"
|
|
32
|
-
*/
|
|
33
|
-
declare const ellipsisFn: (str: string, amount?: number, position?: "start" | "end" | "center") => string;
|
|
34
|
-
/**
|
|
35
|
-
* @name pageFromUri
|
|
36
|
-
* @summary Use url variables to load the default components upon the first page visit.
|
|
37
|
-
*/
|
|
38
|
-
declare const pageFromUri: (pathname: string, fallback: string) => string;
|
|
39
|
-
/**
|
|
40
|
-
* @name rmCommas
|
|
41
|
-
* @summary Removes the commas from a string.
|
|
42
|
-
*/
|
|
43
|
-
declare const rmCommas: (val: string) => string;
|
|
44
|
-
/**
|
|
45
|
-
* @name rmDecimals
|
|
46
|
-
* @summary Removes the decimal point and decimals from a string.
|
|
47
|
-
*/
|
|
48
|
-
declare const rmDecimals: (str: string) => string;
|
|
49
|
-
/**
|
|
50
|
-
* @name shuffle
|
|
51
|
-
* @summary Shuffle a set of objects.
|
|
52
|
-
*/
|
|
53
|
-
declare const shuffle: <T>(array: T[]) => T[];
|
|
54
|
-
/**
|
|
55
|
-
* @name withTimeout
|
|
56
|
-
* @summary Timeout a promise after a specified number of milliseconds.
|
|
57
|
-
*/
|
|
58
|
-
declare const withTimeout: (ms: number, promise: Promise<unknown>, options?: {
|
|
59
|
-
onTimeout?: () => void;
|
|
60
|
-
}) => Promise<unknown>;
|
|
61
|
-
/**
|
|
62
|
-
* @name withTimeoutThrow
|
|
63
|
-
* @summary Timeout a promise after a specified number of milliseconds by throwing an error
|
|
64
|
-
*/
|
|
65
|
-
declare const withTimeoutThrow: <T>(ms: number, promise: Promise<T>, options?: {
|
|
66
|
-
onTimeout?: () => void;
|
|
67
|
-
}) => Promise<unknown>;
|
|
68
|
-
/**
|
|
69
|
-
* @name appendOrEmpty
|
|
70
|
-
* @summary Returns ` value` if a condition is truthy, or an empty string otherwise.
|
|
71
|
-
*/
|
|
72
|
-
declare const appendOrEmpty: (condition: boolean | string | undefined, value: string) => string;
|
|
73
|
-
/**
|
|
74
|
-
* @name appendOr
|
|
75
|
-
* @summary Returns ` value` if condition is truthy, or ` fallback` otherwise.
|
|
76
|
-
*/
|
|
77
|
-
declare const appendOr: (condition: boolean | string | undefined, value: string, fallback: string) => string;
|
|
78
|
-
/**
|
|
79
|
-
* @name formatAccountSs58
|
|
80
|
-
* @summary Formats an address with the supplied ss58 prefix, or returns null if invalid.
|
|
81
|
-
*/
|
|
82
|
-
declare const formatAccountSs58: (address: string, ss58Prefix: number) => string | null;
|
|
83
|
-
/**
|
|
84
|
-
* @name removeHexPrefix
|
|
85
|
-
* @summary Takes a string str as input and returns a new string with the "0x" prefix removed if it
|
|
86
|
-
* exists at the beginning of the input string.
|
|
87
|
-
*/
|
|
88
|
-
declare const removeHexPrefix: (str: string) => string;
|
|
89
|
-
declare const eqSet: (xs: Set<any>, ys: Set<any>) => boolean;
|
|
90
|
-
declare const isSuperset: (set: Set<any>, subset: Set<any>) => boolean;
|
|
91
|
-
/**
|
|
92
|
-
* Finds the maximum value among a list of BigInt values.
|
|
93
|
-
*
|
|
94
|
-
* @function maxBigInt
|
|
95
|
-
* @param {...bigint} values - A list of BigInt values to compare.
|
|
96
|
-
* @returns {bigint} The largest BigInt value in the provided list.
|
|
97
|
-
* @example
|
|
98
|
-
* // Returns the maximum BigInt value
|
|
99
|
-
* maxBigInt(10n, 50n, 30n, 100n, 20n); // 100n
|
|
100
|
-
*/
|
|
101
|
-
declare const maxBigInt: (...values: bigint[]) => bigint;
|
|
102
|
-
/**
|
|
103
|
-
* Finds the minimum value among a list of BigInt values.
|
|
104
|
-
*
|
|
105
|
-
* @function minBigInt
|
|
106
|
-
* @param {...bigint} values - A list of BigInt values to compare.
|
|
107
|
-
* @returns {bigint} The smallest BigInt value in the provided list.
|
|
108
|
-
* @example
|
|
109
|
-
* // Returns the minimum BigInt value
|
|
110
|
-
* minBigInt(10n, 50n, 30n, 100n, 20n); // 10n
|
|
111
|
-
*/
|
|
112
|
-
declare const minBigInt: (...values: bigint[]) => bigint;
|
|
113
|
-
|
|
114
|
-
export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, rmDecimals, shuffle, withTimeout, withTimeoutThrow };
|
package/base.d.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ensures a number has at least the specified number of decimal places, retaining commas in the output if they are present in the input.
|
|
3
|
-
*
|
|
4
|
-
* @function minDecimalPlaces
|
|
5
|
-
* @param {string | number | BigInt} val - The input number, which can be a `string` with or without commas, a `number`, or a `BigInt`.
|
|
6
|
-
* @param {number} minDecimals - The minimum number of decimal places to enforce.
|
|
7
|
-
* @returns {string} The formatted number as a string, padded with zeros if needed to meet `minDecimals`, retaining commas if originally provided.
|
|
8
|
-
* If `val` is invalid, returns "0".
|
|
9
|
-
* @example
|
|
10
|
-
* // Pads "1,234.5" to have at least 3 decimal places, with commas
|
|
11
|
-
* minDecimalPlaces("1,234.5", 3); // returns "1,234.500"
|
|
12
|
-
*
|
|
13
|
-
* // Returns "1234.56" unchanged
|
|
14
|
-
* minDecimalPlaces(1234.56, 2); // returns "1234.56"
|
|
15
|
-
*
|
|
16
|
-
* // Pads BigInt 1234 with 2 decimals
|
|
17
|
-
* minDecimalPlaces(BigInt(1234), 2); // returns "1234.00"
|
|
18
|
-
*/
|
|
19
|
-
declare const minDecimalPlaces: (val: string | number | bigint, minDecimals: number) => string;
|
|
20
|
-
/**
|
|
21
|
-
* @name camelize
|
|
22
|
-
* @summary Converts a string of text to camelCase.
|
|
23
|
-
*/
|
|
24
|
-
declare const camelize: (str: string) => string;
|
|
25
|
-
/**
|
|
26
|
-
* @name ellipsisFn
|
|
27
|
-
* @summary Receives an address and creates ellipsis on the given string, based on parameters.
|
|
28
|
-
* @param str - The string to apply the ellipsis on
|
|
29
|
-
* @param amount - The amount of characters that the ellipsis will be
|
|
30
|
-
* @param position - where the ellipsis will apply; if center the amount of character is the
|
|
31
|
-
* same for beginning and end; if "start" or "end" then its only once the amount; defaults to "start"
|
|
32
|
-
*/
|
|
33
|
-
declare const ellipsisFn: (str: string, amount?: number, position?: "start" | "end" | "center") => string;
|
|
34
|
-
/**
|
|
35
|
-
* @name pageFromUri
|
|
36
|
-
* @summary Use url variables to load the default components upon the first page visit.
|
|
37
|
-
*/
|
|
38
|
-
declare const pageFromUri: (pathname: string, fallback: string) => string;
|
|
39
|
-
/**
|
|
40
|
-
* @name rmCommas
|
|
41
|
-
* @summary Removes the commas from a string.
|
|
42
|
-
*/
|
|
43
|
-
declare const rmCommas: (val: string) => string;
|
|
44
|
-
/**
|
|
45
|
-
* @name rmDecimals
|
|
46
|
-
* @summary Removes the decimal point and decimals from a string.
|
|
47
|
-
*/
|
|
48
|
-
declare const rmDecimals: (str: string) => string;
|
|
49
|
-
/**
|
|
50
|
-
* @name shuffle
|
|
51
|
-
* @summary Shuffle a set of objects.
|
|
52
|
-
*/
|
|
53
|
-
declare const shuffle: <T>(array: T[]) => T[];
|
|
54
|
-
/**
|
|
55
|
-
* @name withTimeout
|
|
56
|
-
* @summary Timeout a promise after a specified number of milliseconds.
|
|
57
|
-
*/
|
|
58
|
-
declare const withTimeout: (ms: number, promise: Promise<unknown>, options?: {
|
|
59
|
-
onTimeout?: () => void;
|
|
60
|
-
}) => Promise<unknown>;
|
|
61
|
-
/**
|
|
62
|
-
* @name withTimeoutThrow
|
|
63
|
-
* @summary Timeout a promise after a specified number of milliseconds by throwing an error
|
|
64
|
-
*/
|
|
65
|
-
declare const withTimeoutThrow: <T>(ms: number, promise: Promise<T>, options?: {
|
|
66
|
-
onTimeout?: () => void;
|
|
67
|
-
}) => Promise<unknown>;
|
|
68
|
-
/**
|
|
69
|
-
* @name appendOrEmpty
|
|
70
|
-
* @summary Returns ` value` if a condition is truthy, or an empty string otherwise.
|
|
71
|
-
*/
|
|
72
|
-
declare const appendOrEmpty: (condition: boolean | string | undefined, value: string) => string;
|
|
73
|
-
/**
|
|
74
|
-
* @name appendOr
|
|
75
|
-
* @summary Returns ` value` if condition is truthy, or ` fallback` otherwise.
|
|
76
|
-
*/
|
|
77
|
-
declare const appendOr: (condition: boolean | string | undefined, value: string, fallback: string) => string;
|
|
78
|
-
/**
|
|
79
|
-
* @name formatAccountSs58
|
|
80
|
-
* @summary Formats an address with the supplied ss58 prefix, or returns null if invalid.
|
|
81
|
-
*/
|
|
82
|
-
declare const formatAccountSs58: (address: string, ss58Prefix: number) => string | null;
|
|
83
|
-
/**
|
|
84
|
-
* @name removeHexPrefix
|
|
85
|
-
* @summary Takes a string str as input and returns a new string with the "0x" prefix removed if it
|
|
86
|
-
* exists at the beginning of the input string.
|
|
87
|
-
*/
|
|
88
|
-
declare const removeHexPrefix: (str: string) => string;
|
|
89
|
-
declare const eqSet: (xs: Set<any>, ys: Set<any>) => boolean;
|
|
90
|
-
declare const isSuperset: (set: Set<any>, subset: Set<any>) => boolean;
|
|
91
|
-
/**
|
|
92
|
-
* Finds the maximum value among a list of BigInt values.
|
|
93
|
-
*
|
|
94
|
-
* @function maxBigInt
|
|
95
|
-
* @param {...bigint} values - A list of BigInt values to compare.
|
|
96
|
-
* @returns {bigint} The largest BigInt value in the provided list.
|
|
97
|
-
* @example
|
|
98
|
-
* // Returns the maximum BigInt value
|
|
99
|
-
* maxBigInt(10n, 50n, 30n, 100n, 20n); // 100n
|
|
100
|
-
*/
|
|
101
|
-
declare const maxBigInt: (...values: bigint[]) => bigint;
|
|
102
|
-
/**
|
|
103
|
-
* Finds the minimum value among a list of BigInt values.
|
|
104
|
-
*
|
|
105
|
-
* @function minBigInt
|
|
106
|
-
* @param {...bigint} values - A list of BigInt values to compare.
|
|
107
|
-
* @returns {bigint} The smallest BigInt value in the provided list.
|
|
108
|
-
* @example
|
|
109
|
-
* // Returns the minimum BigInt value
|
|
110
|
-
* minBigInt(10n, 50n, 30n, 100n, 20n); // 10n
|
|
111
|
-
*/
|
|
112
|
-
declare const minBigInt: (...values: bigint[]) => bigint;
|
|
113
|
-
|
|
114
|
-
export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, rmDecimals, shuffle, withTimeout, withTimeoutThrow };
|
package/base.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
// src/base.ts
|
|
2
|
-
import { encodeAddress } from "dedot/utils";
|
|
3
|
-
var minDecimalPlaces = (val, minDecimals) => {
|
|
4
|
-
try {
|
|
5
|
-
const retainCommas = typeof val === "string" && val.includes(",");
|
|
6
|
-
const strVal = typeof val === "string" ? val.replace(/,/g, "") : val.toString();
|
|
7
|
-
const [integerPart, fractionalPart = ""] = strVal.split(".");
|
|
8
|
-
const whole = BigInt(integerPart || "0");
|
|
9
|
-
const missingDecimals = minDecimals - fractionalPart.length;
|
|
10
|
-
const formattedWhole = retainCommas ? Intl.NumberFormat("en-US").format(whole) : whole.toString();
|
|
11
|
-
return missingDecimals > 0 ? `${formattedWhole}.${fractionalPart}${"0".repeat(missingDecimals)}` : `${formattedWhole}.${fractionalPart}`;
|
|
12
|
-
} catch (e) {
|
|
13
|
-
return "0";
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
var camelize = (str) => {
|
|
17
|
-
const convertToString = (string) => {
|
|
18
|
-
if (string) {
|
|
19
|
-
if (typeof string === "string") {
|
|
20
|
-
return string;
|
|
21
|
-
}
|
|
22
|
-
return String(string);
|
|
23
|
-
}
|
|
24
|
-
return "";
|
|
25
|
-
};
|
|
26
|
-
const toWords = (inp) => convertToString(inp).match(
|
|
27
|
-
/[A-Z\xC0-\xD6\xD8-\xDE]?[a-z\xDF-\xF6\xF8-\xFF]+|[A-Z\xC0-\xD6\xD8-\xDE]+(?![a-z\xDF-\xF6\xF8-\xFF])|\d+/g
|
|
28
|
-
);
|
|
29
|
-
const simpleCamelCase = (inp) => {
|
|
30
|
-
let result = "";
|
|
31
|
-
for (let i = 0; i < inp?.length; i++) {
|
|
32
|
-
const currString = inp[i];
|
|
33
|
-
let tmpStr = currString.toLowerCase();
|
|
34
|
-
if (i != 0) {
|
|
35
|
-
tmpStr = tmpStr.slice(0, 1).toUpperCase() + tmpStr.slice(1, tmpStr.length);
|
|
36
|
-
}
|
|
37
|
-
result += tmpStr;
|
|
38
|
-
}
|
|
39
|
-
return result;
|
|
40
|
-
};
|
|
41
|
-
const w = toWords(str)?.map((a) => a.toLowerCase());
|
|
42
|
-
return simpleCamelCase(w || []);
|
|
43
|
-
};
|
|
44
|
-
var ellipsisFn = (str, amount = 6, position = "center") => {
|
|
45
|
-
const half = str.length / 2;
|
|
46
|
-
if (amount <= 4) {
|
|
47
|
-
if (position === "center") {
|
|
48
|
-
return str.slice(0, 4) + "..." + str.slice(-4);
|
|
49
|
-
}
|
|
50
|
-
if (position === "end") {
|
|
51
|
-
return str.slice(0, 4) + "...";
|
|
52
|
-
}
|
|
53
|
-
return "..." + str.slice(-4);
|
|
54
|
-
}
|
|
55
|
-
if (position === "center") {
|
|
56
|
-
return amount >= (str.length - 2) / 2 ? str.slice(0, half - 3) + "..." + str.slice(-(half - 3)) : str.slice(0, amount) + "..." + str.slice(-amount);
|
|
57
|
-
}
|
|
58
|
-
if (amount >= str.length) {
|
|
59
|
-
if (position === "end") {
|
|
60
|
-
return str.slice(0, str.length - 3) + "...";
|
|
61
|
-
}
|
|
62
|
-
return "..." + str.slice(-(str.length - 3));
|
|
63
|
-
} else {
|
|
64
|
-
if (position === "end") {
|
|
65
|
-
return str.slice(0, amount) + "...";
|
|
66
|
-
}
|
|
67
|
-
return "..." + str.slice(amount);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
var pageFromUri = (pathname, fallback) => {
|
|
71
|
-
const lastUriItem = pathname.substring(pathname.lastIndexOf("/") + 1);
|
|
72
|
-
const page = lastUriItem.trim() === "" ? fallback : lastUriItem;
|
|
73
|
-
return page.trim();
|
|
74
|
-
};
|
|
75
|
-
var rmCommas = (val) => val.replace(/,/g, "");
|
|
76
|
-
var rmDecimals = (str) => str.split(".")[0];
|
|
77
|
-
var shuffle = (array) => {
|
|
78
|
-
let currentIndex = array.length;
|
|
79
|
-
let randomIndex;
|
|
80
|
-
while (currentIndex !== 0) {
|
|
81
|
-
randomIndex = Math.floor(Math.random() * currentIndex);
|
|
82
|
-
currentIndex--;
|
|
83
|
-
[array[currentIndex], array[randomIndex]] = [
|
|
84
|
-
array[randomIndex],
|
|
85
|
-
array[currentIndex]
|
|
86
|
-
];
|
|
87
|
-
}
|
|
88
|
-
return array;
|
|
89
|
-
};
|
|
90
|
-
var withTimeout = (ms, promise, options) => {
|
|
91
|
-
const timeout = new Promise(
|
|
92
|
-
(resolve) => setTimeout(async () => {
|
|
93
|
-
if (typeof options?.onTimeout === "function") {
|
|
94
|
-
options.onTimeout();
|
|
95
|
-
}
|
|
96
|
-
resolve(void 0);
|
|
97
|
-
}, ms)
|
|
98
|
-
);
|
|
99
|
-
return Promise.race([promise, timeout]);
|
|
100
|
-
};
|
|
101
|
-
var withTimeoutThrow = (ms, promise, options) => {
|
|
102
|
-
const timeout = new Promise(
|
|
103
|
-
(reject) => setTimeout(async () => {
|
|
104
|
-
if (typeof options?.onTimeout === "function") {
|
|
105
|
-
options.onTimeout();
|
|
106
|
-
}
|
|
107
|
-
reject("Function timeout");
|
|
108
|
-
}, ms)
|
|
109
|
-
);
|
|
110
|
-
return Promise.race([promise, timeout]);
|
|
111
|
-
};
|
|
112
|
-
var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
|
|
113
|
-
var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
|
|
114
|
-
var formatAccountSs58 = (address, ss58Prefix) => {
|
|
115
|
-
try {
|
|
116
|
-
return encodeAddress(address, ss58Prefix);
|
|
117
|
-
} catch (e) {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
var removeHexPrefix = (str) => str.replace(/^0x/, "");
|
|
122
|
-
var eqSet = (xs, ys) => xs.size === ys.size && [...xs].every((x) => ys.has(x));
|
|
123
|
-
var isSuperset = (set, subset) => {
|
|
124
|
-
for (const elem of subset) {
|
|
125
|
-
if (!set.has(elem)) {
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return true;
|
|
130
|
-
};
|
|
131
|
-
var maxBigInt = (...values) => values.reduce((max, current) => current > max ? current : max);
|
|
132
|
-
var minBigInt = (...values) => values.reduce((min, current) => current < min ? current : min);
|
|
133
|
-
export {
|
|
134
|
-
appendOr,
|
|
135
|
-
appendOrEmpty,
|
|
136
|
-
camelize,
|
|
137
|
-
ellipsisFn,
|
|
138
|
-
eqSet,
|
|
139
|
-
formatAccountSs58,
|
|
140
|
-
isSuperset,
|
|
141
|
-
maxBigInt,
|
|
142
|
-
minBigInt,
|
|
143
|
-
minDecimalPlaces,
|
|
144
|
-
pageFromUri,
|
|
145
|
-
removeHexPrefix,
|
|
146
|
-
rmCommas,
|
|
147
|
-
rmDecimals,
|
|
148
|
-
shuffle,
|
|
149
|
-
withTimeout,
|
|
150
|
-
withTimeoutThrow
|
|
151
|
-
};
|
|
152
|
-
/* @license Copyright 2024 w3ux authors & contributors
|
|
153
|
-
SPDX-License-Identifier: GPL-3.0-only */
|
package/convert.cjs
DELETED
|
@@ -1,40 +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/convert.ts
|
|
21
|
-
var convert_exports = {};
|
|
22
|
-
__export(convert_exports, {
|
|
23
|
-
u8aConcat: () => u8aConcat
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(convert_exports);
|
|
26
|
-
var u8aConcat = (...u8as) => {
|
|
27
|
-
const totalLength = u8as.reduce((sum, u8a) => sum + u8a.length, 0);
|
|
28
|
-
const result = new Uint8Array(totalLength);
|
|
29
|
-
let offset = 0;
|
|
30
|
-
for (const u8a of u8as) {
|
|
31
|
-
result.set(u8a, offset);
|
|
32
|
-
offset += u8a.length;
|
|
33
|
-
}
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
-
0 && (module.exports = {
|
|
38
|
-
u8aConcat
|
|
39
|
-
});
|
|
40
|
-
// /* @license Copyright 2024 w3ux authors & contributors
|
package/convert.d.cts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Concatenates multiple Uint8Array instances into a single Uint8Array.
|
|
3
|
-
*
|
|
4
|
-
* @param {Uint8Array[]} u8as - An array of Uint8Array instances to concatenate.
|
|
5
|
-
* @returns {Uint8Array} A new Uint8Array containing all the input arrays concatenated.
|
|
6
|
-
*/
|
|
7
|
-
declare const u8aConcat: (...u8as: Uint8Array[]) => Uint8Array;
|
|
8
|
-
|
|
9
|
-
export { u8aConcat };
|
package/convert.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Concatenates multiple Uint8Array instances into a single Uint8Array.
|
|
3
|
-
*
|
|
4
|
-
* @param {Uint8Array[]} u8as - An array of Uint8Array instances to concatenate.
|
|
5
|
-
* @returns {Uint8Array} A new Uint8Array containing all the input arrays concatenated.
|
|
6
|
-
*/
|
|
7
|
-
declare const u8aConcat: (...u8as: Uint8Array[]) => Uint8Array;
|
|
8
|
-
|
|
9
|
-
export { u8aConcat };
|
package/convert.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// src/convert.ts
|
|
2
|
-
var u8aConcat = (...u8as) => {
|
|
3
|
-
const totalLength = u8as.reduce((sum, u8a) => sum + u8a.length, 0);
|
|
4
|
-
const result = new Uint8Array(totalLength);
|
|
5
|
-
let offset = 0;
|
|
6
|
-
for (const u8a of u8as) {
|
|
7
|
-
result.set(u8a, offset);
|
|
8
|
-
offset += u8a.length;
|
|
9
|
-
}
|
|
10
|
-
return result;
|
|
11
|
-
};
|
|
12
|
-
export {
|
|
13
|
-
u8aConcat
|
|
14
|
-
};
|
|
15
|
-
// /* @license Copyright 2024 w3ux authors & contributors
|
package/types.cjs
DELETED
|
@@ -1,20 +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 __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
|
|
16
|
-
// src/types.ts
|
|
17
|
-
var types_exports = {};
|
|
18
|
-
module.exports = __toCommonJS(types_exports);
|
|
19
|
-
/* @license Copyright 2024 w3ux authors & contributors
|
|
20
|
-
SPDX-License-Identifier: GPL-3.0-only */
|
package/types.d.cts
DELETED
package/types.d.ts
DELETED
package/types.js
DELETED