@w3ux/utils 2.3.2 → 3.1.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.cjs +0 -30
- package/index.cjs.map +1 -1
- package/index.d.cts +1 -17
- package/index.d.ts +1 -17
- package/index.js +0 -27
- package/index.js.map +1 -1
- package/package.json +1 -4
package/index.cjs
CHANGED
|
@@ -29,10 +29,8 @@ __export(index_exports, {
|
|
|
29
29
|
ellipsisFn: () => ellipsisFn,
|
|
30
30
|
eqSet: () => eqSet,
|
|
31
31
|
extractUrlValue: () => extractUrlValue,
|
|
32
|
-
formatAccountSs58: () => formatAccountSs58,
|
|
33
32
|
inChrome: () => inChrome,
|
|
34
33
|
isSuperset: () => isSuperset,
|
|
35
|
-
isValidAddress: () => isValidAddress,
|
|
36
34
|
isValidHttpUrl: () => isValidHttpUrl,
|
|
37
35
|
localStorageOrDefault: () => localStorageOrDefault,
|
|
38
36
|
makeCancelable: () => makeCancelable,
|
|
@@ -53,7 +51,6 @@ __export(index_exports, {
|
|
|
53
51
|
shuffle: () => shuffle,
|
|
54
52
|
snakeToCamel: () => snakeToCamel,
|
|
55
53
|
sortWithNull: () => sortWithNull,
|
|
56
|
-
tryFormatSs58: () => tryFormatSs58,
|
|
57
54
|
u8aConcat: () => u8aConcat,
|
|
58
55
|
unescape: () => unescape,
|
|
59
56
|
unimplemented: () => unimplemented,
|
|
@@ -65,7 +62,6 @@ __export(index_exports, {
|
|
|
65
62
|
module.exports = __toCommonJS(index_exports);
|
|
66
63
|
|
|
67
64
|
// src/base.ts
|
|
68
|
-
var import_utils = require("dedot/utils");
|
|
69
65
|
var minDecimalPlaces = (val, minDecimals) => {
|
|
70
66
|
try {
|
|
71
67
|
const retainCommas = typeof val === "string" && val.includes(",");
|
|
@@ -177,20 +173,6 @@ var withTimeoutThrow = (ms, promise, options) => {
|
|
|
177
173
|
};
|
|
178
174
|
var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
|
|
179
175
|
var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
|
|
180
|
-
var formatAccountSs58 = (address, ss58) => {
|
|
181
|
-
try {
|
|
182
|
-
return (0, import_utils.encodeAddress)(address, ss58);
|
|
183
|
-
} catch {
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
var tryFormatSs58 = (address, ss58) => {
|
|
188
|
-
try {
|
|
189
|
-
return (0, import_utils.encodeAddress)(address, ss58);
|
|
190
|
-
} catch {
|
|
191
|
-
return address;
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
176
|
var removeHexPrefix = (str) => str.replace(/^0x/, "");
|
|
195
177
|
var eqSet = (xs, ys) => xs.size === ys.size && [...xs].every((x) => ys.has(x));
|
|
196
178
|
var isSuperset = (set, subset) => {
|
|
@@ -217,7 +199,6 @@ var u8aConcat = (...u8as) => {
|
|
|
217
199
|
};
|
|
218
200
|
|
|
219
201
|
// src/unit.ts
|
|
220
|
-
var import_utils2 = require("dedot/utils");
|
|
221
202
|
var planckToUnit = (val, units) => {
|
|
222
203
|
try {
|
|
223
204
|
units = Math.max(Math.round(units), 0);
|
|
@@ -273,14 +254,6 @@ var localStorageOrDefault = (key, _default, parse = false) => {
|
|
|
273
254
|
}
|
|
274
255
|
return val;
|
|
275
256
|
};
|
|
276
|
-
var isValidAddress = (address) => {
|
|
277
|
-
try {
|
|
278
|
-
(0, import_utils2.decodeAddress)(address);
|
|
279
|
-
return true;
|
|
280
|
-
} catch {
|
|
281
|
-
return false;
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
257
|
var extractUrlValue = (key, url) => {
|
|
285
258
|
if (typeof url === "undefined") {
|
|
286
259
|
url = window.location.href;
|
|
@@ -430,10 +403,8 @@ var mergeDeep = (target, ...sources) => {
|
|
|
430
403
|
ellipsisFn,
|
|
431
404
|
eqSet,
|
|
432
405
|
extractUrlValue,
|
|
433
|
-
formatAccountSs58,
|
|
434
406
|
inChrome,
|
|
435
407
|
isSuperset,
|
|
436
|
-
isValidAddress,
|
|
437
408
|
isValidHttpUrl,
|
|
438
409
|
localStorageOrDefault,
|
|
439
410
|
makeCancelable,
|
|
@@ -454,7 +425,6 @@ var mergeDeep = (target, ...sources) => {
|
|
|
454
425
|
shuffle,
|
|
455
426
|
snakeToCamel,
|
|
456
427
|
sortWithNull,
|
|
457
|
-
tryFormatSs58,
|
|
458
428
|
u8aConcat,
|
|
459
429
|
unescape,
|
|
460
430
|
unimplemented,
|
package/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/base.ts","../src/convert.ts","../src/unit.ts"],"sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nexport * from './base'\nexport * from './convert'\nexport * from './unit'\n","/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { encodeAddress } from 'dedot/utils'\n\n/**\n * Ensures a number has at least the specified number of decimal places, retaining commas in the output if they are present in the input.\n *\n * @function minDecimalPlaces\n * @param {string | number | BigInt} val - The input number, which can be a `string` with or without commas, a `number`, or a `BigInt`.\n * @param {number} minDecimals - The minimum number of decimal places to enforce.\n * @returns {string} The formatted number as a string, padded with zeros if needed to meet `minDecimals`, retaining commas if originally provided.\n * If `val` is invalid, returns \"0\".\n * @example\n * // Pads \"1,234.5\" to have at least 3 decimal places, with commas\n * minDecimalPlaces(\"1,234.5\", 3); // returns \"1,234.500\"\n *\n * // Returns \"1234.56\" unchanged\n * minDecimalPlaces(1234.56, 2); // returns \"1234.56\"\n *\n * // Pads BigInt 1234 with 2 decimals\n * minDecimalPlaces(BigInt(1234), 2); // returns \"1234.00\"\n */\nexport const minDecimalPlaces = (\n\tval: string | number | bigint,\n\tminDecimals: number,\n): string => {\n\ttry {\n\t\t// Determine if we should retain commas based on original input type\n\t\tconst retainCommas = typeof val === 'string' && val.includes(',')\n\n\t\t// Convert `val` to a plain string for processing\n\t\tconst strVal =\n\t\t\ttypeof val === 'string' ? val.replace(/,/g, '') : val.toString()\n\n\t\t// Separate integer and decimal parts\n\t\tconst [integerPart, fractionalPart = ''] = strVal.split('.')\n\n\t\t// Parse the integer part as a BigInt\n\t\tconst whole = BigInt(integerPart || '0')\n\n\t\t// Calculate missing decimal places\n\t\tconst missingDecimals = minDecimals - fractionalPart.length\n\n\t\t// Format the integer part back with commas only if the input had commas\n\t\tconst formattedWhole = retainCommas\n\t\t\t? Intl.NumberFormat('en-US').format(whole)\n\t\t\t: whole.toString()\n\n\t\t// If missing decimals are needed, pad with zeros; otherwise, return the original value\n\t\treturn missingDecimals > 0\n\t\t\t? `${formattedWhole}.${fractionalPart}${'0'.repeat(missingDecimals)}`\n\t\t\t: `${formattedWhole}.${fractionalPart}`\n\t} catch {\n\t\t// The provided value is not a valid number, return \"0\".\n\t\treturn '0'\n\t}\n}\n\n/**\n * @name camelize\n * @summary Converts a string of text to camelCase.\n */\nexport const camelize = (str: string) => {\n\tconst convertToString = (string: string) => {\n\t\tif (string) {\n\t\t\tif (typeof string === 'string') {\n\t\t\t\treturn string\n\t\t\t}\n\t\t\treturn String(string)\n\t\t}\n\t\treturn ''\n\t}\n\n\tconst toWords = (inp: string) =>\n\t\tconvertToString(inp).match(\n\t\t\t/[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,\n\t\t)\n\n\tconst simpleCamelCase = (inp: string[]) => {\n\t\tlet result = ''\n\t\tfor (let i = 0; i < inp?.length; i++) {\n\t\t\tconst currString = inp[i]\n\t\t\tlet tmpStr = currString.toLowerCase()\n\t\t\tif (i !== 0) {\n\t\t\t\ttmpStr =\n\t\t\t\t\ttmpStr.slice(0, 1).toUpperCase() + tmpStr.slice(1, tmpStr.length)\n\t\t\t}\n\t\t\tresult += tmpStr\n\t\t}\n\t\treturn result\n\t}\n\n\tconst w = toWords(str)?.map((a) => a.toLowerCase())\n\treturn simpleCamelCase(w || [])\n}\n\n/**\n * @name ellipsisFn\n * @summary Receives an address and creates ellipsis on the given string, based on parameters.\n * @param str - The string to apply the ellipsis on\n * @param amount - The amount of characters that the ellipsis will be\n * @param position - where the ellipsis will apply; if center the amount of character is the\n * same for beginning and end; if \"start\" or \"end\" then its only once the amount; defaults to \"start\"\n */\nexport const ellipsisFn = (\n\tstr: string,\n\tamount = 6,\n\tposition: 'start' | 'end' | 'center' = 'center',\n) => {\n\tconst half = str.length / 2\n\n\t// having an amount less than 4 is a bit extreme so we default there\n\tif (amount <= 4) {\n\t\tif (position === 'center') {\n\t\t\treturn str.slice(0, 4) + '...' + str.slice(-4)\n\t\t}\n\t\tif (position === 'end') {\n\t\t\treturn str.slice(0, 4) + '...'\n\t\t}\n\t\treturn '...' + str.slice(-4)\n\t}\n\t// if the amount requested is in a \"logical\" amount - meaning that it can display the address\n\t// without repeating the same information twice - then go for it;\n\tif (position === 'center') {\n\t\treturn amount >= (str.length - 2) / 2\n\t\t\t? str.slice(0, half - 3) + '...' + str.slice(-(half - 3))\n\t\t\t: str.slice(0, amount) + '...' + str.slice(-amount)\n\t}\n\t// else, the user has been mistaskenly extreme, so just show the maximum possible amount\n\tif (amount >= str.length) {\n\t\tif (position === 'end') {\n\t\t\treturn str.slice(0, str.length - 3) + '...'\n\t\t}\n\t\treturn '...' + str.slice(-(str.length - 3))\n\t} else {\n\t\tif (position === 'end') {\n\t\t\treturn str.slice(0, amount) + '...'\n\t\t}\n\t\treturn '...' + str.slice(amount)\n\t}\n}\n\n/**\n * @name pageFromUri\n * @summary Use url variables to load the default components upon the first page visit.\n */\nexport const pageFromUri = (pathname: string, fallback: string) => {\n\tconst lastUriItem = pathname.substring(pathname.lastIndexOf('/') + 1)\n\tconst page = lastUriItem.trim() === '' ? fallback : lastUriItem\n\treturn page.trim()\n}\n\n/**\n * @name rmCommas\n * @summary Removes the commas from a string.\n */\nexport const rmCommas = (val: string): string => val.replace(/,/g, '')\n\n/**\n * @name rmDecimals\n * @summary Removes the decimal point and decimals from a string.\n */\nexport const rmDecimals = (str: string) => str.split('.')[0]\n\n/**\n * @name shuffle\n * @summary Shuffle a set of objects.\n */\nexport const shuffle = <T>(array: T[]) => {\n\tlet currentIndex = array.length\n\tlet randomIndex\n\twhile (currentIndex !== 0) {\n\t\trandomIndex = Math.floor(Math.random() * currentIndex)\n\t\tcurrentIndex--\n\t\t;[array[currentIndex], array[randomIndex]] = [\n\t\t\tarray[randomIndex],\n\t\t\tarray[currentIndex],\n\t\t]\n\t}\n\treturn array\n}\n\n/**\n * @name withTimeout\n * @summary Timeout a promise after a specified number of milliseconds.\n */\nexport const withTimeout = (\n\tms: number,\n\tpromise: Promise<unknown>,\n\toptions?: {\n\t\tonTimeout?: () => void\n\t},\n) => {\n\tconst timeout = new Promise((resolve) =>\n\t\tsetTimeout(async () => {\n\t\t\tif (typeof options?.onTimeout === 'function') {\n\t\t\t\toptions.onTimeout()\n\t\t\t}\n\t\t\tresolve(undefined)\n\t\t}, ms),\n\t)\n\treturn Promise.race([promise, timeout])\n}\n\n/**\n * @name withTimeoutThrow\n * @summary Timeout a promise after a specified number of milliseconds by throwing an error\n */\nexport const withTimeoutThrow = <T>(\n\tms: number,\n\tpromise: Promise<T>,\n\toptions?: {\n\t\tonTimeout?: () => void\n\t},\n) => {\n\tconst timeout = new Promise((reject) =>\n\t\tsetTimeout(async () => {\n\t\t\tif (typeof options?.onTimeout === 'function') {\n\t\t\t\toptions.onTimeout()\n\t\t\t}\n\t\t\treject('Function timeout')\n\t\t}, ms),\n\t)\n\treturn Promise.race([promise, timeout])\n}\n\n/**\n * @name appendOrEmpty\n * @summary Returns ` value` if a condition is truthy, or an empty string otherwise.\n */\nexport const appendOrEmpty = (\n\tcondition: boolean | string | undefined,\n\tvalue: string,\n) => (condition ? ` ${value}` : '')\n\n/**\n * @name appendOr\n * @summary Returns ` value` if condition is truthy, or ` fallback` otherwise.\n */\nexport const appendOr = (\n\tcondition: boolean | string | undefined,\n\tvalue: string,\n\tfallback: string,\n) => (condition ? ` ${value}` : ` ${fallback}`)\n\n/**\n * @name formatAccountSs58\n * @summary Formats an address with the supplied ss58 prefix, or returns null if invalid.\n */\nexport const formatAccountSs58 = (\n\taddress: string,\n\tss58: number,\n): string | null => {\n\ttry {\n\t\treturn encodeAddress(address, ss58)\n\t} catch {\n\t\treturn null\n\t}\n}\n\n/**\n * @name tryFormatSs58\n * @summary Formats an address with the supplied ss58 prefix, or returns the original address if\n * invalid.\n */\nexport const tryFormatSs58 = (address: string, ss58: number): string => {\n\ttry {\n\t\treturn encodeAddress(address, ss58)\n\t} catch {\n\t\treturn address\n\t}\n}\n\n/**\n * @name removeHexPrefix\n * @summary Takes a string str as input and returns a new string with the \"0x\" prefix removed if it\n * exists at the beginning of the input string.\n */\nexport const removeHexPrefix = (str: string): string => str.replace(/^0x/, '')\n\n// Check if 2 sets contain the same elements.\n// biome-ignore lint/suspicious/noExplicitAny: <>\nexport const eqSet = (xs: Set<any>, ys: Set<any>) =>\n\txs.size === ys.size && [...xs].every((x) => ys.has(x))\n\n// Check if one set contains all the elements of another set.\n// biome-ignore lint/suspicious/noExplicitAny: <>\nexport const isSuperset = (set: Set<any>, subset: Set<any>) => {\n\tfor (const elem of subset) {\n\t\tif (!set.has(elem)) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\n/**\n * Finds the maximum value among a list of BigInt values.\n *\n * @function maxBigInt\n * @param {...bigint} values - A list of BigInt values to compare.\n * @returns {bigint} The largest BigInt value in the provided list.\n * @example\n * // Returns the maximum BigInt value\n * maxBigInt(10n, 50n, 30n, 100n, 20n); // 100n\n */\nexport const maxBigInt = (...values: bigint[]): bigint =>\n\tvalues.reduce((max, current) => (current > max ? current : max))\n\n/**\n * Finds the minimum value among a list of BigInt values.\n *\n * @function minBigInt\n * @param {...bigint} values - A list of BigInt values to compare.\n * @returns {bigint} The smallest BigInt value in the provided list.\n * @example\n * // Returns the minimum BigInt value\n * minBigInt(10n, 50n, 30n, 100n, 20n); // 10n\n */\nexport const minBigInt = (...values: bigint[]): bigint =>\n\tvalues.reduce((min, current) => (current < min ? current : min))\n","// /* @license Copyright 2024 w3ux authors & contributors\n// SPDX-License-Identifier: GPL-3.0-only */\n\n/**\n * Concatenates multiple Uint8Array instances into a single Uint8Array.\n *\n * @param {Uint8Array[]} u8as - An array of Uint8Array instances to concatenate.\n * @returns {Uint8Array} A new Uint8Array containing all the input arrays concatenated.\n */\nexport const u8aConcat = (...u8as: Uint8Array[]): Uint8Array => {\n\t// Calculate the total length of the resulting Uint8Array\n\tconst totalLength = u8as.reduce((sum, u8a) => sum + u8a.length, 0)\n\n\t// Create a new Uint8Array with the total length\n\tconst result = new Uint8Array(totalLength)\n\n\tlet offset = 0 // Initialize the offset for placing elements\n\tfor (const u8a of u8as) {\n\t\tresult.set(u8a, offset) // Set the current Uint8Array at the current offset\n\t\toffset += u8a.length // Update the offset for the next Uint8Array\n\t}\n\n\treturn result\n}\n","/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { decodeAddress } from 'dedot/utils'\nimport type { RefObject } from 'react'\nimport { rmCommas, rmDecimals } from './base'\nimport type { AnyObject } from './types'\n\n/**\n * Converts an on-chain balance value from planck to a decimal value in token units.\n *\n * @function planckToUnit\n * @param {number | BigInt | string} val - The balance value in planck. Accepts a `number`, `BigInt`, or `string`.\n * @param {number} units - The number of decimal places in the token unit (10^units planck per 1 token).\n * @returns {string} The equivalent token unit value as a decimal string.\n * @example\n * // Convert 1500000000000 planck to tokens with 12 decimal places\n * planckToUnit(\"1500000000000\", 12); // returns \"1.5\"\n */\nexport const planckToUnit = (\n\tval: number | bigint | string,\n\tunits: number,\n): string => {\n\ttry {\n\t\t// Ensure `units` is a positive integer.\n\t\tunits = Math.max(Math.round(units), 0)\n\n\t\t// Convert `val` to BigInt based on its type\n\t\tconst bigIntVal =\n\t\t\ttypeof val === 'bigint'\n\t\t\t\t? val\n\t\t\t\t: BigInt(\n\t\t\t\t\t\ttypeof val === 'number'\n\t\t\t\t\t\t\t? Math.floor(val).toString()\n\t\t\t\t\t\t\t: rmDecimals(rmCommas(val)),\n\t\t\t\t\t)\n\n\t\tconst divisor = units === 0 ? 1n : BigInt(10) ** BigInt(units)\n\n\t\t// Integer division and remainder for the fractional part\n\t\tconst integerPart = bigIntVal / divisor\n\t\tconst fractionalPart = bigIntVal % divisor\n\n\t\t// Format fractional part with leading zeros to maintain `units` decimal places\n\t\tconst fractionalStr =\n\t\t\tunits > 0 ? `.${fractionalPart.toString().padStart(units, '0')}` : ``\n\n\t\t// Combine integer and fractional parts as a decimal string\n\t\treturn `${integerPart}${fractionalStr}`\n\t} catch {\n\t\treturn '0'\n\t}\n}\n\n/**\n * Converts a token unit value to an integer value in planck.\n *\n * @function unitToPlanck\n * @param {string | number | BigInt} val - The token unit value to convert. Accepts a string, number, or BigInt.\n * @param {number} units - The number of decimal places for conversion (10^units planck per 1 token).\n * @returns {BigInt} The equivalent value in planck as a BigInt.\n * @example\n * // Convert \"1.5\" tokens to planck with 12 decimal places\n * unitToPlanck(\"1.5\", 12); // returns BigInt(\"1500000000000\")\n */\nexport const unitToPlanck = (\n\tval: string | number | bigint,\n\tunits: number,\n): bigint => {\n\ttry {\n\t\t// Ensure `units` is a positive integer.\n\t\tunits = Math.max(Math.round(units), 0)\n\n\t\t// Convert `val` to a string; if empty or invalid, default to \"0\"\n\t\tconst strVal =\n\t\t\t(typeof val === 'string' ? rmCommas(val) : val.toString()) || '0'\n\n\t\t// Split into integer and fractional parts\n\t\tconst [integerPart, fractionalPart = ''] = strVal.split('.')\n\n\t\t// Process the integer part by converting to BigInt and scaling it to the given units\n\t\tlet bigIntValue = BigInt(integerPart) * BigInt(10) ** BigInt(units)\n\n\t\t// Process the fractional part if it exists\n\t\tif (fractionalPart) {\n\t\t\tlet fractionalValue: bigint\n\n\t\t\tif (fractionalPart.length > units) {\n\t\t\t\t// If fractional part exceeds units, truncate it\n\t\t\t\tfractionalValue = BigInt(fractionalPart.slice(0, units))\n\t\t\t} else {\n\t\t\t\t// Otherwise, pad the fractional part to match units\n\t\t\t\tfractionalValue = BigInt(fractionalPart.padEnd(units, '0'))\n\t\t\t}\n\n\t\t\tbigIntValue += fractionalValue\n\t\t}\n\n\t\treturn bigIntValue\n\t} catch {\n\t\treturn BigInt(0)\n\t}\n}\n\n/**\n * @name remToUnit\n * @summary Converts a rem string to a number.\n */\nexport const remToUnit = (rem: string) =>\n\tNumber(rem.slice(0, rem.length - 3)) *\n\tparseFloat(getComputedStyle(document.documentElement).fontSize)\n\n/**\n * @name capitalizeFirstLetter\n * @summary Capitalize the first letter of a string.\n */\nexport const capitalizeFirstLetter = (string: string) =>\n\tstring.charAt(0).toUpperCase() + string.slice(1)\n\n/**\n * @name snakeToCamel\n * @summary converts a string from snake / kebab-case to camel-case.\n */\nexport const snakeToCamel = (str: string) =>\n\tstr\n\t\t.toLowerCase()\n\t\t.replace(/([-_][a-z])/g, (group) =>\n\t\t\tgroup.toUpperCase().replace('-', '').replace('_', ''),\n\t\t)\n\n/**\n * @name setStateWithRef\n * @summary Synchronize React state and its reference with the provided value.\n */\nexport const setStateWithRef = <T>(\n\tvalue: T,\n\tsetState: (_state: T) => void,\n\tref: RefObject<T>,\n): void => {\n\tsetState(value)\n\tref.current = value\n}\n\n/**\n * @name localStorageOrDefault\n * @summary Retrieve the local stroage value with the key, return defult value if it is not\n * found.\n */\nexport const localStorageOrDefault = <T>(\n\tkey: string,\n\t_default: T,\n\tparse = false,\n): T | string => {\n\tconst val: string | null = localStorage.getItem(key)\n\n\tif (val === null) {\n\t\treturn _default\n\t}\n\n\tif (parse) {\n\t\treturn JSON.parse(val) as T\n\t}\n\treturn val\n}\n\n/**\n * @name isValidAddress\n * @summary Return whether an address is valid Substrate address.\n */\nexport const isValidAddress = (address: string): boolean => {\n\ttry {\n\t\tdecodeAddress(address)\n\t\treturn true\n\t} catch {\n\t\treturn false\n\t}\n}\n\n/**\n * @name extractUrlValue\n * @summary Extracts a URL value from a URL string.\n */\nexport const extractUrlValue = (key: string, url?: string) => {\n\tif (typeof url === 'undefined') {\n\t\turl = window.location.href\n\t}\n\tconst match = url.match(`[?&]${key}=([^&]+)`)\n\treturn match ? match[1] : null\n}\n\n/**\n * @name varToUrlHash\n * @summary Puts a variable into the URL hash as a param.\n * @description\n * Since url variables are added to the hash and are not treated as URL params, the params are split\n * and parsed into a `URLSearchParams`.\n */\nexport const varToUrlHash = (\n\tkey: string,\n\tval: string,\n\taddIfMissing: boolean,\n) => {\n\tconst hash = window.location.hash\n\tconst [page, params] = hash.split('?')\n\tconst searchParams = new URLSearchParams(params)\n\n\tif (searchParams.get(key) === null && !addIfMissing) {\n\t\treturn\n\t}\n\tsearchParams.set(key, val)\n\twindow.location.hash = `${page}?${searchParams.toString()}`\n}\n\n/**\n * @name removeVarFromUrlHash\n * @summary\n * Removes a variable `key` from the URL hash if it exists. Removes dangling `?` if no URL variables\n * exist.\n */\nexport const removeVarFromUrlHash = (key: string) => {\n\tconst hash = window.location.hash\n\tconst [page, params] = hash.split('?')\n\tconst searchParams = new URLSearchParams(params)\n\tif (searchParams.get(key) === null) {\n\t\treturn\n\t}\n\tsearchParams.delete(key)\n\tconst paramsAsStr = searchParams.toString()\n\twindow.location.hash = `${page}${paramsAsStr ? `?${paramsAsStr}` : ``}`\n}\n\n/**\n * @name sortWithNull\n * @summary Sorts an array with nulls last.\n */\nexport const sortWithNull =\n\t(ascending: boolean) => (a: unknown, b: unknown) => {\n\t\t// if both items are undefined, treat them as equal\n\t\tif (typeof a === 'undefined' && typeof b === 'undefined') {\n\t\t\treturn 0\n\t\t}\n\t\t// if either item is undefined, sort it last\n\t\tif (typeof a === 'undefined' || typeof b === 'undefined') {\n\t\t\treturn typeof a === 'undefined' ? 1 : -1\n\t\t}\n\t\t// equal items sort equally\n\t\tif (a === b) {\n\t\t\treturn 0\n\t\t}\n\t\t// nulls sort after anything else\n\t\tif (a === null) {\n\t\t\treturn 1\n\t\t}\n\t\tif (b === null) {\n\t\t\treturn -1\n\t\t}\n\t\t// otherwise, if we're ascending, lowest sorts first\n\t\tif (ascending) {\n\t\t\treturn a < b ? -1 : 1\n\t\t}\n\t\t// if descending, highest sorts first\n\t\treturn a < b ? 1 : -1\n\t}\n\n/**\n * @name applyWidthAsPadding\n * @summary Applies width of subject to paddingRight of container.\n */\nexport const applyWidthAsPadding = (\n\tsubjectRef: RefObject<HTMLDivElement | null>,\n\tcontainerRef: RefObject<HTMLDivElement | null>,\n) => {\n\tif (containerRef.current && subjectRef.current) {\n\t\tcontainerRef.current.style.paddingRight = `${\n\t\t\tsubjectRef.current.offsetWidth + remToUnit('1rem')\n\t\t}px`\n\t}\n}\n\n/**\n * @name unescape\n * @summary Replaces \\” with “\n */\nexport const unescape = (val: string) => val.replace(/\\\\\"/g, '\"')\n\n/**\n * @name inChrome\n * @summary Whether the application is rendering in Chrome.\n */\nexport const inChrome = () => {\n\tconst isChromium = (window as Window & { chrome?: boolean })?.chrome || null\n\tconst winNav = (window as Window)?.navigator || null\n\tconst isOpera =\n\t\ttypeof (window as Window & { opr?: boolean })?.opr !== 'undefined'\n\tconst isIEedge = winNav?.userAgent.indexOf('Edg') > -1 || false\n\tconst isIOSChrome = winNav?.userAgent.match('CriOS') || false\n\n\tif (isIOSChrome) {\n\t\treturn true\n\t}\n\tif (\n\t\tisChromium !== null &&\n\t\ttypeof isChromium !== 'undefined' &&\n\t\tisOpera === false &&\n\t\tisIEedge === false\n\t) {\n\t\treturn true\n\t}\n\treturn false\n}\n\n/**\n * @name addedTo\n * @summary Given 2 objects and some keys, return items in the fresh object that do not exist in the\n * stale object by matching the given common key values of both objects.\n */\nexport const addedTo = (\n\tfresh: AnyObject[],\n\tstale: AnyObject[],\n\tkeys: string[],\n): AnyObject[] =>\n\ttypeof fresh !== 'object' || typeof stale !== 'object' || !keys.length\n\t\t? []\n\t\t: fresh.filter(\n\t\t\t\t(freshItem) =>\n\t\t\t\t\t!stale.find((staleItem) =>\n\t\t\t\t\t\tkeys.every((key) =>\n\t\t\t\t\t\t\t!(key in staleItem) || !(key in freshItem)\n\t\t\t\t\t\t\t\t? false\n\t\t\t\t\t\t\t\t: staleItem[key] === freshItem[key],\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t)\n\n/**\n * @name removedFrom\n * @summary Given 2 objects and some keys, return items in the stale object that do not exist in the\n * fresh object by matching the given common key values of both objects.\n */\nexport const removedFrom = (\n\tfresh: AnyObject[],\n\tstale: AnyObject[],\n\tkeys: string[],\n): AnyObject[] =>\n\ttypeof fresh !== 'object' || typeof stale !== 'object' || !keys.length\n\t\t? []\n\t\t: stale.filter(\n\t\t\t\t(staleItem) =>\n\t\t\t\t\t!fresh.find((freshItem) =>\n\t\t\t\t\t\tkeys.every((key) =>\n\t\t\t\t\t\t\t!(key in staleItem) || !(key in freshItem)\n\t\t\t\t\t\t\t\t? false\n\t\t\t\t\t\t\t\t: freshItem[key] === staleItem[key],\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t)\n\n/**\n * @name matchedProperties\n * @summary Given 2 objects and some keys, return items in object 1 that also exist in object 2 by\n * matching the given common key values of both objects.\n */\nexport const matchedProperties = (\n\tobjX: AnyObject[],\n\tobjY: AnyObject[],\n\tkeys: string[],\n): AnyObject[] =>\n\ttypeof objX !== 'object' || typeof objY !== 'object' || !keys.length\n\t\t? []\n\t\t: objY.filter((x) =>\n\t\t\t\tobjX.find((y) =>\n\t\t\t\t\tkeys.every((key) =>\n\t\t\t\t\t\t!(key in x) || !(key in y) ? false : y[key] === x[key],\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t)\n\n/**\n * @name isValidHttpUrl\n * @summary Give a string, return whether it is a valid http URL.\n * @param string - The string to check.\n */\nexport const isValidHttpUrl = (string: string) => {\n\tlet url: URL\n\ttry {\n\t\turl = new URL(string)\n\t} catch (_) {\n\t\treturn false\n\t}\n\treturn url.protocol === 'http:' || url.protocol === 'https:'\n}\n\n/**\n * @name makeCancelable\n * @summary Makes a promise cancellable.\n * @param promise - The promise to make cancellable.\n */\nexport const makeCancelable = (promise: Promise<AnyObject>) => {\n\tlet hasCanceled = false\n\n\tconst wrappedPromise = new Promise((resolve, reject) => {\n\t\tpromise.then((val) =>\n\t\t\thasCanceled ? reject(Error('Cancelled')) : resolve(val),\n\t\t)\n\t\tpromise.catch((error) =>\n\t\t\thasCanceled ? reject(Error('Cancelled')) : reject(error),\n\t\t)\n\t})\n\n\treturn {\n\t\tpromise: wrappedPromise,\n\t\tcancel: () => {\n\t\t\thasCanceled = true\n\t\t},\n\t}\n}\n\n/**\n * @name unimplemented\n * @summary A placeholder function to signal a deliberate unimplementation.\n * Consumes an arbitrary number of props.\n */\nexport const unimplemented = (_props?: unknown) => {\n\t/* unimplemented */\n}\n\n/**\n * Deep merge two objects.\n * @param target\n * @param ...sources\n */\n\nexport const mergeDeep = (\n\ttarget: AnyObject,\n\t...sources: AnyObject[]\n): AnyObject => {\n\tif (!sources.length) {\n\t\treturn target\n\t}\n\n\tconst isObject = (item: AnyObject) =>\n\t\titem && typeof item === 'object' && !Array.isArray(item)\n\tconst source = sources.shift()\n\n\tif (isObject(target) && isObject(source)) {\n\t\tfor (const key in source) {\n\t\t\tif (isObject(source[key])) {\n\t\t\t\tif (!target[key]) {\n\t\t\t\t\tObject.assign(target, { [key]: {} })\n\t\t\t\t}\n\t\t\t\tmergeDeep(target[key], source[key])\n\t\t\t} else {\n\t\t\t\tObject.assign(target, { [key]: source[key] })\n\t\t\t}\n\t\t}\n\t}\n\treturn mergeDeep(target, ...sources)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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,IAAI,OAAO,KAAK;AAAA,IACxD;AAAA,EACD,CAAC;AAED,SAAO;AAAA,IACN,SAAS;AAAA,IACT,QAAQ,MAAM;AACb,oBAAc;AAAA,IACf;AAAA,EACD;AACD;AAOO,IAAM,gBAAgB,CAAC,WAAqB;AAEnD;AAQO,IAAM,YAAY,CACxB,WACG,YACY;AACf,MAAI,CAAC,QAAQ,QAAQ;AACpB,WAAO;AAAA,EACR;AAEA,QAAM,WAAW,CAAC,SACjB,QAAQ,OAAO,SAAS,YAAY,CAAC,MAAM,QAAQ,IAAI;AACxD,QAAM,SAAS,QAAQ,MAAM;AAE7B,MAAI,SAAS,MAAM,KAAK,SAAS,MAAM,GAAG;AACzC,eAAW,OAAO,QAAQ;AACzB,UAAI,SAAS,OAAO,GAAG,CAAC,GAAG;AAC1B,YAAI,CAAC,OAAO,GAAG,GAAG;AACjB,iBAAO,OAAO,QAAQ,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC;AAAA,QACpC;AACA,kBAAU,OAAO,GAAG,GAAG,OAAO,GAAG,CAAC;AAAA,MACnC,OAAO;AACN,eAAO,OAAO,QAAQ,EAAE,CAAC,GAAG,GAAG,OAAO,GAAG,EAAE,CAAC;AAAA,MAC7C;AAAA,IACD;AAAA,EACD;AACA,SAAO,UAAU,QAAQ,GAAG,OAAO;AACpC;","names":["import_utils"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/base.ts","../src/convert.ts","../src/unit.ts"],"sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nexport * from './base'\nexport * from './convert'\nexport * from './unit'\n","/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\n/**\n * Ensures a number has at least the specified number of decimal places, retaining commas in the output if they are present in the input.\n *\n * @function minDecimalPlaces\n * @param {string | number | BigInt} val - The input number, which can be a `string` with or without commas, a `number`, or a `BigInt`.\n * @param {number} minDecimals - The minimum number of decimal places to enforce.\n * @returns {string} The formatted number as a string, padded with zeros if needed to meet `minDecimals`, retaining commas if originally provided.\n * If `val` is invalid, returns \"0\".\n * @example\n * // Pads \"1,234.5\" to have at least 3 decimal places, with commas\n * minDecimalPlaces(\"1,234.5\", 3); // returns \"1,234.500\"\n *\n * // Returns \"1234.56\" unchanged\n * minDecimalPlaces(1234.56, 2); // returns \"1234.56\"\n *\n * // Pads BigInt 1234 with 2 decimals\n * minDecimalPlaces(BigInt(1234), 2); // returns \"1234.00\"\n */\nexport const minDecimalPlaces = (\n\tval: string | number | bigint,\n\tminDecimals: number,\n): string => {\n\ttry {\n\t\t// Determine if we should retain commas based on original input type\n\t\tconst retainCommas = typeof val === 'string' && val.includes(',')\n\n\t\t// Convert `val` to a plain string for processing\n\t\tconst strVal =\n\t\t\ttypeof val === 'string' ? val.replace(/,/g, '') : val.toString()\n\n\t\t// Separate integer and decimal parts\n\t\tconst [integerPart, fractionalPart = ''] = strVal.split('.')\n\n\t\t// Parse the integer part as a BigInt\n\t\tconst whole = BigInt(integerPart || '0')\n\n\t\t// Calculate missing decimal places\n\t\tconst missingDecimals = minDecimals - fractionalPart.length\n\n\t\t// Format the integer part back with commas only if the input had commas\n\t\tconst formattedWhole = retainCommas\n\t\t\t? Intl.NumberFormat('en-US').format(whole)\n\t\t\t: whole.toString()\n\n\t\t// If missing decimals are needed, pad with zeros; otherwise, return the original value\n\t\treturn missingDecimals > 0\n\t\t\t? `${formattedWhole}.${fractionalPart}${'0'.repeat(missingDecimals)}`\n\t\t\t: `${formattedWhole}.${fractionalPart}`\n\t} catch {\n\t\t// The provided value is not a valid number, return \"0\".\n\t\treturn '0'\n\t}\n}\n\n/**\n * @name camelize\n * @summary Converts a string of text to camelCase.\n */\nexport const camelize = (str: string) => {\n\tconst convertToString = (string: string) => {\n\t\tif (string) {\n\t\t\tif (typeof string === 'string') {\n\t\t\t\treturn string\n\t\t\t}\n\t\t\treturn String(string)\n\t\t}\n\t\treturn ''\n\t}\n\n\tconst toWords = (inp: string) =>\n\t\tconvertToString(inp).match(\n\t\t\t/[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,\n\t\t)\n\n\tconst simpleCamelCase = (inp: string[]) => {\n\t\tlet result = ''\n\t\tfor (let i = 0; i < inp?.length; i++) {\n\t\t\tconst currString = inp[i]\n\t\t\tlet tmpStr = currString.toLowerCase()\n\t\t\tif (i !== 0) {\n\t\t\t\ttmpStr =\n\t\t\t\t\ttmpStr.slice(0, 1).toUpperCase() + tmpStr.slice(1, tmpStr.length)\n\t\t\t}\n\t\t\tresult += tmpStr\n\t\t}\n\t\treturn result\n\t}\n\n\tconst w = toWords(str)?.map((a) => a.toLowerCase())\n\treturn simpleCamelCase(w || [])\n}\n\n/**\n * @name ellipsisFn\n * @summary Receives an address and creates ellipsis on the given string, based on parameters.\n * @param str - The string to apply the ellipsis on\n * @param amount - The amount of characters that the ellipsis will be\n * @param position - where the ellipsis will apply; if center the amount of character is the\n * same for beginning and end; if \"start\" or \"end\" then its only once the amount; defaults to \"start\"\n */\nexport const ellipsisFn = (\n\tstr: string,\n\tamount = 6,\n\tposition: 'start' | 'end' | 'center' = 'center',\n) => {\n\tconst half = str.length / 2\n\n\t// having an amount less than 4 is a bit extreme so we default there\n\tif (amount <= 4) {\n\t\tif (position === 'center') {\n\t\t\treturn str.slice(0, 4) + '...' + str.slice(-4)\n\t\t}\n\t\tif (position === 'end') {\n\t\t\treturn str.slice(0, 4) + '...'\n\t\t}\n\t\treturn '...' + str.slice(-4)\n\t}\n\t// if the amount requested is in a \"logical\" amount - meaning that it can display the address\n\t// without repeating the same information twice - then go for it;\n\tif (position === 'center') {\n\t\treturn amount >= (str.length - 2) / 2\n\t\t\t? str.slice(0, half - 3) + '...' + str.slice(-(half - 3))\n\t\t\t: str.slice(0, amount) + '...' + str.slice(-amount)\n\t}\n\t// else, the user has been mistaskenly extreme, so just show the maximum possible amount\n\tif (amount >= str.length) {\n\t\tif (position === 'end') {\n\t\t\treturn str.slice(0, str.length - 3) + '...'\n\t\t}\n\t\treturn '...' + str.slice(-(str.length - 3))\n\t} else {\n\t\tif (position === 'end') {\n\t\t\treturn str.slice(0, amount) + '...'\n\t\t}\n\t\treturn '...' + str.slice(amount)\n\t}\n}\n\n/**\n * @name pageFromUri\n * @summary Use url variables to load the default components upon the first page visit.\n */\nexport const pageFromUri = (pathname: string, fallback: string) => {\n\tconst lastUriItem = pathname.substring(pathname.lastIndexOf('/') + 1)\n\tconst page = lastUriItem.trim() === '' ? fallback : lastUriItem\n\treturn page.trim()\n}\n\n/**\n * @name rmCommas\n * @summary Removes the commas from a string.\n */\nexport const rmCommas = (val: string): string => val.replace(/,/g, '')\n\n/**\n * @name rmDecimals\n * @summary Removes the decimal point and decimals from a string.\n */\nexport const rmDecimals = (str: string) => str.split('.')[0]\n\n/**\n * @name shuffle\n * @summary Shuffle a set of objects.\n */\nexport const shuffle = <T>(array: T[]) => {\n\tlet currentIndex = array.length\n\tlet randomIndex\n\twhile (currentIndex !== 0) {\n\t\trandomIndex = Math.floor(Math.random() * currentIndex)\n\t\tcurrentIndex--\n\t\t;[array[currentIndex], array[randomIndex]] = [\n\t\t\tarray[randomIndex],\n\t\t\tarray[currentIndex],\n\t\t]\n\t}\n\treturn array\n}\n\n/**\n * @name withTimeout\n * @summary Timeout a promise after a specified number of milliseconds.\n */\nexport const withTimeout = (\n\tms: number,\n\tpromise: Promise<unknown>,\n\toptions?: {\n\t\tonTimeout?: () => void\n\t},\n) => {\n\tconst timeout = new Promise((resolve) =>\n\t\tsetTimeout(async () => {\n\t\t\tif (typeof options?.onTimeout === 'function') {\n\t\t\t\toptions.onTimeout()\n\t\t\t}\n\t\t\tresolve(undefined)\n\t\t}, ms),\n\t)\n\treturn Promise.race([promise, timeout])\n}\n\n/**\n * @name withTimeoutThrow\n * @summary Timeout a promise after a specified number of milliseconds by throwing an error\n */\nexport const withTimeoutThrow = <T>(\n\tms: number,\n\tpromise: Promise<T>,\n\toptions?: {\n\t\tonTimeout?: () => void\n\t},\n) => {\n\tconst timeout = new Promise((reject) =>\n\t\tsetTimeout(async () => {\n\t\t\tif (typeof options?.onTimeout === 'function') {\n\t\t\t\toptions.onTimeout()\n\t\t\t}\n\t\t\treject('Function timeout')\n\t\t}, ms),\n\t)\n\treturn Promise.race([promise, timeout])\n}\n\n/**\n * @name appendOrEmpty\n * @summary Returns ` value` if a condition is truthy, or an empty string otherwise.\n */\nexport const appendOrEmpty = (\n\tcondition: boolean | string | undefined,\n\tvalue: string,\n) => (condition ? ` ${value}` : '')\n\n/**\n * @name appendOr\n * @summary Returns ` value` if condition is truthy, or ` fallback` otherwise.\n */\nexport const appendOr = (\n\tcondition: boolean | string | undefined,\n\tvalue: string,\n\tfallback: string,\n) => (condition ? ` ${value}` : ` ${fallback}`)\n\n/**\n * @name removeHexPrefix\n * @summary Takes a string str as input and returns a new string with the \"0x\" prefix removed if it\n * exists at the beginning of the input string.\n */\nexport const removeHexPrefix = (str: string): string => str.replace(/^0x/, '')\n\n// Check if 2 sets contain the same elements.\n// biome-ignore lint/suspicious/noExplicitAny: <>\nexport const eqSet = (xs: Set<any>, ys: Set<any>) =>\n\txs.size === ys.size && [...xs].every((x) => ys.has(x))\n\n// Check if one set contains all the elements of another set.\n// biome-ignore lint/suspicious/noExplicitAny: <>\nexport const isSuperset = (set: Set<any>, subset: Set<any>) => {\n\tfor (const elem of subset) {\n\t\tif (!set.has(elem)) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\n/**\n * Finds the maximum value among a list of BigInt values.\n *\n * @function maxBigInt\n * @param {...bigint} values - A list of BigInt values to compare.\n * @returns {bigint} The largest BigInt value in the provided list.\n * @example\n * // Returns the maximum BigInt value\n * maxBigInt(10n, 50n, 30n, 100n, 20n); // 100n\n */\nexport const maxBigInt = (...values: bigint[]): bigint =>\n\tvalues.reduce((max, current) => (current > max ? current : max))\n\n/**\n * Finds the minimum value among a list of BigInt values.\n *\n * @function minBigInt\n * @param {...bigint} values - A list of BigInt values to compare.\n * @returns {bigint} The smallest BigInt value in the provided list.\n * @example\n * // Returns the minimum BigInt value\n * minBigInt(10n, 50n, 30n, 100n, 20n); // 10n\n */\nexport const minBigInt = (...values: bigint[]): bigint =>\n\tvalues.reduce((min, current) => (current < min ? current : min))\n","// /* @license Copyright 2024 w3ux authors & contributors\n// SPDX-License-Identifier: GPL-3.0-only */\n\n/**\n * Concatenates multiple Uint8Array instances into a single Uint8Array.\n *\n * @param {Uint8Array[]} u8as - An array of Uint8Array instances to concatenate.\n * @returns {Uint8Array} A new Uint8Array containing all the input arrays concatenated.\n */\nexport const u8aConcat = (...u8as: Uint8Array[]): Uint8Array => {\n\t// Calculate the total length of the resulting Uint8Array\n\tconst totalLength = u8as.reduce((sum, u8a) => sum + u8a.length, 0)\n\n\t// Create a new Uint8Array with the total length\n\tconst result = new Uint8Array(totalLength)\n\n\tlet offset = 0 // Initialize the offset for placing elements\n\tfor (const u8a of u8as) {\n\t\tresult.set(u8a, offset) // Set the current Uint8Array at the current offset\n\t\toffset += u8a.length // Update the offset for the next Uint8Array\n\t}\n\n\treturn result\n}\n","/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { RefObject } from 'react'\nimport { rmCommas, rmDecimals } from './base'\nimport type { AnyObject } from './types'\n\n/**\n * Converts an on-chain balance value from planck to a decimal value in token units.\n *\n * @function planckToUnit\n * @param {number | BigInt | string} val - The balance value in planck. Accepts a `number`, `BigInt`, or `string`.\n * @param {number} units - The number of decimal places in the token unit (10^units planck per 1 token).\n * @returns {string} The equivalent token unit value as a decimal string.\n * @example\n * // Convert 1500000000000 planck to tokens with 12 decimal places\n * planckToUnit(\"1500000000000\", 12); // returns \"1.5\"\n */\nexport const planckToUnit = (\n\tval: number | bigint | string,\n\tunits: number,\n): string => {\n\ttry {\n\t\t// Ensure `units` is a positive integer.\n\t\tunits = Math.max(Math.round(units), 0)\n\n\t\t// Convert `val` to BigInt based on its type\n\t\tconst bigIntVal =\n\t\t\ttypeof val === 'bigint'\n\t\t\t\t? val\n\t\t\t\t: BigInt(\n\t\t\t\t\t\ttypeof val === 'number'\n\t\t\t\t\t\t\t? Math.floor(val).toString()\n\t\t\t\t\t\t\t: rmDecimals(rmCommas(val)),\n\t\t\t\t\t)\n\n\t\tconst divisor = units === 0 ? 1n : BigInt(10) ** BigInt(units)\n\n\t\t// Integer division and remainder for the fractional part\n\t\tconst integerPart = bigIntVal / divisor\n\t\tconst fractionalPart = bigIntVal % divisor\n\n\t\t// Format fractional part with leading zeros to maintain `units` decimal places\n\t\tconst fractionalStr =\n\t\t\tunits > 0 ? `.${fractionalPart.toString().padStart(units, '0')}` : ``\n\n\t\t// Combine integer and fractional parts as a decimal string\n\t\treturn `${integerPart}${fractionalStr}`\n\t} catch {\n\t\treturn '0'\n\t}\n}\n\n/**\n * Converts a token unit value to an integer value in planck.\n *\n * @function unitToPlanck\n * @param {string | number | BigInt} val - The token unit value to convert. Accepts a string, number, or BigInt.\n * @param {number} units - The number of decimal places for conversion (10^units planck per 1 token).\n * @returns {BigInt} The equivalent value in planck as a BigInt.\n * @example\n * // Convert \"1.5\" tokens to planck with 12 decimal places\n * unitToPlanck(\"1.5\", 12); // returns BigInt(\"1500000000000\")\n */\nexport const unitToPlanck = (\n\tval: string | number | bigint,\n\tunits: number,\n): bigint => {\n\ttry {\n\t\t// Ensure `units` is a positive integer.\n\t\tunits = Math.max(Math.round(units), 0)\n\n\t\t// Convert `val` to a string; if empty or invalid, default to \"0\"\n\t\tconst strVal =\n\t\t\t(typeof val === 'string' ? rmCommas(val) : val.toString()) || '0'\n\n\t\t// Split into integer and fractional parts\n\t\tconst [integerPart, fractionalPart = ''] = strVal.split('.')\n\n\t\t// Process the integer part by converting to BigInt and scaling it to the given units\n\t\tlet bigIntValue = BigInt(integerPart) * BigInt(10) ** BigInt(units)\n\n\t\t// Process the fractional part if it exists\n\t\tif (fractionalPart) {\n\t\t\tlet fractionalValue: bigint\n\n\t\t\tif (fractionalPart.length > units) {\n\t\t\t\t// If fractional part exceeds units, truncate it\n\t\t\t\tfractionalValue = BigInt(fractionalPart.slice(0, units))\n\t\t\t} else {\n\t\t\t\t// Otherwise, pad the fractional part to match units\n\t\t\t\tfractionalValue = BigInt(fractionalPart.padEnd(units, '0'))\n\t\t\t}\n\n\t\t\tbigIntValue += fractionalValue\n\t\t}\n\n\t\treturn bigIntValue\n\t} catch {\n\t\treturn BigInt(0)\n\t}\n}\n\n/**\n * @name remToUnit\n * @summary Converts a rem string to a number.\n */\nexport const remToUnit = (rem: string) =>\n\tNumber(rem.slice(0, rem.length - 3)) *\n\tparseFloat(getComputedStyle(document.documentElement).fontSize)\n\n/**\n * @name capitalizeFirstLetter\n * @summary Capitalize the first letter of a string.\n */\nexport const capitalizeFirstLetter = (string: string) =>\n\tstring.charAt(0).toUpperCase() + string.slice(1)\n\n/**\n * @name snakeToCamel\n * @summary converts a string from snake / kebab-case to camel-case.\n */\nexport const snakeToCamel = (str: string) =>\n\tstr\n\t\t.toLowerCase()\n\t\t.replace(/([-_][a-z])/g, (group) =>\n\t\t\tgroup.toUpperCase().replace('-', '').replace('_', ''),\n\t\t)\n\n/**\n * @name setStateWithRef\n * @summary Synchronize React state and its reference with the provided value.\n */\nexport const setStateWithRef = <T>(\n\tvalue: T,\n\tsetState: (_state: T) => void,\n\tref: RefObject<T>,\n): void => {\n\tsetState(value)\n\tref.current = value\n}\n\n/**\n * @name localStorageOrDefault\n * @summary Retrieve the local stroage value with the key, return defult value if it is not\n * found.\n */\nexport const localStorageOrDefault = <T>(\n\tkey: string,\n\t_default: T,\n\tparse = false,\n): T | string => {\n\tconst val: string | null = localStorage.getItem(key)\n\n\tif (val === null) {\n\t\treturn _default\n\t}\n\n\tif (parse) {\n\t\treturn JSON.parse(val) as T\n\t}\n\treturn val\n}\n\n/**\n * @name extractUrlValue\n * @summary Extracts a URL value from a URL string.\n */\nexport const extractUrlValue = (key: string, url?: string) => {\n\tif (typeof url === 'undefined') {\n\t\turl = window.location.href\n\t}\n\tconst match = url.match(`[?&]${key}=([^&]+)`)\n\treturn match ? match[1] : null\n}\n\n/**\n * @name varToUrlHash\n * @summary Puts a variable into the URL hash as a param.\n * @description\n * Since url variables are added to the hash and are not treated as URL params, the params are split\n * and parsed into a `URLSearchParams`.\n */\nexport const varToUrlHash = (\n\tkey: string,\n\tval: string,\n\taddIfMissing: boolean,\n) => {\n\tconst hash = window.location.hash\n\tconst [page, params] = hash.split('?')\n\tconst searchParams = new URLSearchParams(params)\n\n\tif (searchParams.get(key) === null && !addIfMissing) {\n\t\treturn\n\t}\n\tsearchParams.set(key, val)\n\twindow.location.hash = `${page}?${searchParams.toString()}`\n}\n\n/**\n * @name removeVarFromUrlHash\n * @summary\n * Removes a variable `key` from the URL hash if it exists. Removes dangling `?` if no URL variables\n * exist.\n */\nexport const removeVarFromUrlHash = (key: string) => {\n\tconst hash = window.location.hash\n\tconst [page, params] = hash.split('?')\n\tconst searchParams = new URLSearchParams(params)\n\tif (searchParams.get(key) === null) {\n\t\treturn\n\t}\n\tsearchParams.delete(key)\n\tconst paramsAsStr = searchParams.toString()\n\twindow.location.hash = `${page}${paramsAsStr ? `?${paramsAsStr}` : ``}`\n}\n\n/**\n * @name sortWithNull\n * @summary Sorts an array with nulls last.\n */\nexport const sortWithNull =\n\t(ascending: boolean) => (a: unknown, b: unknown) => {\n\t\t// if both items are undefined, treat them as equal\n\t\tif (typeof a === 'undefined' && typeof b === 'undefined') {\n\t\t\treturn 0\n\t\t}\n\t\t// if either item is undefined, sort it last\n\t\tif (typeof a === 'undefined' || typeof b === 'undefined') {\n\t\t\treturn typeof a === 'undefined' ? 1 : -1\n\t\t}\n\t\t// equal items sort equally\n\t\tif (a === b) {\n\t\t\treturn 0\n\t\t}\n\t\t// nulls sort after anything else\n\t\tif (a === null) {\n\t\t\treturn 1\n\t\t}\n\t\tif (b === null) {\n\t\t\treturn -1\n\t\t}\n\t\t// otherwise, if we're ascending, lowest sorts first\n\t\tif (ascending) {\n\t\t\treturn a < b ? -1 : 1\n\t\t}\n\t\t// if descending, highest sorts first\n\t\treturn a < b ? 1 : -1\n\t}\n\n/**\n * @name applyWidthAsPadding\n * @summary Applies width of subject to paddingRight of container.\n */\nexport const applyWidthAsPadding = (\n\tsubjectRef: RefObject<HTMLDivElement | null>,\n\tcontainerRef: RefObject<HTMLDivElement | null>,\n) => {\n\tif (containerRef.current && subjectRef.current) {\n\t\tcontainerRef.current.style.paddingRight = `${\n\t\t\tsubjectRef.current.offsetWidth + remToUnit('1rem')\n\t\t}px`\n\t}\n}\n\n/**\n * @name unescape\n * @summary Replaces \\” with “\n */\nexport const unescape = (val: string) => val.replace(/\\\\\"/g, '\"')\n\n/**\n * @name inChrome\n * @summary Whether the application is rendering in Chrome.\n */\nexport const inChrome = () => {\n\tconst isChromium = (window as Window & { chrome?: boolean })?.chrome || null\n\tconst winNav = (window as Window)?.navigator || null\n\tconst isOpera =\n\t\ttypeof (window as Window & { opr?: boolean })?.opr !== 'undefined'\n\tconst isIEedge = winNav?.userAgent.indexOf('Edg') > -1 || false\n\tconst isIOSChrome = winNav?.userAgent.match('CriOS') || false\n\n\tif (isIOSChrome) {\n\t\treturn true\n\t}\n\tif (\n\t\tisChromium !== null &&\n\t\ttypeof isChromium !== 'undefined' &&\n\t\tisOpera === false &&\n\t\tisIEedge === false\n\t) {\n\t\treturn true\n\t}\n\treturn false\n}\n\n/**\n * @name addedTo\n * @summary Given 2 objects and some keys, return items in the fresh object that do not exist in the\n * stale object by matching the given common key values of both objects.\n */\nexport const addedTo = (\n\tfresh: AnyObject[],\n\tstale: AnyObject[],\n\tkeys: string[],\n): AnyObject[] =>\n\ttypeof fresh !== 'object' || typeof stale !== 'object' || !keys.length\n\t\t? []\n\t\t: fresh.filter(\n\t\t\t\t(freshItem) =>\n\t\t\t\t\t!stale.find((staleItem) =>\n\t\t\t\t\t\tkeys.every((key) =>\n\t\t\t\t\t\t\t!(key in staleItem) || !(key in freshItem)\n\t\t\t\t\t\t\t\t? false\n\t\t\t\t\t\t\t\t: staleItem[key] === freshItem[key],\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t)\n\n/**\n * @name removedFrom\n * @summary Given 2 objects and some keys, return items in the stale object that do not exist in the\n * fresh object by matching the given common key values of both objects.\n */\nexport const removedFrom = (\n\tfresh: AnyObject[],\n\tstale: AnyObject[],\n\tkeys: string[],\n): AnyObject[] =>\n\ttypeof fresh !== 'object' || typeof stale !== 'object' || !keys.length\n\t\t? []\n\t\t: stale.filter(\n\t\t\t\t(staleItem) =>\n\t\t\t\t\t!fresh.find((freshItem) =>\n\t\t\t\t\t\tkeys.every((key) =>\n\t\t\t\t\t\t\t!(key in staleItem) || !(key in freshItem)\n\t\t\t\t\t\t\t\t? false\n\t\t\t\t\t\t\t\t: freshItem[key] === staleItem[key],\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t)\n\n/**\n * @name matchedProperties\n * @summary Given 2 objects and some keys, return items in object 1 that also exist in object 2 by\n * matching the given common key values of both objects.\n */\nexport const matchedProperties = (\n\tobjX: AnyObject[],\n\tobjY: AnyObject[],\n\tkeys: string[],\n): AnyObject[] =>\n\ttypeof objX !== 'object' || typeof objY !== 'object' || !keys.length\n\t\t? []\n\t\t: objY.filter((x) =>\n\t\t\t\tobjX.find((y) =>\n\t\t\t\t\tkeys.every((key) =>\n\t\t\t\t\t\t!(key in x) || !(key in y) ? false : y[key] === x[key],\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t)\n\n/**\n * @name isValidHttpUrl\n * @summary Give a string, return whether it is a valid http URL.\n * @param string - The string to check.\n */\nexport const isValidHttpUrl = (string: string) => {\n\tlet url: URL\n\ttry {\n\t\turl = new URL(string)\n\t} catch (_) {\n\t\treturn false\n\t}\n\treturn url.protocol === 'http:' || url.protocol === 'https:'\n}\n\n/**\n * @name makeCancelable\n * @summary Makes a promise cancellable.\n * @param promise - The promise to make cancellable.\n */\nexport const makeCancelable = (promise: Promise<AnyObject>) => {\n\tlet hasCanceled = false\n\n\tconst wrappedPromise = new Promise((resolve, reject) => {\n\t\tpromise.then((val) =>\n\t\t\thasCanceled ? reject(Error('Cancelled')) : resolve(val),\n\t\t)\n\t\tpromise.catch((error) =>\n\t\t\thasCanceled ? reject(Error('Cancelled')) : reject(error),\n\t\t)\n\t})\n\n\treturn {\n\t\tpromise: wrappedPromise,\n\t\tcancel: () => {\n\t\t\thasCanceled = true\n\t\t},\n\t}\n}\n\n/**\n * @name unimplemented\n * @summary A placeholder function to signal a deliberate unimplementation.\n * Consumes an arbitrary number of props.\n */\nexport const unimplemented = (_props?: unknown) => {\n\t/* unimplemented */\n}\n\n/**\n * Deep merge two objects.\n * @param target\n * @param ...sources\n */\n\nexport const mergeDeep = (\n\ttarget: AnyObject,\n\t...sources: AnyObject[]\n): AnyObject => {\n\tif (!sources.length) {\n\t\treturn target\n\t}\n\n\tconst isObject = (item: AnyObject) =>\n\t\titem && typeof item === 'object' && !Array.isArray(item)\n\tconst source = sources.shift()\n\n\tif (isObject(target) && isObject(source)) {\n\t\tfor (const key in source) {\n\t\t\tif (isObject(source[key])) {\n\t\t\t\tif (!target[key]) {\n\t\t\t\t\tObject.assign(target, { [key]: {} })\n\t\t\t\t}\n\t\t\t\tmergeDeep(target[key], source[key])\n\t\t\t} else {\n\t\t\t\tObject.assign(target, { [key]: source[key] })\n\t\t\t}\n\t\t}\n\t}\n\treturn mergeDeep(target, ...sources)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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AG;AAC1B,YAAI,CAAC,OAAO,GAAG,GAAG;AACjB,iBAAO,OAAO,QAAQ,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC;AAAA,QACpC;AACA,kBAAU,OAAO,GAAG,GAAG,OAAO,GAAG,CAAC;AAAA,MACnC,OAAO;AACN,eAAO,OAAO,QAAQ,EAAE,CAAC,GAAG,GAAG,OAAO,GAAG,EAAE,CAAC;AAAA,MAC7C;AAAA,IACD;AAAA,EACD;AACA,SAAO,UAAU,QAAQ,GAAG,OAAO;AACpC;","names":[]}
|
package/index.d.cts
CHANGED
|
@@ -77,17 +77,6 @@ declare const appendOrEmpty: (condition: boolean | string | undefined, value: st
|
|
|
77
77
|
* @summary Returns ` value` if condition is truthy, or ` fallback` otherwise.
|
|
78
78
|
*/
|
|
79
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, ss58: number) => string | null;
|
|
85
|
-
/**
|
|
86
|
-
* @name tryFormatSs58
|
|
87
|
-
* @summary Formats an address with the supplied ss58 prefix, or returns the original address if
|
|
88
|
-
* invalid.
|
|
89
|
-
*/
|
|
90
|
-
declare const tryFormatSs58: (address: string, ss58: number) => string;
|
|
91
80
|
/**
|
|
92
81
|
* @name removeHexPrefix
|
|
93
82
|
* @summary Takes a string str as input and returns a new string with the "0x" prefix removed if it
|
|
@@ -179,11 +168,6 @@ declare const setStateWithRef: <T>(value: T, setState: (_state: T) => void, ref:
|
|
|
179
168
|
* found.
|
|
180
169
|
*/
|
|
181
170
|
declare const localStorageOrDefault: <T>(key: string, _default: T, parse?: boolean) => T | string;
|
|
182
|
-
/**
|
|
183
|
-
* @name isValidAddress
|
|
184
|
-
* @summary Return whether an address is valid Substrate address.
|
|
185
|
-
*/
|
|
186
|
-
declare const isValidAddress: (address: string) => boolean;
|
|
187
171
|
/**
|
|
188
172
|
* @name extractUrlValue
|
|
189
173
|
* @summary Extracts a URL value from a URL string.
|
|
@@ -270,4 +254,4 @@ declare const unimplemented: (_props?: unknown) => void;
|
|
|
270
254
|
*/
|
|
271
255
|
declare const mergeDeep: (target: AnyObject, ...sources: AnyObject[]) => AnyObject;
|
|
272
256
|
|
|
273
|
-
export { addedTo, appendOr, appendOrEmpty, applyWidthAsPadding, camelize, capitalizeFirstLetter, ellipsisFn, eqSet, extractUrlValue,
|
|
257
|
+
export { addedTo, appendOr, appendOrEmpty, applyWidthAsPadding, camelize, capitalizeFirstLetter, ellipsisFn, eqSet, extractUrlValue, inChrome, isSuperset, 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
|
@@ -77,17 +77,6 @@ declare const appendOrEmpty: (condition: boolean | string | undefined, value: st
|
|
|
77
77
|
* @summary Returns ` value` if condition is truthy, or ` fallback` otherwise.
|
|
78
78
|
*/
|
|
79
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, ss58: number) => string | null;
|
|
85
|
-
/**
|
|
86
|
-
* @name tryFormatSs58
|
|
87
|
-
* @summary Formats an address with the supplied ss58 prefix, or returns the original address if
|
|
88
|
-
* invalid.
|
|
89
|
-
*/
|
|
90
|
-
declare const tryFormatSs58: (address: string, ss58: number) => string;
|
|
91
80
|
/**
|
|
92
81
|
* @name removeHexPrefix
|
|
93
82
|
* @summary Takes a string str as input and returns a new string with the "0x" prefix removed if it
|
|
@@ -179,11 +168,6 @@ declare const setStateWithRef: <T>(value: T, setState: (_state: T) => void, ref:
|
|
|
179
168
|
* found.
|
|
180
169
|
*/
|
|
181
170
|
declare const localStorageOrDefault: <T>(key: string, _default: T, parse?: boolean) => T | string;
|
|
182
|
-
/**
|
|
183
|
-
* @name isValidAddress
|
|
184
|
-
* @summary Return whether an address is valid Substrate address.
|
|
185
|
-
*/
|
|
186
|
-
declare const isValidAddress: (address: string) => boolean;
|
|
187
171
|
/**
|
|
188
172
|
* @name extractUrlValue
|
|
189
173
|
* @summary Extracts a URL value from a URL string.
|
|
@@ -270,4 +254,4 @@ declare const unimplemented: (_props?: unknown) => void;
|
|
|
270
254
|
*/
|
|
271
255
|
declare const mergeDeep: (target: AnyObject, ...sources: AnyObject[]) => AnyObject;
|
|
272
256
|
|
|
273
|
-
export { addedTo, appendOr, appendOrEmpty, applyWidthAsPadding, camelize, capitalizeFirstLetter, ellipsisFn, eqSet, extractUrlValue,
|
|
257
|
+
export { addedTo, appendOr, appendOrEmpty, applyWidthAsPadding, camelize, capitalizeFirstLetter, ellipsisFn, eqSet, extractUrlValue, inChrome, isSuperset, 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.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// src/base.ts
|
|
2
|
-
import { encodeAddress } from "dedot/utils";
|
|
3
2
|
var minDecimalPlaces = (val, minDecimals) => {
|
|
4
3
|
try {
|
|
5
4
|
const retainCommas = typeof val === "string" && val.includes(",");
|
|
@@ -111,20 +110,6 @@ var withTimeoutThrow = (ms, promise, options) => {
|
|
|
111
110
|
};
|
|
112
111
|
var appendOrEmpty = (condition, value) => condition ? ` ${value}` : "";
|
|
113
112
|
var appendOr = (condition, value, fallback) => condition ? ` ${value}` : ` ${fallback}`;
|
|
114
|
-
var formatAccountSs58 = (address, ss58) => {
|
|
115
|
-
try {
|
|
116
|
-
return encodeAddress(address, ss58);
|
|
117
|
-
} catch {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
var tryFormatSs58 = (address, ss58) => {
|
|
122
|
-
try {
|
|
123
|
-
return encodeAddress(address, ss58);
|
|
124
|
-
} catch {
|
|
125
|
-
return address;
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
113
|
var removeHexPrefix = (str) => str.replace(/^0x/, "");
|
|
129
114
|
var eqSet = (xs, ys) => xs.size === ys.size && [...xs].every((x) => ys.has(x));
|
|
130
115
|
var isSuperset = (set, subset) => {
|
|
@@ -151,7 +136,6 @@ var u8aConcat = (...u8as) => {
|
|
|
151
136
|
};
|
|
152
137
|
|
|
153
138
|
// src/unit.ts
|
|
154
|
-
import { decodeAddress } from "dedot/utils";
|
|
155
139
|
var planckToUnit = (val, units) => {
|
|
156
140
|
try {
|
|
157
141
|
units = Math.max(Math.round(units), 0);
|
|
@@ -207,14 +191,6 @@ var localStorageOrDefault = (key, _default, parse = false) => {
|
|
|
207
191
|
}
|
|
208
192
|
return val;
|
|
209
193
|
};
|
|
210
|
-
var isValidAddress = (address) => {
|
|
211
|
-
try {
|
|
212
|
-
decodeAddress(address);
|
|
213
|
-
return true;
|
|
214
|
-
} catch {
|
|
215
|
-
return false;
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
194
|
var extractUrlValue = (key, url) => {
|
|
219
195
|
if (typeof url === "undefined") {
|
|
220
196
|
url = window.location.href;
|
|
@@ -363,10 +339,8 @@ export {
|
|
|
363
339
|
ellipsisFn,
|
|
364
340
|
eqSet,
|
|
365
341
|
extractUrlValue,
|
|
366
|
-
formatAccountSs58,
|
|
367
342
|
inChrome,
|
|
368
343
|
isSuperset,
|
|
369
|
-
isValidAddress,
|
|
370
344
|
isValidHttpUrl,
|
|
371
345
|
localStorageOrDefault,
|
|
372
346
|
makeCancelable,
|
|
@@ -387,7 +361,6 @@ export {
|
|
|
387
361
|
shuffle,
|
|
388
362
|
snakeToCamel,
|
|
389
363
|
sortWithNull,
|
|
390
|
-
tryFormatSs58,
|
|
391
364
|
u8aConcat,
|
|
392
365
|
unescape,
|
|
393
366
|
unimplemented,
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/base.ts","../src/convert.ts","../src/unit.ts"],"sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { encodeAddress } from 'dedot/utils'\n\n/**\n * Ensures a number has at least the specified number of decimal places, retaining commas in the output if they are present in the input.\n *\n * @function minDecimalPlaces\n * @param {string | number | BigInt} val - The input number, which can be a `string` with or without commas, a `number`, or a `BigInt`.\n * @param {number} minDecimals - The minimum number of decimal places to enforce.\n * @returns {string} The formatted number as a string, padded with zeros if needed to meet `minDecimals`, retaining commas if originally provided.\n * If `val` is invalid, returns \"0\".\n * @example\n * // Pads \"1,234.5\" to have at least 3 decimal places, with commas\n * minDecimalPlaces(\"1,234.5\", 3); // returns \"1,234.500\"\n *\n * // Returns \"1234.56\" unchanged\n * minDecimalPlaces(1234.56, 2); // returns \"1234.56\"\n *\n * // Pads BigInt 1234 with 2 decimals\n * minDecimalPlaces(BigInt(1234), 2); // returns \"1234.00\"\n */\nexport const minDecimalPlaces = (\n\tval: string | number | bigint,\n\tminDecimals: number,\n): string => {\n\ttry {\n\t\t// Determine if we should retain commas based on original input type\n\t\tconst retainCommas = typeof val === 'string' && val.includes(',')\n\n\t\t// Convert `val` to a plain string for processing\n\t\tconst strVal =\n\t\t\ttypeof val === 'string' ? val.replace(/,/g, '') : val.toString()\n\n\t\t// Separate integer and decimal parts\n\t\tconst [integerPart, fractionalPart = ''] = strVal.split('.')\n\n\t\t// Parse the integer part as a BigInt\n\t\tconst whole = BigInt(integerPart || '0')\n\n\t\t// Calculate missing decimal places\n\t\tconst missingDecimals = minDecimals - fractionalPart.length\n\n\t\t// Format the integer part back with commas only if the input had commas\n\t\tconst formattedWhole = retainCommas\n\t\t\t? Intl.NumberFormat('en-US').format(whole)\n\t\t\t: whole.toString()\n\n\t\t// If missing decimals are needed, pad with zeros; otherwise, return the original value\n\t\treturn missingDecimals > 0\n\t\t\t? `${formattedWhole}.${fractionalPart}${'0'.repeat(missingDecimals)}`\n\t\t\t: `${formattedWhole}.${fractionalPart}`\n\t} catch {\n\t\t// The provided value is not a valid number, return \"0\".\n\t\treturn '0'\n\t}\n}\n\n/**\n * @name camelize\n * @summary Converts a string of text to camelCase.\n */\nexport const camelize = (str: string) => {\n\tconst convertToString = (string: string) => {\n\t\tif (string) {\n\t\t\tif (typeof string === 'string') {\n\t\t\t\treturn string\n\t\t\t}\n\t\t\treturn String(string)\n\t\t}\n\t\treturn ''\n\t}\n\n\tconst toWords = (inp: string) =>\n\t\tconvertToString(inp).match(\n\t\t\t/[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,\n\t\t)\n\n\tconst simpleCamelCase = (inp: string[]) => {\n\t\tlet result = ''\n\t\tfor (let i = 0; i < inp?.length; i++) {\n\t\t\tconst currString = inp[i]\n\t\t\tlet tmpStr = currString.toLowerCase()\n\t\t\tif (i !== 0) {\n\t\t\t\ttmpStr =\n\t\t\t\t\ttmpStr.slice(0, 1).toUpperCase() + tmpStr.slice(1, tmpStr.length)\n\t\t\t}\n\t\t\tresult += tmpStr\n\t\t}\n\t\treturn result\n\t}\n\n\tconst w = toWords(str)?.map((a) => a.toLowerCase())\n\treturn simpleCamelCase(w || [])\n}\n\n/**\n * @name ellipsisFn\n * @summary Receives an address and creates ellipsis on the given string, based on parameters.\n * @param str - The string to apply the ellipsis on\n * @param amount - The amount of characters that the ellipsis will be\n * @param position - where the ellipsis will apply; if center the amount of character is the\n * same for beginning and end; if \"start\" or \"end\" then its only once the amount; defaults to \"start\"\n */\nexport const ellipsisFn = (\n\tstr: string,\n\tamount = 6,\n\tposition: 'start' | 'end' | 'center' = 'center',\n) => {\n\tconst half = str.length / 2\n\n\t// having an amount less than 4 is a bit extreme so we default there\n\tif (amount <= 4) {\n\t\tif (position === 'center') {\n\t\t\treturn str.slice(0, 4) + '...' + str.slice(-4)\n\t\t}\n\t\tif (position === 'end') {\n\t\t\treturn str.slice(0, 4) + '...'\n\t\t}\n\t\treturn '...' + str.slice(-4)\n\t}\n\t// if the amount requested is in a \"logical\" amount - meaning that it can display the address\n\t// without repeating the same information twice - then go for it;\n\tif (position === 'center') {\n\t\treturn amount >= (str.length - 2) / 2\n\t\t\t? str.slice(0, half - 3) + '...' + str.slice(-(half - 3))\n\t\t\t: str.slice(0, amount) + '...' + str.slice(-amount)\n\t}\n\t// else, the user has been mistaskenly extreme, so just show the maximum possible amount\n\tif (amount >= str.length) {\n\t\tif (position === 'end') {\n\t\t\treturn str.slice(0, str.length - 3) + '...'\n\t\t}\n\t\treturn '...' + str.slice(-(str.length - 3))\n\t} else {\n\t\tif (position === 'end') {\n\t\t\treturn str.slice(0, amount) + '...'\n\t\t}\n\t\treturn '...' + str.slice(amount)\n\t}\n}\n\n/**\n * @name pageFromUri\n * @summary Use url variables to load the default components upon the first page visit.\n */\nexport const pageFromUri = (pathname: string, fallback: string) => {\n\tconst lastUriItem = pathname.substring(pathname.lastIndexOf('/') + 1)\n\tconst page = lastUriItem.trim() === '' ? fallback : lastUriItem\n\treturn page.trim()\n}\n\n/**\n * @name rmCommas\n * @summary Removes the commas from a string.\n */\nexport const rmCommas = (val: string): string => val.replace(/,/g, '')\n\n/**\n * @name rmDecimals\n * @summary Removes the decimal point and decimals from a string.\n */\nexport const rmDecimals = (str: string) => str.split('.')[0]\n\n/**\n * @name shuffle\n * @summary Shuffle a set of objects.\n */\nexport const shuffle = <T>(array: T[]) => {\n\tlet currentIndex = array.length\n\tlet randomIndex\n\twhile (currentIndex !== 0) {\n\t\trandomIndex = Math.floor(Math.random() * currentIndex)\n\t\tcurrentIndex--\n\t\t;[array[currentIndex], array[randomIndex]] = [\n\t\t\tarray[randomIndex],\n\t\t\tarray[currentIndex],\n\t\t]\n\t}\n\treturn array\n}\n\n/**\n * @name withTimeout\n * @summary Timeout a promise after a specified number of milliseconds.\n */\nexport const withTimeout = (\n\tms: number,\n\tpromise: Promise<unknown>,\n\toptions?: {\n\t\tonTimeout?: () => void\n\t},\n) => {\n\tconst timeout = new Promise((resolve) =>\n\t\tsetTimeout(async () => {\n\t\t\tif (typeof options?.onTimeout === 'function') {\n\t\t\t\toptions.onTimeout()\n\t\t\t}\n\t\t\tresolve(undefined)\n\t\t}, ms),\n\t)\n\treturn Promise.race([promise, timeout])\n}\n\n/**\n * @name withTimeoutThrow\n * @summary Timeout a promise after a specified number of milliseconds by throwing an error\n */\nexport const withTimeoutThrow = <T>(\n\tms: number,\n\tpromise: Promise<T>,\n\toptions?: {\n\t\tonTimeout?: () => void\n\t},\n) => {\n\tconst timeout = new Promise((reject) =>\n\t\tsetTimeout(async () => {\n\t\t\tif (typeof options?.onTimeout === 'function') {\n\t\t\t\toptions.onTimeout()\n\t\t\t}\n\t\t\treject('Function timeout')\n\t\t}, ms),\n\t)\n\treturn Promise.race([promise, timeout])\n}\n\n/**\n * @name appendOrEmpty\n * @summary Returns ` value` if a condition is truthy, or an empty string otherwise.\n */\nexport const appendOrEmpty = (\n\tcondition: boolean | string | undefined,\n\tvalue: string,\n) => (condition ? ` ${value}` : '')\n\n/**\n * @name appendOr\n * @summary Returns ` value` if condition is truthy, or ` fallback` otherwise.\n */\nexport const appendOr = (\n\tcondition: boolean | string | undefined,\n\tvalue: string,\n\tfallback: string,\n) => (condition ? ` ${value}` : ` ${fallback}`)\n\n/**\n * @name formatAccountSs58\n * @summary Formats an address with the supplied ss58 prefix, or returns null if invalid.\n */\nexport const formatAccountSs58 = (\n\taddress: string,\n\tss58: number,\n): string | null => {\n\ttry {\n\t\treturn encodeAddress(address, ss58)\n\t} catch {\n\t\treturn null\n\t}\n}\n\n/**\n * @name tryFormatSs58\n * @summary Formats an address with the supplied ss58 prefix, or returns the original address if\n * invalid.\n */\nexport const tryFormatSs58 = (address: string, ss58: number): string => {\n\ttry {\n\t\treturn encodeAddress(address, ss58)\n\t} catch {\n\t\treturn address\n\t}\n}\n\n/**\n * @name removeHexPrefix\n * @summary Takes a string str as input and returns a new string with the \"0x\" prefix removed if it\n * exists at the beginning of the input string.\n */\nexport const removeHexPrefix = (str: string): string => str.replace(/^0x/, '')\n\n// Check if 2 sets contain the same elements.\n// biome-ignore lint/suspicious/noExplicitAny: <>\nexport const eqSet = (xs: Set<any>, ys: Set<any>) =>\n\txs.size === ys.size && [...xs].every((x) => ys.has(x))\n\n// Check if one set contains all the elements of another set.\n// biome-ignore lint/suspicious/noExplicitAny: <>\nexport const isSuperset = (set: Set<any>, subset: Set<any>) => {\n\tfor (const elem of subset) {\n\t\tif (!set.has(elem)) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\n/**\n * Finds the maximum value among a list of BigInt values.\n *\n * @function maxBigInt\n * @param {...bigint} values - A list of BigInt values to compare.\n * @returns {bigint} The largest BigInt value in the provided list.\n * @example\n * // Returns the maximum BigInt value\n * maxBigInt(10n, 50n, 30n, 100n, 20n); // 100n\n */\nexport const maxBigInt = (...values: bigint[]): bigint =>\n\tvalues.reduce((max, current) => (current > max ? current : max))\n\n/**\n * Finds the minimum value among a list of BigInt values.\n *\n * @function minBigInt\n * @param {...bigint} values - A list of BigInt values to compare.\n * @returns {bigint} The smallest BigInt value in the provided list.\n * @example\n * // Returns the minimum BigInt value\n * minBigInt(10n, 50n, 30n, 100n, 20n); // 10n\n */\nexport const minBigInt = (...values: bigint[]): bigint =>\n\tvalues.reduce((min, current) => (current < min ? current : min))\n","// /* @license Copyright 2024 w3ux authors & contributors\n// SPDX-License-Identifier: GPL-3.0-only */\n\n/**\n * Concatenates multiple Uint8Array instances into a single Uint8Array.\n *\n * @param {Uint8Array[]} u8as - An array of Uint8Array instances to concatenate.\n * @returns {Uint8Array} A new Uint8Array containing all the input arrays concatenated.\n */\nexport const u8aConcat = (...u8as: Uint8Array[]): Uint8Array => {\n\t// Calculate the total length of the resulting Uint8Array\n\tconst totalLength = u8as.reduce((sum, u8a) => sum + u8a.length, 0)\n\n\t// Create a new Uint8Array with the total length\n\tconst result = new Uint8Array(totalLength)\n\n\tlet offset = 0 // Initialize the offset for placing elements\n\tfor (const u8a of u8as) {\n\t\tresult.set(u8a, offset) // Set the current Uint8Array at the current offset\n\t\toffset += u8a.length // Update the offset for the next Uint8Array\n\t}\n\n\treturn result\n}\n","/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { decodeAddress } from 'dedot/utils'\nimport type { RefObject } from 'react'\nimport { rmCommas, rmDecimals } from './base'\nimport type { AnyObject } from './types'\n\n/**\n * Converts an on-chain balance value from planck to a decimal value in token units.\n *\n * @function planckToUnit\n * @param {number | BigInt | string} val - The balance value in planck. Accepts a `number`, `BigInt`, or `string`.\n * @param {number} units - The number of decimal places in the token unit (10^units planck per 1 token).\n * @returns {string} The equivalent token unit value as a decimal string.\n * @example\n * // Convert 1500000000000 planck to tokens with 12 decimal places\n * planckToUnit(\"1500000000000\", 12); // returns \"1.5\"\n */\nexport const planckToUnit = (\n\tval: number | bigint | string,\n\tunits: number,\n): string => {\n\ttry {\n\t\t// Ensure `units` is a positive integer.\n\t\tunits = Math.max(Math.round(units), 0)\n\n\t\t// Convert `val` to BigInt based on its type\n\t\tconst bigIntVal =\n\t\t\ttypeof val === 'bigint'\n\t\t\t\t? val\n\t\t\t\t: BigInt(\n\t\t\t\t\t\ttypeof val === 'number'\n\t\t\t\t\t\t\t? Math.floor(val).toString()\n\t\t\t\t\t\t\t: rmDecimals(rmCommas(val)),\n\t\t\t\t\t)\n\n\t\tconst divisor = units === 0 ? 1n : BigInt(10) ** BigInt(units)\n\n\t\t// Integer division and remainder for the fractional part\n\t\tconst integerPart = bigIntVal / divisor\n\t\tconst fractionalPart = bigIntVal % divisor\n\n\t\t// Format fractional part with leading zeros to maintain `units` decimal places\n\t\tconst fractionalStr =\n\t\t\tunits > 0 ? `.${fractionalPart.toString().padStart(units, '0')}` : ``\n\n\t\t// Combine integer and fractional parts as a decimal string\n\t\treturn `${integerPart}${fractionalStr}`\n\t} catch {\n\t\treturn '0'\n\t}\n}\n\n/**\n * Converts a token unit value to an integer value in planck.\n *\n * @function unitToPlanck\n * @param {string | number | BigInt} val - The token unit value to convert. Accepts a string, number, or BigInt.\n * @param {number} units - The number of decimal places for conversion (10^units planck per 1 token).\n * @returns {BigInt} The equivalent value in planck as a BigInt.\n * @example\n * // Convert \"1.5\" tokens to planck with 12 decimal places\n * unitToPlanck(\"1.5\", 12); // returns BigInt(\"1500000000000\")\n */\nexport const unitToPlanck = (\n\tval: string | number | bigint,\n\tunits: number,\n): bigint => {\n\ttry {\n\t\t// Ensure `units` is a positive integer.\n\t\tunits = Math.max(Math.round(units), 0)\n\n\t\t// Convert `val` to a string; if empty or invalid, default to \"0\"\n\t\tconst strVal =\n\t\t\t(typeof val === 'string' ? rmCommas(val) : val.toString()) || '0'\n\n\t\t// Split into integer and fractional parts\n\t\tconst [integerPart, fractionalPart = ''] = strVal.split('.')\n\n\t\t// Process the integer part by converting to BigInt and scaling it to the given units\n\t\tlet bigIntValue = BigInt(integerPart) * BigInt(10) ** BigInt(units)\n\n\t\t// Process the fractional part if it exists\n\t\tif (fractionalPart) {\n\t\t\tlet fractionalValue: bigint\n\n\t\t\tif (fractionalPart.length > units) {\n\t\t\t\t// If fractional part exceeds units, truncate it\n\t\t\t\tfractionalValue = BigInt(fractionalPart.slice(0, units))\n\t\t\t} else {\n\t\t\t\t// Otherwise, pad the fractional part to match units\n\t\t\t\tfractionalValue = BigInt(fractionalPart.padEnd(units, '0'))\n\t\t\t}\n\n\t\t\tbigIntValue += fractionalValue\n\t\t}\n\n\t\treturn bigIntValue\n\t} catch {\n\t\treturn BigInt(0)\n\t}\n}\n\n/**\n * @name remToUnit\n * @summary Converts a rem string to a number.\n */\nexport const remToUnit = (rem: string) =>\n\tNumber(rem.slice(0, rem.length - 3)) *\n\tparseFloat(getComputedStyle(document.documentElement).fontSize)\n\n/**\n * @name capitalizeFirstLetter\n * @summary Capitalize the first letter of a string.\n */\nexport const capitalizeFirstLetter = (string: string) =>\n\tstring.charAt(0).toUpperCase() + string.slice(1)\n\n/**\n * @name snakeToCamel\n * @summary converts a string from snake / kebab-case to camel-case.\n */\nexport const snakeToCamel = (str: string) =>\n\tstr\n\t\t.toLowerCase()\n\t\t.replace(/([-_][a-z])/g, (group) =>\n\t\t\tgroup.toUpperCase().replace('-', '').replace('_', ''),\n\t\t)\n\n/**\n * @name setStateWithRef\n * @summary Synchronize React state and its reference with the provided value.\n */\nexport const setStateWithRef = <T>(\n\tvalue: T,\n\tsetState: (_state: T) => void,\n\tref: RefObject<T>,\n): void => {\n\tsetState(value)\n\tref.current = value\n}\n\n/**\n * @name localStorageOrDefault\n * @summary Retrieve the local stroage value with the key, return defult value if it is not\n * found.\n */\nexport const localStorageOrDefault = <T>(\n\tkey: string,\n\t_default: T,\n\tparse = false,\n): T | string => {\n\tconst val: string | null = localStorage.getItem(key)\n\n\tif (val === null) {\n\t\treturn _default\n\t}\n\n\tif (parse) {\n\t\treturn JSON.parse(val) as T\n\t}\n\treturn val\n}\n\n/**\n * @name isValidAddress\n * @summary Return whether an address is valid Substrate address.\n */\nexport const isValidAddress = (address: string): boolean => {\n\ttry {\n\t\tdecodeAddress(address)\n\t\treturn true\n\t} catch {\n\t\treturn false\n\t}\n}\n\n/**\n * @name extractUrlValue\n * @summary Extracts a URL value from a URL string.\n */\nexport const extractUrlValue = (key: string, url?: string) => {\n\tif (typeof url === 'undefined') {\n\t\turl = window.location.href\n\t}\n\tconst match = url.match(`[?&]${key}=([^&]+)`)\n\treturn match ? match[1] : null\n}\n\n/**\n * @name varToUrlHash\n * @summary Puts a variable into the URL hash as a param.\n * @description\n * Since url variables are added to the hash and are not treated as URL params, the params are split\n * and parsed into a `URLSearchParams`.\n */\nexport const varToUrlHash = (\n\tkey: string,\n\tval: string,\n\taddIfMissing: boolean,\n) => {\n\tconst hash = window.location.hash\n\tconst [page, params] = hash.split('?')\n\tconst searchParams = new URLSearchParams(params)\n\n\tif (searchParams.get(key) === null && !addIfMissing) {\n\t\treturn\n\t}\n\tsearchParams.set(key, val)\n\twindow.location.hash = `${page}?${searchParams.toString()}`\n}\n\n/**\n * @name removeVarFromUrlHash\n * @summary\n * Removes a variable `key` from the URL hash if it exists. Removes dangling `?` if no URL variables\n * exist.\n */\nexport const removeVarFromUrlHash = (key: string) => {\n\tconst hash = window.location.hash\n\tconst [page, params] = hash.split('?')\n\tconst searchParams = new URLSearchParams(params)\n\tif (searchParams.get(key) === null) {\n\t\treturn\n\t}\n\tsearchParams.delete(key)\n\tconst paramsAsStr = searchParams.toString()\n\twindow.location.hash = `${page}${paramsAsStr ? `?${paramsAsStr}` : ``}`\n}\n\n/**\n * @name sortWithNull\n * @summary Sorts an array with nulls last.\n */\nexport const sortWithNull =\n\t(ascending: boolean) => (a: unknown, b: unknown) => {\n\t\t// if both items are undefined, treat them as equal\n\t\tif (typeof a === 'undefined' && typeof b === 'undefined') {\n\t\t\treturn 0\n\t\t}\n\t\t// if either item is undefined, sort it last\n\t\tif (typeof a === 'undefined' || typeof b === 'undefined') {\n\t\t\treturn typeof a === 'undefined' ? 1 : -1\n\t\t}\n\t\t// equal items sort equally\n\t\tif (a === b) {\n\t\t\treturn 0\n\t\t}\n\t\t// nulls sort after anything else\n\t\tif (a === null) {\n\t\t\treturn 1\n\t\t}\n\t\tif (b === null) {\n\t\t\treturn -1\n\t\t}\n\t\t// otherwise, if we're ascending, lowest sorts first\n\t\tif (ascending) {\n\t\t\treturn a < b ? -1 : 1\n\t\t}\n\t\t// if descending, highest sorts first\n\t\treturn a < b ? 1 : -1\n\t}\n\n/**\n * @name applyWidthAsPadding\n * @summary Applies width of subject to paddingRight of container.\n */\nexport const applyWidthAsPadding = (\n\tsubjectRef: RefObject<HTMLDivElement | null>,\n\tcontainerRef: RefObject<HTMLDivElement | null>,\n) => {\n\tif (containerRef.current && subjectRef.current) {\n\t\tcontainerRef.current.style.paddingRight = `${\n\t\t\tsubjectRef.current.offsetWidth + remToUnit('1rem')\n\t\t}px`\n\t}\n}\n\n/**\n * @name unescape\n * @summary Replaces \\” with “\n */\nexport const unescape = (val: string) => val.replace(/\\\\\"/g, '\"')\n\n/**\n * @name inChrome\n * @summary Whether the application is rendering in Chrome.\n */\nexport const inChrome = () => {\n\tconst isChromium = (window as Window & { chrome?: boolean })?.chrome || null\n\tconst winNav = (window as Window)?.navigator || null\n\tconst isOpera =\n\t\ttypeof (window as Window & { opr?: boolean })?.opr !== 'undefined'\n\tconst isIEedge = winNav?.userAgent.indexOf('Edg') > -1 || false\n\tconst isIOSChrome = winNav?.userAgent.match('CriOS') || false\n\n\tif (isIOSChrome) {\n\t\treturn true\n\t}\n\tif (\n\t\tisChromium !== null &&\n\t\ttypeof isChromium !== 'undefined' &&\n\t\tisOpera === false &&\n\t\tisIEedge === false\n\t) {\n\t\treturn true\n\t}\n\treturn false\n}\n\n/**\n * @name addedTo\n * @summary Given 2 objects and some keys, return items in the fresh object that do not exist in the\n * stale object by matching the given common key values of both objects.\n */\nexport const addedTo = (\n\tfresh: AnyObject[],\n\tstale: AnyObject[],\n\tkeys: string[],\n): AnyObject[] =>\n\ttypeof fresh !== 'object' || typeof stale !== 'object' || !keys.length\n\t\t? []\n\t\t: fresh.filter(\n\t\t\t\t(freshItem) =>\n\t\t\t\t\t!stale.find((staleItem) =>\n\t\t\t\t\t\tkeys.every((key) =>\n\t\t\t\t\t\t\t!(key in staleItem) || !(key in freshItem)\n\t\t\t\t\t\t\t\t? false\n\t\t\t\t\t\t\t\t: staleItem[key] === freshItem[key],\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t)\n\n/**\n * @name removedFrom\n * @summary Given 2 objects and some keys, return items in the stale object that do not exist in the\n * fresh object by matching the given common key values of both objects.\n */\nexport const removedFrom = (\n\tfresh: AnyObject[],\n\tstale: AnyObject[],\n\tkeys: string[],\n): AnyObject[] =>\n\ttypeof fresh !== 'object' || typeof stale !== 'object' || !keys.length\n\t\t? []\n\t\t: stale.filter(\n\t\t\t\t(staleItem) =>\n\t\t\t\t\t!fresh.find((freshItem) =>\n\t\t\t\t\t\tkeys.every((key) =>\n\t\t\t\t\t\t\t!(key in staleItem) || !(key in freshItem)\n\t\t\t\t\t\t\t\t? false\n\t\t\t\t\t\t\t\t: freshItem[key] === staleItem[key],\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t)\n\n/**\n * @name matchedProperties\n * @summary Given 2 objects and some keys, return items in object 1 that also exist in object 2 by\n * matching the given common key values of both objects.\n */\nexport const matchedProperties = (\n\tobjX: AnyObject[],\n\tobjY: AnyObject[],\n\tkeys: string[],\n): AnyObject[] =>\n\ttypeof objX !== 'object' || typeof objY !== 'object' || !keys.length\n\t\t? []\n\t\t: objY.filter((x) =>\n\t\t\t\tobjX.find((y) =>\n\t\t\t\t\tkeys.every((key) =>\n\t\t\t\t\t\t!(key in x) || !(key in y) ? false : y[key] === x[key],\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t)\n\n/**\n * @name isValidHttpUrl\n * @summary Give a string, return whether it is a valid http URL.\n * @param string - The string to check.\n */\nexport const isValidHttpUrl = (string: string) => {\n\tlet url: URL\n\ttry {\n\t\turl = new URL(string)\n\t} catch (_) {\n\t\treturn false\n\t}\n\treturn url.protocol === 'http:' || url.protocol === 'https:'\n}\n\n/**\n * @name makeCancelable\n * @summary Makes a promise cancellable.\n * @param promise - The promise to make cancellable.\n */\nexport const makeCancelable = (promise: Promise<AnyObject>) => {\n\tlet hasCanceled = false\n\n\tconst wrappedPromise = new Promise((resolve, reject) => {\n\t\tpromise.then((val) =>\n\t\t\thasCanceled ? reject(Error('Cancelled')) : resolve(val),\n\t\t)\n\t\tpromise.catch((error) =>\n\t\t\thasCanceled ? reject(Error('Cancelled')) : reject(error),\n\t\t)\n\t})\n\n\treturn {\n\t\tpromise: wrappedPromise,\n\t\tcancel: () => {\n\t\t\thasCanceled = true\n\t\t},\n\t}\n}\n\n/**\n * @name unimplemented\n * @summary A placeholder function to signal a deliberate unimplementation.\n * Consumes an arbitrary number of props.\n */\nexport const unimplemented = (_props?: unknown) => {\n\t/* unimplemented */\n}\n\n/**\n * Deep merge two objects.\n * @param target\n * @param ...sources\n */\n\nexport const mergeDeep = (\n\ttarget: AnyObject,\n\t...sources: AnyObject[]\n): AnyObject => {\n\tif (!sources.length) {\n\t\treturn target\n\t}\n\n\tconst isObject = (item: AnyObject) =>\n\t\titem && typeof item === 'object' && !Array.isArray(item)\n\tconst source = sources.shift()\n\n\tif (isObject(target) && isObject(source)) {\n\t\tfor (const key in source) {\n\t\t\tif (isObject(source[key])) {\n\t\t\t\tif (!target[key]) {\n\t\t\t\t\tObject.assign(target, { [key]: {} })\n\t\t\t\t}\n\t\t\t\tmergeDeep(target[key], source[key])\n\t\t\t} else {\n\t\t\t\tObject.assign(target, { [key]: source[key] })\n\t\t\t}\n\t\t}\n\t}\n\treturn mergeDeep(target, ...sources)\n}\n"],"mappings":";AAGA,SAAS,qBAAqB;AAoBvB,IAAM,mBAAmB,CAC/B,KACA,gBACY;AACZ,MAAI;AAEH,UAAM,eAAe,OAAO,QAAQ,YAAY,IAAI,SAAS,GAAG;AAGhE,UAAM,SACL,OAAO,QAAQ,WAAW,IAAI,QAAQ,MAAM,EAAE,IAAI,IAAI,SAAS;AAGhE,UAAM,CAAC,aAAa,iBAAi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AS,QAAQ,MAAM;AAE7B,MAAI,SAAS,MAAM,KAAK,SAAS,MAAM,GAAG;AACzC,eAAW,OAAO,QAAQ;AACzB,UAAI,SAAS,OAAO,GAAG,CAAC,GAAG;AAC1B,YAAI,CAAC,OAAO,GAAG,GAAG;AACjB,iBAAO,OAAO,QAAQ,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC;AAAA,QACpC;AACA,kBAAU,OAAO,GAAG,GAAG,OAAO,GAAG,CAAC;AAAA,MACnC,OAAO;AACN,eAAO,OAAO,QAAQ,EAAE,CAAC,GAAG,GAAG,OAAO,GAAG,EAAE,CAAC;AAAA,MAC7C;AAAA,IACD;AAAA,EACD;AACA,SAAO,UAAU,QAAQ,GAAG,OAAO;AACpC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/base.ts","../src/convert.ts","../src/unit.ts"],"sourcesContent":["/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\n/**\n * Ensures a number has at least the specified number of decimal places, retaining commas in the output if they are present in the input.\n *\n * @function minDecimalPlaces\n * @param {string | number | BigInt} val - The input number, which can be a `string` with or without commas, a `number`, or a `BigInt`.\n * @param {number} minDecimals - The minimum number of decimal places to enforce.\n * @returns {string} The formatted number as a string, padded with zeros if needed to meet `minDecimals`, retaining commas if originally provided.\n * If `val` is invalid, returns \"0\".\n * @example\n * // Pads \"1,234.5\" to have at least 3 decimal places, with commas\n * minDecimalPlaces(\"1,234.5\", 3); // returns \"1,234.500\"\n *\n * // Returns \"1234.56\" unchanged\n * minDecimalPlaces(1234.56, 2); // returns \"1234.56\"\n *\n * // Pads BigInt 1234 with 2 decimals\n * minDecimalPlaces(BigInt(1234), 2); // returns \"1234.00\"\n */\nexport const minDecimalPlaces = (\n\tval: string | number | bigint,\n\tminDecimals: number,\n): string => {\n\ttry {\n\t\t// Determine if we should retain commas based on original input type\n\t\tconst retainCommas = typeof val === 'string' && val.includes(',')\n\n\t\t// Convert `val` to a plain string for processing\n\t\tconst strVal =\n\t\t\ttypeof val === 'string' ? val.replace(/,/g, '') : val.toString()\n\n\t\t// Separate integer and decimal parts\n\t\tconst [integerPart, fractionalPart = ''] = strVal.split('.')\n\n\t\t// Parse the integer part as a BigInt\n\t\tconst whole = BigInt(integerPart || '0')\n\n\t\t// Calculate missing decimal places\n\t\tconst missingDecimals = minDecimals - fractionalPart.length\n\n\t\t// Format the integer part back with commas only if the input had commas\n\t\tconst formattedWhole = retainCommas\n\t\t\t? Intl.NumberFormat('en-US').format(whole)\n\t\t\t: whole.toString()\n\n\t\t// If missing decimals are needed, pad with zeros; otherwise, return the original value\n\t\treturn missingDecimals > 0\n\t\t\t? `${formattedWhole}.${fractionalPart}${'0'.repeat(missingDecimals)}`\n\t\t\t: `${formattedWhole}.${fractionalPart}`\n\t} catch {\n\t\t// The provided value is not a valid number, return \"0\".\n\t\treturn '0'\n\t}\n}\n\n/**\n * @name camelize\n * @summary Converts a string of text to camelCase.\n */\nexport const camelize = (str: string) => {\n\tconst convertToString = (string: string) => {\n\t\tif (string) {\n\t\t\tif (typeof string === 'string') {\n\t\t\t\treturn string\n\t\t\t}\n\t\t\treturn String(string)\n\t\t}\n\t\treturn ''\n\t}\n\n\tconst toWords = (inp: string) =>\n\t\tconvertToString(inp).match(\n\t\t\t/[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,\n\t\t)\n\n\tconst simpleCamelCase = (inp: string[]) => {\n\t\tlet result = ''\n\t\tfor (let i = 0; i < inp?.length; i++) {\n\t\t\tconst currString = inp[i]\n\t\t\tlet tmpStr = currString.toLowerCase()\n\t\t\tif (i !== 0) {\n\t\t\t\ttmpStr =\n\t\t\t\t\ttmpStr.slice(0, 1).toUpperCase() + tmpStr.slice(1, tmpStr.length)\n\t\t\t}\n\t\t\tresult += tmpStr\n\t\t}\n\t\treturn result\n\t}\n\n\tconst w = toWords(str)?.map((a) => a.toLowerCase())\n\treturn simpleCamelCase(w || [])\n}\n\n/**\n * @name ellipsisFn\n * @summary Receives an address and creates ellipsis on the given string, based on parameters.\n * @param str - The string to apply the ellipsis on\n * @param amount - The amount of characters that the ellipsis will be\n * @param position - where the ellipsis will apply; if center the amount of character is the\n * same for beginning and end; if \"start\" or \"end\" then its only once the amount; defaults to \"start\"\n */\nexport const ellipsisFn = (\n\tstr: string,\n\tamount = 6,\n\tposition: 'start' | 'end' | 'center' = 'center',\n) => {\n\tconst half = str.length / 2\n\n\t// having an amount less than 4 is a bit extreme so we default there\n\tif (amount <= 4) {\n\t\tif (position === 'center') {\n\t\t\treturn str.slice(0, 4) + '...' + str.slice(-4)\n\t\t}\n\t\tif (position === 'end') {\n\t\t\treturn str.slice(0, 4) + '...'\n\t\t}\n\t\treturn '...' + str.slice(-4)\n\t}\n\t// if the amount requested is in a \"logical\" amount - meaning that it can display the address\n\t// without repeating the same information twice - then go for it;\n\tif (position === 'center') {\n\t\treturn amount >= (str.length - 2) / 2\n\t\t\t? str.slice(0, half - 3) + '...' + str.slice(-(half - 3))\n\t\t\t: str.slice(0, amount) + '...' + str.slice(-amount)\n\t}\n\t// else, the user has been mistaskenly extreme, so just show the maximum possible amount\n\tif (amount >= str.length) {\n\t\tif (position === 'end') {\n\t\t\treturn str.slice(0, str.length - 3) + '...'\n\t\t}\n\t\treturn '...' + str.slice(-(str.length - 3))\n\t} else {\n\t\tif (position === 'end') {\n\t\t\treturn str.slice(0, amount) + '...'\n\t\t}\n\t\treturn '...' + str.slice(amount)\n\t}\n}\n\n/**\n * @name pageFromUri\n * @summary Use url variables to load the default components upon the first page visit.\n */\nexport const pageFromUri = (pathname: string, fallback: string) => {\n\tconst lastUriItem = pathname.substring(pathname.lastIndexOf('/') + 1)\n\tconst page = lastUriItem.trim() === '' ? fallback : lastUriItem\n\treturn page.trim()\n}\n\n/**\n * @name rmCommas\n * @summary Removes the commas from a string.\n */\nexport const rmCommas = (val: string): string => val.replace(/,/g, '')\n\n/**\n * @name rmDecimals\n * @summary Removes the decimal point and decimals from a string.\n */\nexport const rmDecimals = (str: string) => str.split('.')[0]\n\n/**\n * @name shuffle\n * @summary Shuffle a set of objects.\n */\nexport const shuffle = <T>(array: T[]) => {\n\tlet currentIndex = array.length\n\tlet randomIndex\n\twhile (currentIndex !== 0) {\n\t\trandomIndex = Math.floor(Math.random() * currentIndex)\n\t\tcurrentIndex--\n\t\t;[array[currentIndex], array[randomIndex]] = [\n\t\t\tarray[randomIndex],\n\t\t\tarray[currentIndex],\n\t\t]\n\t}\n\treturn array\n}\n\n/**\n * @name withTimeout\n * @summary Timeout a promise after a specified number of milliseconds.\n */\nexport const withTimeout = (\n\tms: number,\n\tpromise: Promise<unknown>,\n\toptions?: {\n\t\tonTimeout?: () => void\n\t},\n) => {\n\tconst timeout = new Promise((resolve) =>\n\t\tsetTimeout(async () => {\n\t\t\tif (typeof options?.onTimeout === 'function') {\n\t\t\t\toptions.onTimeout()\n\t\t\t}\n\t\t\tresolve(undefined)\n\t\t}, ms),\n\t)\n\treturn Promise.race([promise, timeout])\n}\n\n/**\n * @name withTimeoutThrow\n * @summary Timeout a promise after a specified number of milliseconds by throwing an error\n */\nexport const withTimeoutThrow = <T>(\n\tms: number,\n\tpromise: Promise<T>,\n\toptions?: {\n\t\tonTimeout?: () => void\n\t},\n) => {\n\tconst timeout = new Promise((reject) =>\n\t\tsetTimeout(async () => {\n\t\t\tif (typeof options?.onTimeout === 'function') {\n\t\t\t\toptions.onTimeout()\n\t\t\t}\n\t\t\treject('Function timeout')\n\t\t}, ms),\n\t)\n\treturn Promise.race([promise, timeout])\n}\n\n/**\n * @name appendOrEmpty\n * @summary Returns ` value` if a condition is truthy, or an empty string otherwise.\n */\nexport const appendOrEmpty = (\n\tcondition: boolean | string | undefined,\n\tvalue: string,\n) => (condition ? ` ${value}` : '')\n\n/**\n * @name appendOr\n * @summary Returns ` value` if condition is truthy, or ` fallback` otherwise.\n */\nexport const appendOr = (\n\tcondition: boolean | string | undefined,\n\tvalue: string,\n\tfallback: string,\n) => (condition ? ` ${value}` : ` ${fallback}`)\n\n/**\n * @name removeHexPrefix\n * @summary Takes a string str as input and returns a new string with the \"0x\" prefix removed if it\n * exists at the beginning of the input string.\n */\nexport const removeHexPrefix = (str: string): string => str.replace(/^0x/, '')\n\n// Check if 2 sets contain the same elements.\n// biome-ignore lint/suspicious/noExplicitAny: <>\nexport const eqSet = (xs: Set<any>, ys: Set<any>) =>\n\txs.size === ys.size && [...xs].every((x) => ys.has(x))\n\n// Check if one set contains all the elements of another set.\n// biome-ignore lint/suspicious/noExplicitAny: <>\nexport const isSuperset = (set: Set<any>, subset: Set<any>) => {\n\tfor (const elem of subset) {\n\t\tif (!set.has(elem)) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\n/**\n * Finds the maximum value among a list of BigInt values.\n *\n * @function maxBigInt\n * @param {...bigint} values - A list of BigInt values to compare.\n * @returns {bigint} The largest BigInt value in the provided list.\n * @example\n * // Returns the maximum BigInt value\n * maxBigInt(10n, 50n, 30n, 100n, 20n); // 100n\n */\nexport const maxBigInt = (...values: bigint[]): bigint =>\n\tvalues.reduce((max, current) => (current > max ? current : max))\n\n/**\n * Finds the minimum value among a list of BigInt values.\n *\n * @function minBigInt\n * @param {...bigint} values - A list of BigInt values to compare.\n * @returns {bigint} The smallest BigInt value in the provided list.\n * @example\n * // Returns the minimum BigInt value\n * minBigInt(10n, 50n, 30n, 100n, 20n); // 10n\n */\nexport const minBigInt = (...values: bigint[]): bigint =>\n\tvalues.reduce((min, current) => (current < min ? current : min))\n","// /* @license Copyright 2024 w3ux authors & contributors\n// SPDX-License-Identifier: GPL-3.0-only */\n\n/**\n * Concatenates multiple Uint8Array instances into a single Uint8Array.\n *\n * @param {Uint8Array[]} u8as - An array of Uint8Array instances to concatenate.\n * @returns {Uint8Array} A new Uint8Array containing all the input arrays concatenated.\n */\nexport const u8aConcat = (...u8as: Uint8Array[]): Uint8Array => {\n\t// Calculate the total length of the resulting Uint8Array\n\tconst totalLength = u8as.reduce((sum, u8a) => sum + u8a.length, 0)\n\n\t// Create a new Uint8Array with the total length\n\tconst result = new Uint8Array(totalLength)\n\n\tlet offset = 0 // Initialize the offset for placing elements\n\tfor (const u8a of u8as) {\n\t\tresult.set(u8a, offset) // Set the current Uint8Array at the current offset\n\t\toffset += u8a.length // Update the offset for the next Uint8Array\n\t}\n\n\treturn result\n}\n","/* @license Copyright 2024 w3ux authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport type { RefObject } from 'react'\nimport { rmCommas, rmDecimals } from './base'\nimport type { AnyObject } from './types'\n\n/**\n * Converts an on-chain balance value from planck to a decimal value in token units.\n *\n * @function planckToUnit\n * @param {number | BigInt | string} val - The balance value in planck. Accepts a `number`, `BigInt`, or `string`.\n * @param {number} units - The number of decimal places in the token unit (10^units planck per 1 token).\n * @returns {string} The equivalent token unit value as a decimal string.\n * @example\n * // Convert 1500000000000 planck to tokens with 12 decimal places\n * planckToUnit(\"1500000000000\", 12); // returns \"1.5\"\n */\nexport const planckToUnit = (\n\tval: number | bigint | string,\n\tunits: number,\n): string => {\n\ttry {\n\t\t// Ensure `units` is a positive integer.\n\t\tunits = Math.max(Math.round(units), 0)\n\n\t\t// Convert `val` to BigInt based on its type\n\t\tconst bigIntVal =\n\t\t\ttypeof val === 'bigint'\n\t\t\t\t? val\n\t\t\t\t: BigInt(\n\t\t\t\t\t\ttypeof val === 'number'\n\t\t\t\t\t\t\t? Math.floor(val).toString()\n\t\t\t\t\t\t\t: rmDecimals(rmCommas(val)),\n\t\t\t\t\t)\n\n\t\tconst divisor = units === 0 ? 1n : BigInt(10) ** BigInt(units)\n\n\t\t// Integer division and remainder for the fractional part\n\t\tconst integerPart = bigIntVal / divisor\n\t\tconst fractionalPart = bigIntVal % divisor\n\n\t\t// Format fractional part with leading zeros to maintain `units` decimal places\n\t\tconst fractionalStr =\n\t\t\tunits > 0 ? `.${fractionalPart.toString().padStart(units, '0')}` : ``\n\n\t\t// Combine integer and fractional parts as a decimal string\n\t\treturn `${integerPart}${fractionalStr}`\n\t} catch {\n\t\treturn '0'\n\t}\n}\n\n/**\n * Converts a token unit value to an integer value in planck.\n *\n * @function unitToPlanck\n * @param {string | number | BigInt} val - The token unit value to convert. Accepts a string, number, or BigInt.\n * @param {number} units - The number of decimal places for conversion (10^units planck per 1 token).\n * @returns {BigInt} The equivalent value in planck as a BigInt.\n * @example\n * // Convert \"1.5\" tokens to planck with 12 decimal places\n * unitToPlanck(\"1.5\", 12); // returns BigInt(\"1500000000000\")\n */\nexport const unitToPlanck = (\n\tval: string | number | bigint,\n\tunits: number,\n): bigint => {\n\ttry {\n\t\t// Ensure `units` is a positive integer.\n\t\tunits = Math.max(Math.round(units), 0)\n\n\t\t// Convert `val` to a string; if empty or invalid, default to \"0\"\n\t\tconst strVal =\n\t\t\t(typeof val === 'string' ? rmCommas(val) : val.toString()) || '0'\n\n\t\t// Split into integer and fractional parts\n\t\tconst [integerPart, fractionalPart = ''] = strVal.split('.')\n\n\t\t// Process the integer part by converting to BigInt and scaling it to the given units\n\t\tlet bigIntValue = BigInt(integerPart) * BigInt(10) ** BigInt(units)\n\n\t\t// Process the fractional part if it exists\n\t\tif (fractionalPart) {\n\t\t\tlet fractionalValue: bigint\n\n\t\t\tif (fractionalPart.length > units) {\n\t\t\t\t// If fractional part exceeds units, truncate it\n\t\t\t\tfractionalValue = BigInt(fractionalPart.slice(0, units))\n\t\t\t} else {\n\t\t\t\t// Otherwise, pad the fractional part to match units\n\t\t\t\tfractionalValue = BigInt(fractionalPart.padEnd(units, '0'))\n\t\t\t}\n\n\t\t\tbigIntValue += fractionalValue\n\t\t}\n\n\t\treturn bigIntValue\n\t} catch {\n\t\treturn BigInt(0)\n\t}\n}\n\n/**\n * @name remToUnit\n * @summary Converts a rem string to a number.\n */\nexport const remToUnit = (rem: string) =>\n\tNumber(rem.slice(0, rem.length - 3)) *\n\tparseFloat(getComputedStyle(document.documentElement).fontSize)\n\n/**\n * @name capitalizeFirstLetter\n * @summary Capitalize the first letter of a string.\n */\nexport const capitalizeFirstLetter = (string: string) =>\n\tstring.charAt(0).toUpperCase() + string.slice(1)\n\n/**\n * @name snakeToCamel\n * @summary converts a string from snake / kebab-case to camel-case.\n */\nexport const snakeToCamel = (str: string) =>\n\tstr\n\t\t.toLowerCase()\n\t\t.replace(/([-_][a-z])/g, (group) =>\n\t\t\tgroup.toUpperCase().replace('-', '').replace('_', ''),\n\t\t)\n\n/**\n * @name setStateWithRef\n * @summary Synchronize React state and its reference with the provided value.\n */\nexport const setStateWithRef = <T>(\n\tvalue: T,\n\tsetState: (_state: T) => void,\n\tref: RefObject<T>,\n): void => {\n\tsetState(value)\n\tref.current = value\n}\n\n/**\n * @name localStorageOrDefault\n * @summary Retrieve the local stroage value with the key, return defult value if it is not\n * found.\n */\nexport const localStorageOrDefault = <T>(\n\tkey: string,\n\t_default: T,\n\tparse = false,\n): T | string => {\n\tconst val: string | null = localStorage.getItem(key)\n\n\tif (val === null) {\n\t\treturn _default\n\t}\n\n\tif (parse) {\n\t\treturn JSON.parse(val) as T\n\t}\n\treturn val\n}\n\n/**\n * @name extractUrlValue\n * @summary Extracts a URL value from a URL string.\n */\nexport const extractUrlValue = (key: string, url?: string) => {\n\tif (typeof url === 'undefined') {\n\t\turl = window.location.href\n\t}\n\tconst match = url.match(`[?&]${key}=([^&]+)`)\n\treturn match ? match[1] : null\n}\n\n/**\n * @name varToUrlHash\n * @summary Puts a variable into the URL hash as a param.\n * @description\n * Since url variables are added to the hash and are not treated as URL params, the params are split\n * and parsed into a `URLSearchParams`.\n */\nexport const varToUrlHash = (\n\tkey: string,\n\tval: string,\n\taddIfMissing: boolean,\n) => {\n\tconst hash = window.location.hash\n\tconst [page, params] = hash.split('?')\n\tconst searchParams = new URLSearchParams(params)\n\n\tif (searchParams.get(key) === null && !addIfMissing) {\n\t\treturn\n\t}\n\tsearchParams.set(key, val)\n\twindow.location.hash = `${page}?${searchParams.toString()}`\n}\n\n/**\n * @name removeVarFromUrlHash\n * @summary\n * Removes a variable `key` from the URL hash if it exists. Removes dangling `?` if no URL variables\n * exist.\n */\nexport const removeVarFromUrlHash = (key: string) => {\n\tconst hash = window.location.hash\n\tconst [page, params] = hash.split('?')\n\tconst searchParams = new URLSearchParams(params)\n\tif (searchParams.get(key) === null) {\n\t\treturn\n\t}\n\tsearchParams.delete(key)\n\tconst paramsAsStr = searchParams.toString()\n\twindow.location.hash = `${page}${paramsAsStr ? `?${paramsAsStr}` : ``}`\n}\n\n/**\n * @name sortWithNull\n * @summary Sorts an array with nulls last.\n */\nexport const sortWithNull =\n\t(ascending: boolean) => (a: unknown, b: unknown) => {\n\t\t// if both items are undefined, treat them as equal\n\t\tif (typeof a === 'undefined' && typeof b === 'undefined') {\n\t\t\treturn 0\n\t\t}\n\t\t// if either item is undefined, sort it last\n\t\tif (typeof a === 'undefined' || typeof b === 'undefined') {\n\t\t\treturn typeof a === 'undefined' ? 1 : -1\n\t\t}\n\t\t// equal items sort equally\n\t\tif (a === b) {\n\t\t\treturn 0\n\t\t}\n\t\t// nulls sort after anything else\n\t\tif (a === null) {\n\t\t\treturn 1\n\t\t}\n\t\tif (b === null) {\n\t\t\treturn -1\n\t\t}\n\t\t// otherwise, if we're ascending, lowest sorts first\n\t\tif (ascending) {\n\t\t\treturn a < b ? -1 : 1\n\t\t}\n\t\t// if descending, highest sorts first\n\t\treturn a < b ? 1 : -1\n\t}\n\n/**\n * @name applyWidthAsPadding\n * @summary Applies width of subject to paddingRight of container.\n */\nexport const applyWidthAsPadding = (\n\tsubjectRef: RefObject<HTMLDivElement | null>,\n\tcontainerRef: RefObject<HTMLDivElement | null>,\n) => {\n\tif (containerRef.current && subjectRef.current) {\n\t\tcontainerRef.current.style.paddingRight = `${\n\t\t\tsubjectRef.current.offsetWidth + remToUnit('1rem')\n\t\t}px`\n\t}\n}\n\n/**\n * @name unescape\n * @summary Replaces \\” with “\n */\nexport const unescape = (val: string) => val.replace(/\\\\\"/g, '\"')\n\n/**\n * @name inChrome\n * @summary Whether the application is rendering in Chrome.\n */\nexport const inChrome = () => {\n\tconst isChromium = (window as Window & { chrome?: boolean })?.chrome || null\n\tconst winNav = (window as Window)?.navigator || null\n\tconst isOpera =\n\t\ttypeof (window as Window & { opr?: boolean })?.opr !== 'undefined'\n\tconst isIEedge = winNav?.userAgent.indexOf('Edg') > -1 || false\n\tconst isIOSChrome = winNav?.userAgent.match('CriOS') || false\n\n\tif (isIOSChrome) {\n\t\treturn true\n\t}\n\tif (\n\t\tisChromium !== null &&\n\t\ttypeof isChromium !== 'undefined' &&\n\t\tisOpera === false &&\n\t\tisIEedge === false\n\t) {\n\t\treturn true\n\t}\n\treturn false\n}\n\n/**\n * @name addedTo\n * @summary Given 2 objects and some keys, return items in the fresh object that do not exist in the\n * stale object by matching the given common key values of both objects.\n */\nexport const addedTo = (\n\tfresh: AnyObject[],\n\tstale: AnyObject[],\n\tkeys: string[],\n): AnyObject[] =>\n\ttypeof fresh !== 'object' || typeof stale !== 'object' || !keys.length\n\t\t? []\n\t\t: fresh.filter(\n\t\t\t\t(freshItem) =>\n\t\t\t\t\t!stale.find((staleItem) =>\n\t\t\t\t\t\tkeys.every((key) =>\n\t\t\t\t\t\t\t!(key in staleItem) || !(key in freshItem)\n\t\t\t\t\t\t\t\t? false\n\t\t\t\t\t\t\t\t: staleItem[key] === freshItem[key],\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t)\n\n/**\n * @name removedFrom\n * @summary Given 2 objects and some keys, return items in the stale object that do not exist in the\n * fresh object by matching the given common key values of both objects.\n */\nexport const removedFrom = (\n\tfresh: AnyObject[],\n\tstale: AnyObject[],\n\tkeys: string[],\n): AnyObject[] =>\n\ttypeof fresh !== 'object' || typeof stale !== 'object' || !keys.length\n\t\t? []\n\t\t: stale.filter(\n\t\t\t\t(staleItem) =>\n\t\t\t\t\t!fresh.find((freshItem) =>\n\t\t\t\t\t\tkeys.every((key) =>\n\t\t\t\t\t\t\t!(key in staleItem) || !(key in freshItem)\n\t\t\t\t\t\t\t\t? false\n\t\t\t\t\t\t\t\t: freshItem[key] === staleItem[key],\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t)\n\n/**\n * @name matchedProperties\n * @summary Given 2 objects and some keys, return items in object 1 that also exist in object 2 by\n * matching the given common key values of both objects.\n */\nexport const matchedProperties = (\n\tobjX: AnyObject[],\n\tobjY: AnyObject[],\n\tkeys: string[],\n): AnyObject[] =>\n\ttypeof objX !== 'object' || typeof objY !== 'object' || !keys.length\n\t\t? []\n\t\t: objY.filter((x) =>\n\t\t\t\tobjX.find((y) =>\n\t\t\t\t\tkeys.every((key) =>\n\t\t\t\t\t\t!(key in x) || !(key in y) ? false : y[key] === x[key],\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t)\n\n/**\n * @name isValidHttpUrl\n * @summary Give a string, return whether it is a valid http URL.\n * @param string - The string to check.\n */\nexport const isValidHttpUrl = (string: string) => {\n\tlet url: URL\n\ttry {\n\t\turl = new URL(string)\n\t} catch (_) {\n\t\treturn false\n\t}\n\treturn url.protocol === 'http:' || url.protocol === 'https:'\n}\n\n/**\n * @name makeCancelable\n * @summary Makes a promise cancellable.\n * @param promise - The promise to make cancellable.\n */\nexport const makeCancelable = (promise: Promise<AnyObject>) => {\n\tlet hasCanceled = false\n\n\tconst wrappedPromise = new Promise((resolve, reject) => {\n\t\tpromise.then((val) =>\n\t\t\thasCanceled ? reject(Error('Cancelled')) : resolve(val),\n\t\t)\n\t\tpromise.catch((error) =>\n\t\t\thasCanceled ? reject(Error('Cancelled')) : reject(error),\n\t\t)\n\t})\n\n\treturn {\n\t\tpromise: wrappedPromise,\n\t\tcancel: () => {\n\t\t\thasCanceled = true\n\t\t},\n\t}\n}\n\n/**\n * @name unimplemented\n * @summary A placeholder function to signal a deliberate unimplementation.\n * Consumes an arbitrary number of props.\n */\nexport const unimplemented = (_props?: unknown) => {\n\t/* unimplemented */\n}\n\n/**\n * Deep merge two objects.\n * @param target\n * @param ...sources\n */\n\nexport const mergeDeep = (\n\ttarget: AnyObject,\n\t...sources: AnyObject[]\n): AnyObject => {\n\tif (!sources.length) {\n\t\treturn target\n\t}\n\n\tconst isObject = (item: AnyObject) =>\n\t\titem && typeof item === 'object' && !Array.isArray(item)\n\tconst source = sources.shift()\n\n\tif (isObject(target) && isObject(source)) {\n\t\tfor (const key in source) {\n\t\t\tif (isObject(source[key])) {\n\t\t\t\tif (!target[key]) {\n\t\t\t\t\tObject.assign(target, { [key]: {} })\n\t\t\t\t}\n\t\t\t\tmergeDeep(target[key], source[key])\n\t\t\t} else {\n\t\t\t\tObject.assign(target, { [key]: source[key] })\n\t\t\t}\n\t\t}\n\t}\n\treturn mergeDeep(target, ...sources)\n}\n"],"mappings":";AAqBO,IAAM,mBAAmB,CAC/B,KACA,gBACY;AACZ,MAAI;AAEH,UAAM,eAAe,OAAO,QAAQ,YAAY,IAAI,SAAS,GAAG;AAGhE,UAAM,SACL,OAAO,QAAQ,WAAW,IAAI,QAAQ,MAAM,EAAE,IAAI,IAAI,SAAS;AAGhE,UAAM,CAAC,aAAa,iBAAiB,EAAE,IAAI,OAAO,MAAM,GAAG;AAG3D,UAAM,QAAQ,OAAO,eAAe,GAAG;AAGvC,UAAM,kBAAkB,cAAc,eAAe;AAGrD,UAAM,iBAAiB,eACpB,KAAK,aAAa,OAAO,EAAE,OAAO,KAAK,IACvC,MAAM,SAAS;AAGlB,WAAO,kBAAkB,IACtB,GAAG,cAAc,IAAI,cAAc,GAAG,IAAI,OAAO,eAAe,CAAC,KACjE,GAAG,cAAc,IAAI,cAAc;AAAA,EACvC,QAAQ;AAEP,WAAO;AAAA,EACR;AACD;AAMO,IAAM,WAAW,CAAC,QAAgB;AACxC,QAAM,kBAAkB,CAAC,WAAmB;AAC3C,QAAI,QAAQ;AACX,UAAI,OAAO,WAAW,UAAU;AAC/B,eAAO;AAAA,MACR;A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,KAAK;AAAA,IACxD;AAAA,EACD,CAAC;AAED,SAAO;AAAA,IACN,SAAS;AAAA,IACT,QAAQ,MAAM;AACb,oBAAc;AAAA,IACf;AAAA,EACD;AACD;AAOO,IAAM,gBAAgB,CAAC,WAAqB;AAEnD;AAQO,IAAM,YAAY,CACxB,WACG,YACY;AACf,MAAI,CAAC,QAAQ,QAAQ;AACpB,WAAO;AAAA,EACR;AAEA,QAAM,WAAW,CAAC,SACjB,QAAQ,OAAO,SAAS,YAAY,CAAC,MAAM,QAAQ,IAAI;AACxD,QAAM,SAAS,QAAQ,MAAM;AAE7B,MAAI,SAAS,MAAM,KAAK,SAAS,MAAM,GAAG;AACzC,eAAW,OAAO,QAAQ;AACzB,UAAI,SAAS,OAAO,GAAG,CAAC,GAAG;AAC1B,YAAI,CAAC,OAAO,GAAG,GAAG;AACjB,iBAAO,OAAO,QAAQ,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC;AAAA,QACpC;AACA,kBAAU,OAAO,GAAG,GAAG,OAAO,GAAG,CAAC;AAAA,MACnC,OAAO;AACN,eAAO,OAAO,QAAQ,EAAE,CAAC,GAAG,GAAG,OAAO,GAAG,EAAE,CAAC;AAAA,MAC7C;AAAA,IACD;AAAA,EACD;AACA,SAAO,UAAU,QAAQ,GAAG,OAAO;AACpC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@w3ux/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"license": "GPL-3.0-only",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A collection of reusable utilities for manipulating data",
|
|
@@ -26,8 +26,5 @@
|
|
|
26
26
|
"import": "./index.js",
|
|
27
27
|
"require": "./index.cjs"
|
|
28
28
|
}
|
|
29
|
-
},
|
|
30
|
-
"dependencies": {
|
|
31
|
-
"dedot": "1.0.4"
|
|
32
29
|
}
|
|
33
30
|
}
|