@w3ux/utils 1.1.1-beta.1 → 1.1.1-beta.11

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/base.cjs CHANGED
@@ -32,6 +32,7 @@ __export(base_exports, {
32
32
  pageFromUri: () => pageFromUri,
33
33
  removeHexPrefix: () => removeHexPrefix,
34
34
  rmCommas: () => rmCommas,
35
+ rmDecimals: () => rmDecimals,
35
36
  shuffle: () => shuffle,
36
37
  withTimeout: () => withTimeout
37
38
  });
@@ -110,6 +111,7 @@ var pageFromUri = (pathname, fallback) => {
110
111
  return page.trim();
111
112
  };
112
113
  var rmCommas = (val) => val.replace(/,/g, "");
114
+ var rmDecimals = (str) => str.split(".")[0];
113
115
  var shuffle = (array) => {
114
116
  let currentIndex = array.length;
115
117
  let randomIndex;
@@ -171,6 +173,7 @@ var minBigInt = (...values) => values.reduce((min, current) => current < min ? c
171
173
  pageFromUri,
172
174
  removeHexPrefix,
173
175
  rmCommas,
176
+ rmDecimals,
174
177
  shuffle,
175
178
  withTimeout
176
179
  });
package/base.d.cts CHANGED
@@ -43,6 +43,11 @@ declare const pageFromUri: (pathname: string, fallback: string) => string;
43
43
  * @summary Removes the commas from a string.
44
44
  */
45
45
  declare const rmCommas: (val: string) => string;
46
+ /**
47
+ * @name rmCommas
48
+ * @summary Removes the decimal point and decimals from a string.
49
+ */
50
+ declare const rmDecimals: (str: any) => any;
46
51
  /**
47
52
  * @name shuffle
48
53
  * @summary Shuffle a set of objects.
@@ -101,4 +106,4 @@ declare const maxBigInt: (...values: bigint[]) => bigint;
101
106
  */
102
107
  declare const minBigInt: (...values: bigint[]) => bigint;
103
108
 
104
- export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout };
109
+ export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, rmDecimals, shuffle, withTimeout };
package/base.d.ts CHANGED
@@ -43,6 +43,11 @@ declare const pageFromUri: (pathname: string, fallback: string) => string;
43
43
  * @summary Removes the commas from a string.
44
44
  */
45
45
  declare const rmCommas: (val: string) => string;
46
+ /**
47
+ * @name rmCommas
48
+ * @summary Removes the decimal point and decimals from a string.
49
+ */
50
+ declare const rmDecimals: (str: any) => any;
46
51
  /**
47
52
  * @name shuffle
48
53
  * @summary Shuffle a set of objects.
@@ -101,4 +106,4 @@ declare const maxBigInt: (...values: bigint[]) => bigint;
101
106
  */
102
107
  declare const minBigInt: (...values: bigint[]) => bigint;
103
108
 
104
- export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout };
109
+ export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, rmDecimals, shuffle, withTimeout };
package/base.js CHANGED
@@ -73,6 +73,7 @@ var pageFromUri = (pathname, fallback) => {
73
73
  return page.trim();
74
74
  };
75
75
  var rmCommas = (val) => val.replace(/,/g, "");
76
+ var rmDecimals = (str) => str.split(".")[0];
76
77
  var shuffle = (array) => {
77
78
  let currentIndex = array.length;
78
79
  let randomIndex;
@@ -133,6 +134,7 @@ export {
133
134
  pageFromUri,
134
135
  removeHexPrefix,
135
136
  rmCommas,
137
+ rmDecimals,
136
138
  shuffle,
137
139
  withTimeout
138
140
  };
@@ -16,31 +16,24 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // src/conversions.ts
20
- var conversions_exports = {};
21
- __export(conversions_exports, {
22
- stringToU8a: () => stringToU8a,
23
- u8aToString: () => u8aToString
19
+ // src/convert.ts
20
+ var convert_exports = {};
21
+ __export(convert_exports, {
22
+ u8aConcat: () => u8aConcat
24
23
  });
25
- module.exports = __toCommonJS(conversions_exports);
26
- var stringToU8a = (input) => {
27
- const u8a = new Uint8Array(input.length);
28
- for (let i = 0; i < input.length; i++) {
29
- u8a[i] = input.charCodeAt(i);
24
+ module.exports = __toCommonJS(convert_exports);
25
+ var u8aConcat = (...u8as) => {
26
+ const totalLength = u8as.reduce((sum, u8a) => sum + u8a.length, 0);
27
+ const result = new Uint8Array(totalLength);
28
+ let offset = 0;
29
+ for (const u8a of u8as) {
30
+ result.set(u8a, offset);
31
+ offset += u8a.length;
30
32
  }
31
- return u8a;
32
- };
33
- var u8aToString = (u8a) => {
34
- const chars = new Array(u8a.length);
35
- for (let i = 0; i < u8a.length; i++) {
36
- chars[i] = String.fromCharCode(u8a[i]);
37
- }
38
- return chars.join("");
33
+ return result;
39
34
  };
40
35
  // Annotate the CommonJS export names for ESM import in node:
41
36
  0 && (module.exports = {
42
- stringToU8a,
43
- u8aToString
37
+ u8aConcat
44
38
  });
45
- /* @license Copyright 2024 w3ux authors & contributors
46
- SPDX-License-Identifier: GPL-3.0-only */
39
+ // /* @license Copyright 2024 w3ux authors & contributors
package/convert.d.cts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Concatenates multiple Uint8Array instances into a single Uint8Array.
3
+ *
4
+ * @param {Uint8Array[]} u8as - An array of Uint8Array instances to concatenate.
5
+ * @returns {Uint8Array} A new Uint8Array containing all the input arrays concatenated.
6
+ */
7
+ declare const u8aConcat: (...u8as: Uint8Array[]) => Uint8Array;
8
+
9
+ export { u8aConcat };
package/convert.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Concatenates multiple Uint8Array instances into a single Uint8Array.
3
+ *
4
+ * @param {Uint8Array[]} u8as - An array of Uint8Array instances to concatenate.
5
+ * @returns {Uint8Array} A new Uint8Array containing all the input arrays concatenated.
6
+ */
7
+ declare const u8aConcat: (...u8as: Uint8Array[]) => Uint8Array;
8
+
9
+ export { u8aConcat };
package/convert.js ADDED
@@ -0,0 +1,15 @@
1
+ // src/convert.ts
2
+ var u8aConcat = (...u8as) => {
3
+ const totalLength = u8as.reduce((sum, u8a) => sum + u8a.length, 0);
4
+ const result = new Uint8Array(totalLength);
5
+ let offset = 0;
6
+ for (const u8a of u8as) {
7
+ result.set(u8a, offset);
8
+ offset += u8a.length;
9
+ }
10
+ return result;
11
+ };
12
+ export {
13
+ u8aConcat
14
+ };
15
+ // /* @license Copyright 2024 w3ux authors & contributors
package/index.cjs CHANGED
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,14 +14,6 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
18
 
29
19
  // src/index.ts
@@ -35,7 +25,6 @@ __export(src_exports, {
35
25
  applyWidthAsPadding: () => applyWidthAsPadding,
36
26
  camelize: () => camelize,
37
27
  capitalizeFirstLetter: () => capitalizeFirstLetter,
38
- determinePoolDisplay: () => determinePoolDisplay,
39
28
  ellipsisFn: () => ellipsisFn,
40
29
  eqSet: () => eqSet,
41
30
  extractUrlValue: () => extractUrlValue,
@@ -58,12 +47,12 @@ __export(src_exports, {
58
47
  removeVarFromUrlHash: () => removeVarFromUrlHash,
59
48
  removedFrom: () => removedFrom,
60
49
  rmCommas: () => rmCommas,
50
+ rmDecimals: () => rmDecimals,
61
51
  setStateWithRef: () => setStateWithRef,
62
52
  shuffle: () => shuffle,
63
53
  snakeToCamel: () => snakeToCamel,
64
54
  sortWithNull: () => sortWithNull,
65
- stringToU8a: () => stringToU8a,
66
- u8aToString: () => u8aToString,
55
+ u8aConcat: () => u8aConcat,
67
56
  unescape: () => unescape,
68
57
  unimplemented: () => unimplemented,
69
58
  unitToPlanck: () => unitToPlanck,
@@ -147,6 +136,7 @@ var pageFromUri = (pathname, fallback) => {
147
136
  return page.trim();
148
137
  };
149
138
  var rmCommas = (val) => val.replace(/,/g, "");
139
+ var rmDecimals = (str) => str.split(".")[0];
150
140
  var shuffle = (array) => {
151
141
  let currentIndex = array.length;
152
142
  let randomIndex;
@@ -194,167 +184,17 @@ var isSuperset = (set, subset) => {
194
184
  var maxBigInt = (...values) => values.reduce((max, current) => current > max ? current : max);
195
185
  var minBigInt = (...values) => values.reduce((min, current) => current < min ? current : min);
196
186
 
197
- // src/conversions.ts
198
- var stringToU8a = (input) => {
199
- const u8a = new Uint8Array(input.length);
200
- for (let i = 0; i < input.length; i++) {
201
- u8a[i] = input.charCodeAt(i);
202
- }
203
- return u8a;
204
- };
205
- var u8aToString = (u8a) => {
206
- const chars = new Array(u8a.length);
207
- for (let i = 0; i < u8a.length; i++) {
208
- chars[i] = String.fromCharCode(u8a[i]);
209
- }
210
- return chars.join("");
211
- };
212
-
213
- // ../../node_modules/@polkadot/x-textdecoder/node.js
214
- var import_node_util = __toESM(require("util"), 1);
215
-
216
- // ../../node_modules/@polkadot/x-global/index.js
217
- function evaluateThis(fn) {
218
- return fn("return this");
219
- }
220
- var xglobal = typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : evaluateThis(Function);
221
- function extractGlobal(name, fallback) {
222
- return typeof xglobal[name] === "undefined" ? fallback : xglobal[name];
223
- }
224
-
225
- // ../../node_modules/@polkadot/x-textdecoder/node.js
226
- var TextDecoder = /* @__PURE__ */ extractGlobal("TextDecoder", import_node_util.default.TextDecoder);
227
-
228
- // ../../node_modules/@polkadot/x-textencoder/node.js
229
- var import_node_util2 = __toESM(require("util"), 1);
230
- var Fallback = class {
231
- __internal__encoder;
232
- constructor() {
233
- this.__internal__encoder = new import_node_util2.default.TextEncoder();
234
- }
235
- // For a Jest 26.0.1 environment, Buffer !== Uint8Array
236
- encode(value) {
237
- return Uint8Array.from(this.__internal__encoder.encode(value));
238
- }
239
- };
240
- var TextEncoder = /* @__PURE__ */ extractGlobal("TextEncoder", Fallback);
241
-
242
- // ../../node_modules/@polkadot/util/is/function.js
243
- function isFunction(value) {
244
- return typeof value === "function";
245
- }
246
-
247
- // ../../node_modules/@polkadot/x-bigint/index.js
248
- function invalidFallback() {
249
- return Number.NaN;
250
- }
251
- var BigInt2 = /* @__PURE__ */ extractGlobal("BigInt", invalidFallback);
252
-
253
- // ../../node_modules/@polkadot/util/hex/toU8a.js
254
- var CHR = "0123456789abcdef";
255
- var U8 = new Uint8Array(256);
256
- var U16 = new Uint8Array(256 * 256);
257
- for (let i = 0, count = CHR.length; i < count; i++) {
258
- U8[CHR[i].charCodeAt(0) | 0] = i | 0;
259
- if (i > 9) {
260
- U8[CHR[i].toUpperCase().charCodeAt(0) | 0] = i | 0;
261
- }
262
- }
263
- for (let i = 0; i < 256; i++) {
264
- const s = i << 8;
265
- for (let j = 0; j < 256; j++) {
266
- U16[s | j] = U8[i] << 4 | U8[j];
267
- }
268
- }
269
- function hexToU8a(value, bitLength = -1) {
270
- if (!value) {
271
- return new Uint8Array();
272
- }
273
- let s = value.startsWith("0x") ? 2 : 0;
274
- const decLength = Math.ceil((value.length - s) / 2);
275
- const endLength = Math.ceil(bitLength === -1 ? decLength : bitLength / 8);
276
- const result = new Uint8Array(endLength);
277
- const offset = endLength > decLength ? endLength - decLength : 0;
278
- for (let i = offset; i < endLength; i++, s += 2) {
279
- result[i] = U16[value.charCodeAt(s) << 8 | value.charCodeAt(s + 1)];
187
+ // src/convert.ts
188
+ var u8aConcat = (...u8as) => {
189
+ const totalLength = u8as.reduce((sum, u8a) => sum + u8a.length, 0);
190
+ const result = new Uint8Array(totalLength);
191
+ let offset = 0;
192
+ for (const u8a of u8as) {
193
+ result.set(u8a, offset);
194
+ offset += u8a.length;
280
195
  }
281
196
  return result;
282
- }
283
-
284
- // ../../node_modules/@polkadot/util/is/hex.js
285
- var REGEX_HEX_PREFIXED = /^0x[\da-fA-F]+$/;
286
- function isHex(value, bitLength = -1, ignoreLength) {
287
- return typeof value === "string" && (value === "0x" || REGEX_HEX_PREFIXED.test(value)) && (bitLength === -1 ? ignoreLength || value.length % 2 === 0 : value.length === 2 + Math.ceil(bitLength / 4));
288
- }
289
-
290
- // ../../node_modules/@polkadot/util/has.js
291
- var hasBigInt = typeof BigInt2 === "function" && typeof BigInt2.asIntN === "function";
292
- var hasBuffer = typeof xglobal.Buffer === "function" && typeof xglobal.Buffer.isBuffer === "function";
293
- var hasProcess = typeof xglobal.process === "object";
294
-
295
- // ../../node_modules/@polkadot/util/is/buffer.js
296
- function isBuffer(value) {
297
- return hasBuffer && !!value && isFunction(value.readDoubleLE) && xglobal.Buffer.isBuffer(value);
298
- }
299
-
300
- // ../../node_modules/@polkadot/util/is/u8a.js
301
- function isU8a(value) {
302
- return (value && value.constructor) === Uint8Array || value instanceof Uint8Array;
303
- }
304
-
305
- // ../../node_modules/@polkadot/util/string/toU8a.js
306
- var encoder = new TextEncoder();
307
- function stringToU8a2(value) {
308
- return value ? encoder.encode(value.toString()) : new Uint8Array();
309
- }
310
-
311
- // ../../node_modules/@polkadot/util/u8a/toU8a.js
312
- function u8aToU8a(value) {
313
- return isU8a(value) ? isBuffer(value) ? new Uint8Array(value) : value : isHex(value) ? hexToU8a(value) : Array.isArray(value) ? new Uint8Array(value) : stringToU8a2(value);
314
- }
315
-
316
- // ../../node_modules/@polkadot/util/u8a/eq.js
317
- function u8aEq(a, b) {
318
- const u8aa = u8aToU8a(a);
319
- const u8ab = u8aToU8a(b);
320
- if (u8aa.length === u8ab.length) {
321
- const dvA = new DataView(u8aa.buffer, u8aa.byteOffset);
322
- const dvB = new DataView(u8ab.buffer, u8ab.byteOffset);
323
- const mod = u8aa.length % 4 | 0;
324
- const length = u8aa.length - mod | 0;
325
- for (let i = 0; i < length; i += 4) {
326
- if (dvA.getUint32(i) !== dvB.getUint32(i)) {
327
- return false;
328
- }
329
- }
330
- for (let i = length, count = u8aa.length; i < count; i++) {
331
- if (u8aa[i] !== u8ab[i]) {
332
- return false;
333
- }
334
- }
335
- return true;
336
- }
337
- return false;
338
- }
339
-
340
- // ../../node_modules/@polkadot/util/u8a/toString.js
341
- var decoder = new TextDecoder("utf-8");
342
- function u8aToString2(value) {
343
- return value ? decoder.decode(value) : "";
344
- }
345
-
346
- // ../../node_modules/@polkadot/util/u8a/wrap.js
347
- var U8A_WRAP_ETHEREUM = /* @__PURE__ */ u8aToU8a("Ethereum Signed Message:\n");
348
- var U8A_WRAP_PREFIX = /* @__PURE__ */ u8aToU8a("<Bytes>");
349
- var U8A_WRAP_POSTFIX = /* @__PURE__ */ u8aToU8a("</Bytes>");
350
- var WRAP_LEN = U8A_WRAP_PREFIX.length + U8A_WRAP_POSTFIX.length;
351
- function u8aIsWrapped(u8a, withEthereum) {
352
- return u8a.length >= WRAP_LEN && u8aEq(u8a.subarray(0, U8A_WRAP_PREFIX.length), U8A_WRAP_PREFIX) && u8aEq(u8a.slice(-U8A_WRAP_POSTFIX.length), U8A_WRAP_POSTFIX) || withEthereum && u8a.length >= U8A_WRAP_ETHEREUM.length && u8aEq(u8a.subarray(0, U8A_WRAP_ETHEREUM.length), U8A_WRAP_ETHEREUM);
353
- }
354
- function u8aUnwrapBytes(bytes) {
355
- const u8a = u8aToU8a(bytes);
356
- return u8aIsWrapped(u8a, false) ? u8a.subarray(U8A_WRAP_PREFIX.length, u8a.length - U8A_WRAP_POSTFIX.length) : u8a;
357
- }
197
+ };
358
198
 
359
199
  // src/unit.ts
360
200
  var import_substrate_bindings2 = require("@polkadot-api/substrate-bindings");
@@ -362,7 +202,7 @@ var planckToUnit = (val, units) => {
362
202
  try {
363
203
  units = Math.max(Math.round(units), 0);
364
204
  const bigIntVal = typeof val === "bigint" ? val : BigInt(
365
- typeof val === "number" ? Math.floor(val).toString() : rmCommas(val)
205
+ typeof val === "number" ? Math.floor(val).toString() : rmDecimals(rmCommas(val))
366
206
  );
367
207
  const divisor = units === 0 ? 1n : BigInt(10) ** BigInt(units);
368
208
  const integerPart = bigIntVal / divisor;
@@ -422,18 +262,6 @@ var isValidAddress = (address) => {
422
262
  return false;
423
263
  }
424
264
  };
425
- var determinePoolDisplay = (address, batchItem) => {
426
- const defaultDisplay = ellipsisFn(address, 6);
427
- let display = batchItem ?? defaultDisplay;
428
- const displayAsBytes = u8aToString2(u8aUnwrapBytes(display));
429
- if (displayAsBytes !== "") {
430
- display = displayAsBytes;
431
- }
432
- if (display === "") {
433
- display = defaultDisplay;
434
- }
435
- return display;
436
- };
437
265
  var extractUrlValue = (key, url) => {
438
266
  if (typeof url === "undefined") {
439
267
  url = window.location.href;
@@ -574,7 +402,6 @@ var mergeDeep = (target, ...sources) => {
574
402
  applyWidthAsPadding,
575
403
  camelize,
576
404
  capitalizeFirstLetter,
577
- determinePoolDisplay,
578
405
  ellipsisFn,
579
406
  eqSet,
580
407
  extractUrlValue,
@@ -597,12 +424,12 @@ var mergeDeep = (target, ...sources) => {
597
424
  removeVarFromUrlHash,
598
425
  removedFrom,
599
426
  rmCommas,
427
+ rmDecimals,
600
428
  setStateWithRef,
601
429
  shuffle,
602
430
  snakeToCamel,
603
431
  sortWithNull,
604
- stringToU8a,
605
- u8aToString,
432
+ u8aConcat,
606
433
  unescape,
607
434
  unimplemented,
608
435
  unitToPlanck,
@@ -611,3 +438,4 @@ var mergeDeep = (target, ...sources) => {
611
438
  });
612
439
  /* @license Copyright 2024 w3ux authors & contributors
613
440
  SPDX-License-Identifier: GPL-3.0-only */
441
+ // /* @license Copyright 2024 w3ux authors & contributors
package/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout } from './base.cjs';
2
- export { stringToU8a, u8aToString } from './conversions.cjs';
3
- export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, determinePoolDisplay, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, unescape, unimplemented, unitToPlanck, varToUrlHash } from './unit.cjs';
1
+ export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, rmDecimals, shuffle, withTimeout } from './base.cjs';
2
+ export { u8aConcat } from './convert.cjs';
3
+ export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, unescape, unimplemented, unitToPlanck, varToUrlHash } from './unit.cjs';
4
4
  import '@w3ux/types';
5
5
  import 'react';
6
6
  import './types.cjs';
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout } from './base.js';
2
- export { stringToU8a, u8aToString } from './conversions.js';
3
- export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, determinePoolDisplay, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, unescape, unimplemented, unitToPlanck, varToUrlHash } from './unit.js';
1
+ export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, maxBigInt, minBigInt, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, rmDecimals, shuffle, withTimeout } from './base.js';
2
+ export { u8aConcat } from './convert.js';
3
+ export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, unescape, unimplemented, unitToPlanck, varToUrlHash } from './unit.js';
4
4
  import '@w3ux/types';
5
5
  import 'react';
6
6
  import './types.js';
package/index.js CHANGED
@@ -73,6 +73,7 @@ var pageFromUri = (pathname, fallback) => {
73
73
  return page.trim();
74
74
  };
75
75
  var rmCommas = (val) => val.replace(/,/g, "");
76
+ var rmDecimals = (str) => str.split(".")[0];
76
77
  var shuffle = (array) => {
77
78
  let currentIndex = array.length;
78
79
  let randomIndex;
@@ -120,167 +121,17 @@ var isSuperset = (set, subset) => {
120
121
  var maxBigInt = (...values) => values.reduce((max, current) => current > max ? current : max);
121
122
  var minBigInt = (...values) => values.reduce((min, current) => current < min ? current : min);
122
123
 
123
- // src/conversions.ts
124
- var stringToU8a = (input) => {
125
- const u8a = new Uint8Array(input.length);
126
- for (let i = 0; i < input.length; i++) {
127
- u8a[i] = input.charCodeAt(i);
128
- }
129
- return u8a;
130
- };
131
- var u8aToString = (u8a) => {
132
- const chars = new Array(u8a.length);
133
- for (let i = 0; i < u8a.length; i++) {
134
- chars[i] = String.fromCharCode(u8a[i]);
135
- }
136
- return chars.join("");
137
- };
138
-
139
- // ../../node_modules/@polkadot/x-textdecoder/node.js
140
- import util from "node:util";
141
-
142
- // ../../node_modules/@polkadot/x-global/index.js
143
- function evaluateThis(fn) {
144
- return fn("return this");
145
- }
146
- var xglobal = typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : evaluateThis(Function);
147
- function extractGlobal(name, fallback) {
148
- return typeof xglobal[name] === "undefined" ? fallback : xglobal[name];
149
- }
150
-
151
- // ../../node_modules/@polkadot/x-textdecoder/node.js
152
- var TextDecoder = /* @__PURE__ */ extractGlobal("TextDecoder", util.TextDecoder);
153
-
154
- // ../../node_modules/@polkadot/x-textencoder/node.js
155
- import util2 from "node:util";
156
- var Fallback = class {
157
- __internal__encoder;
158
- constructor() {
159
- this.__internal__encoder = new util2.TextEncoder();
160
- }
161
- // For a Jest 26.0.1 environment, Buffer !== Uint8Array
162
- encode(value) {
163
- return Uint8Array.from(this.__internal__encoder.encode(value));
164
- }
165
- };
166
- var TextEncoder = /* @__PURE__ */ extractGlobal("TextEncoder", Fallback);
167
-
168
- // ../../node_modules/@polkadot/util/is/function.js
169
- function isFunction(value) {
170
- return typeof value === "function";
171
- }
172
-
173
- // ../../node_modules/@polkadot/x-bigint/index.js
174
- function invalidFallback() {
175
- return Number.NaN;
176
- }
177
- var BigInt2 = /* @__PURE__ */ extractGlobal("BigInt", invalidFallback);
178
-
179
- // ../../node_modules/@polkadot/util/hex/toU8a.js
180
- var CHR = "0123456789abcdef";
181
- var U8 = new Uint8Array(256);
182
- var U16 = new Uint8Array(256 * 256);
183
- for (let i = 0, count = CHR.length; i < count; i++) {
184
- U8[CHR[i].charCodeAt(0) | 0] = i | 0;
185
- if (i > 9) {
186
- U8[CHR[i].toUpperCase().charCodeAt(0) | 0] = i | 0;
187
- }
188
- }
189
- for (let i = 0; i < 256; i++) {
190
- const s = i << 8;
191
- for (let j = 0; j < 256; j++) {
192
- U16[s | j] = U8[i] << 4 | U8[j];
193
- }
194
- }
195
- function hexToU8a(value, bitLength = -1) {
196
- if (!value) {
197
- return new Uint8Array();
198
- }
199
- let s = value.startsWith("0x") ? 2 : 0;
200
- const decLength = Math.ceil((value.length - s) / 2);
201
- const endLength = Math.ceil(bitLength === -1 ? decLength : bitLength / 8);
202
- const result = new Uint8Array(endLength);
203
- const offset = endLength > decLength ? endLength - decLength : 0;
204
- for (let i = offset; i < endLength; i++, s += 2) {
205
- result[i] = U16[value.charCodeAt(s) << 8 | value.charCodeAt(s + 1)];
124
+ // src/convert.ts
125
+ var u8aConcat = (...u8as) => {
126
+ const totalLength = u8as.reduce((sum, u8a) => sum + u8a.length, 0);
127
+ const result = new Uint8Array(totalLength);
128
+ let offset = 0;
129
+ for (const u8a of u8as) {
130
+ result.set(u8a, offset);
131
+ offset += u8a.length;
206
132
  }
207
133
  return result;
208
- }
209
-
210
- // ../../node_modules/@polkadot/util/is/hex.js
211
- var REGEX_HEX_PREFIXED = /^0x[\da-fA-F]+$/;
212
- function isHex(value, bitLength = -1, ignoreLength) {
213
- return typeof value === "string" && (value === "0x" || REGEX_HEX_PREFIXED.test(value)) && (bitLength === -1 ? ignoreLength || value.length % 2 === 0 : value.length === 2 + Math.ceil(bitLength / 4));
214
- }
215
-
216
- // ../../node_modules/@polkadot/util/has.js
217
- var hasBigInt = typeof BigInt2 === "function" && typeof BigInt2.asIntN === "function";
218
- var hasBuffer = typeof xglobal.Buffer === "function" && typeof xglobal.Buffer.isBuffer === "function";
219
- var hasProcess = typeof xglobal.process === "object";
220
-
221
- // ../../node_modules/@polkadot/util/is/buffer.js
222
- function isBuffer(value) {
223
- return hasBuffer && !!value && isFunction(value.readDoubleLE) && xglobal.Buffer.isBuffer(value);
224
- }
225
-
226
- // ../../node_modules/@polkadot/util/is/u8a.js
227
- function isU8a(value) {
228
- return (value && value.constructor) === Uint8Array || value instanceof Uint8Array;
229
- }
230
-
231
- // ../../node_modules/@polkadot/util/string/toU8a.js
232
- var encoder = new TextEncoder();
233
- function stringToU8a2(value) {
234
- return value ? encoder.encode(value.toString()) : new Uint8Array();
235
- }
236
-
237
- // ../../node_modules/@polkadot/util/u8a/toU8a.js
238
- function u8aToU8a(value) {
239
- return isU8a(value) ? isBuffer(value) ? new Uint8Array(value) : value : isHex(value) ? hexToU8a(value) : Array.isArray(value) ? new Uint8Array(value) : stringToU8a2(value);
240
- }
241
-
242
- // ../../node_modules/@polkadot/util/u8a/eq.js
243
- function u8aEq(a, b) {
244
- const u8aa = u8aToU8a(a);
245
- const u8ab = u8aToU8a(b);
246
- if (u8aa.length === u8ab.length) {
247
- const dvA = new DataView(u8aa.buffer, u8aa.byteOffset);
248
- const dvB = new DataView(u8ab.buffer, u8ab.byteOffset);
249
- const mod = u8aa.length % 4 | 0;
250
- const length = u8aa.length - mod | 0;
251
- for (let i = 0; i < length; i += 4) {
252
- if (dvA.getUint32(i) !== dvB.getUint32(i)) {
253
- return false;
254
- }
255
- }
256
- for (let i = length, count = u8aa.length; i < count; i++) {
257
- if (u8aa[i] !== u8ab[i]) {
258
- return false;
259
- }
260
- }
261
- return true;
262
- }
263
- return false;
264
- }
265
-
266
- // ../../node_modules/@polkadot/util/u8a/toString.js
267
- var decoder = new TextDecoder("utf-8");
268
- function u8aToString2(value) {
269
- return value ? decoder.decode(value) : "";
270
- }
271
-
272
- // ../../node_modules/@polkadot/util/u8a/wrap.js
273
- var U8A_WRAP_ETHEREUM = /* @__PURE__ */ u8aToU8a("Ethereum Signed Message:\n");
274
- var U8A_WRAP_PREFIX = /* @__PURE__ */ u8aToU8a("<Bytes>");
275
- var U8A_WRAP_POSTFIX = /* @__PURE__ */ u8aToU8a("</Bytes>");
276
- var WRAP_LEN = U8A_WRAP_PREFIX.length + U8A_WRAP_POSTFIX.length;
277
- function u8aIsWrapped(u8a, withEthereum) {
278
- return u8a.length >= WRAP_LEN && u8aEq(u8a.subarray(0, U8A_WRAP_PREFIX.length), U8A_WRAP_PREFIX) && u8aEq(u8a.slice(-U8A_WRAP_POSTFIX.length), U8A_WRAP_POSTFIX) || withEthereum && u8a.length >= U8A_WRAP_ETHEREUM.length && u8aEq(u8a.subarray(0, U8A_WRAP_ETHEREUM.length), U8A_WRAP_ETHEREUM);
279
- }
280
- function u8aUnwrapBytes(bytes) {
281
- const u8a = u8aToU8a(bytes);
282
- return u8aIsWrapped(u8a, false) ? u8a.subarray(U8A_WRAP_PREFIX.length, u8a.length - U8A_WRAP_POSTFIX.length) : u8a;
283
- }
134
+ };
284
135
 
285
136
  // src/unit.ts
286
137
  import { AccountId as AccountId2 } from "@polkadot-api/substrate-bindings";
@@ -288,7 +139,7 @@ var planckToUnit = (val, units) => {
288
139
  try {
289
140
  units = Math.max(Math.round(units), 0);
290
141
  const bigIntVal = typeof val === "bigint" ? val : BigInt(
291
- typeof val === "number" ? Math.floor(val).toString() : rmCommas(val)
142
+ typeof val === "number" ? Math.floor(val).toString() : rmDecimals(rmCommas(val))
292
143
  );
293
144
  const divisor = units === 0 ? 1n : BigInt(10) ** BigInt(units);
294
145
  const integerPart = bigIntVal / divisor;
@@ -348,18 +199,6 @@ var isValidAddress = (address) => {
348
199
  return false;
349
200
  }
350
201
  };
351
- var determinePoolDisplay = (address, batchItem) => {
352
- const defaultDisplay = ellipsisFn(address, 6);
353
- let display = batchItem ?? defaultDisplay;
354
- const displayAsBytes = u8aToString2(u8aUnwrapBytes(display));
355
- if (displayAsBytes !== "") {
356
- display = displayAsBytes;
357
- }
358
- if (display === "") {
359
- display = defaultDisplay;
360
- }
361
- return display;
362
- };
363
202
  var extractUrlValue = (key, url) => {
364
203
  if (typeof url === "undefined") {
365
204
  url = window.location.href;
@@ -499,7 +338,6 @@ export {
499
338
  applyWidthAsPadding,
500
339
  camelize,
501
340
  capitalizeFirstLetter,
502
- determinePoolDisplay,
503
341
  ellipsisFn,
504
342
  eqSet,
505
343
  extractUrlValue,
@@ -522,12 +360,12 @@ export {
522
360
  removeVarFromUrlHash,
523
361
  removedFrom,
524
362
  rmCommas,
363
+ rmDecimals,
525
364
  setStateWithRef,
526
365
  shuffle,
527
366
  snakeToCamel,
528
367
  sortWithNull,
529
- stringToU8a,
530
- u8aToString,
368
+ u8aConcat,
531
369
  unescape,
532
370
  unimplemented,
533
371
  unitToPlanck,
@@ -536,3 +374,4 @@ export {
536
374
  };
537
375
  /* @license Copyright 2024 w3ux authors & contributors
538
376
  SPDX-License-Identifier: GPL-3.0-only */
377
+ // /* @license Copyright 2024 w3ux authors & contributors
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@w3ux/utils",
3
- "version": "1.1.1-beta.1",
3
+ "version": "1.1.1-beta.11",
4
4
  "license": "GPL-3.0-only",
5
5
  "dependencies": {
6
6
  "@polkadot-api/substrate-bindings": "^0.9.3"
package/unit.cjs CHANGED
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,14 +14,6 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
18
 
29
19
  // src/unit.ts
@@ -32,7 +22,6 @@ __export(unit_exports, {
32
22
  addedTo: () => addedTo,
33
23
  applyWidthAsPadding: () => applyWidthAsPadding,
34
24
  capitalizeFirstLetter: () => capitalizeFirstLetter,
35
- determinePoolDisplay: () => determinePoolDisplay,
36
25
  extractUrlValue: () => extractUrlValue,
37
26
  inChrome: () => inChrome,
38
27
  isValidAddress: () => isValidAddress,
@@ -55,181 +44,10 @@ __export(unit_exports, {
55
44
  });
56
45
  module.exports = __toCommonJS(unit_exports);
57
46
 
58
- // ../../node_modules/@polkadot/x-textdecoder/node.js
59
- var import_node_util = __toESM(require("util"), 1);
60
-
61
- // ../../node_modules/@polkadot/x-global/index.js
62
- function evaluateThis(fn) {
63
- return fn("return this");
64
- }
65
- var xglobal = typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : evaluateThis(Function);
66
- function extractGlobal(name, fallback) {
67
- return typeof xglobal[name] === "undefined" ? fallback : xglobal[name];
68
- }
69
-
70
- // ../../node_modules/@polkadot/x-textdecoder/node.js
71
- var TextDecoder = /* @__PURE__ */ extractGlobal("TextDecoder", import_node_util.default.TextDecoder);
72
-
73
- // ../../node_modules/@polkadot/x-textencoder/node.js
74
- var import_node_util2 = __toESM(require("util"), 1);
75
- var Fallback = class {
76
- __internal__encoder;
77
- constructor() {
78
- this.__internal__encoder = new import_node_util2.default.TextEncoder();
79
- }
80
- // For a Jest 26.0.1 environment, Buffer !== Uint8Array
81
- encode(value) {
82
- return Uint8Array.from(this.__internal__encoder.encode(value));
83
- }
84
- };
85
- var TextEncoder = /* @__PURE__ */ extractGlobal("TextEncoder", Fallback);
86
-
87
- // ../../node_modules/@polkadot/util/is/function.js
88
- function isFunction(value) {
89
- return typeof value === "function";
90
- }
91
-
92
- // ../../node_modules/@polkadot/x-bigint/index.js
93
- function invalidFallback() {
94
- return Number.NaN;
95
- }
96
- var BigInt2 = /* @__PURE__ */ extractGlobal("BigInt", invalidFallback);
97
-
98
- // ../../node_modules/@polkadot/util/hex/toU8a.js
99
- var CHR = "0123456789abcdef";
100
- var U8 = new Uint8Array(256);
101
- var U16 = new Uint8Array(256 * 256);
102
- for (let i = 0, count = CHR.length; i < count; i++) {
103
- U8[CHR[i].charCodeAt(0) | 0] = i | 0;
104
- if (i > 9) {
105
- U8[CHR[i].toUpperCase().charCodeAt(0) | 0] = i | 0;
106
- }
107
- }
108
- for (let i = 0; i < 256; i++) {
109
- const s = i << 8;
110
- for (let j = 0; j < 256; j++) {
111
- U16[s | j] = U8[i] << 4 | U8[j];
112
- }
113
- }
114
- function hexToU8a(value, bitLength = -1) {
115
- if (!value) {
116
- return new Uint8Array();
117
- }
118
- let s = value.startsWith("0x") ? 2 : 0;
119
- const decLength = Math.ceil((value.length - s) / 2);
120
- const endLength = Math.ceil(bitLength === -1 ? decLength : bitLength / 8);
121
- const result = new Uint8Array(endLength);
122
- const offset = endLength > decLength ? endLength - decLength : 0;
123
- for (let i = offset; i < endLength; i++, s += 2) {
124
- result[i] = U16[value.charCodeAt(s) << 8 | value.charCodeAt(s + 1)];
125
- }
126
- return result;
127
- }
128
-
129
- // ../../node_modules/@polkadot/util/is/hex.js
130
- var REGEX_HEX_PREFIXED = /^0x[\da-fA-F]+$/;
131
- function isHex(value, bitLength = -1, ignoreLength) {
132
- return typeof value === "string" && (value === "0x" || REGEX_HEX_PREFIXED.test(value)) && (bitLength === -1 ? ignoreLength || value.length % 2 === 0 : value.length === 2 + Math.ceil(bitLength / 4));
133
- }
134
-
135
- // ../../node_modules/@polkadot/util/has.js
136
- var hasBigInt = typeof BigInt2 === "function" && typeof BigInt2.asIntN === "function";
137
- var hasBuffer = typeof xglobal.Buffer === "function" && typeof xglobal.Buffer.isBuffer === "function";
138
- var hasProcess = typeof xglobal.process === "object";
139
-
140
- // ../../node_modules/@polkadot/util/is/buffer.js
141
- function isBuffer(value) {
142
- return hasBuffer && !!value && isFunction(value.readDoubleLE) && xglobal.Buffer.isBuffer(value);
143
- }
144
-
145
- // ../../node_modules/@polkadot/util/is/u8a.js
146
- function isU8a(value) {
147
- return (value && value.constructor) === Uint8Array || value instanceof Uint8Array;
148
- }
149
-
150
- // ../../node_modules/@polkadot/util/string/toU8a.js
151
- var encoder = new TextEncoder();
152
- function stringToU8a(value) {
153
- return value ? encoder.encode(value.toString()) : new Uint8Array();
154
- }
155
-
156
- // ../../node_modules/@polkadot/util/u8a/toU8a.js
157
- function u8aToU8a(value) {
158
- return isU8a(value) ? isBuffer(value) ? new Uint8Array(value) : value : isHex(value) ? hexToU8a(value) : Array.isArray(value) ? new Uint8Array(value) : stringToU8a(value);
159
- }
160
-
161
- // ../../node_modules/@polkadot/util/u8a/eq.js
162
- function u8aEq(a, b) {
163
- const u8aa = u8aToU8a(a);
164
- const u8ab = u8aToU8a(b);
165
- if (u8aa.length === u8ab.length) {
166
- const dvA = new DataView(u8aa.buffer, u8aa.byteOffset);
167
- const dvB = new DataView(u8ab.buffer, u8ab.byteOffset);
168
- const mod = u8aa.length % 4 | 0;
169
- const length = u8aa.length - mod | 0;
170
- for (let i = 0; i < length; i += 4) {
171
- if (dvA.getUint32(i) !== dvB.getUint32(i)) {
172
- return false;
173
- }
174
- }
175
- for (let i = length, count = u8aa.length; i < count; i++) {
176
- if (u8aa[i] !== u8ab[i]) {
177
- return false;
178
- }
179
- }
180
- return true;
181
- }
182
- return false;
183
- }
184
-
185
- // ../../node_modules/@polkadot/util/u8a/toString.js
186
- var decoder = new TextDecoder("utf-8");
187
- function u8aToString(value) {
188
- return value ? decoder.decode(value) : "";
189
- }
190
-
191
- // ../../node_modules/@polkadot/util/u8a/wrap.js
192
- var U8A_WRAP_ETHEREUM = /* @__PURE__ */ u8aToU8a("Ethereum Signed Message:\n");
193
- var U8A_WRAP_PREFIX = /* @__PURE__ */ u8aToU8a("<Bytes>");
194
- var U8A_WRAP_POSTFIX = /* @__PURE__ */ u8aToU8a("</Bytes>");
195
- var WRAP_LEN = U8A_WRAP_PREFIX.length + U8A_WRAP_POSTFIX.length;
196
- function u8aIsWrapped(u8a, withEthereum) {
197
- return u8a.length >= WRAP_LEN && u8aEq(u8a.subarray(0, U8A_WRAP_PREFIX.length), U8A_WRAP_PREFIX) && u8aEq(u8a.slice(-U8A_WRAP_POSTFIX.length), U8A_WRAP_POSTFIX) || withEthereum && u8a.length >= U8A_WRAP_ETHEREUM.length && u8aEq(u8a.subarray(0, U8A_WRAP_ETHEREUM.length), U8A_WRAP_ETHEREUM);
198
- }
199
- function u8aUnwrapBytes(bytes) {
200
- const u8a = u8aToU8a(bytes);
201
- return u8aIsWrapped(u8a, false) ? u8a.subarray(U8A_WRAP_PREFIX.length, u8a.length - U8A_WRAP_POSTFIX.length) : u8a;
202
- }
203
-
204
47
  // src/base.ts
205
48
  var import_substrate_bindings = require("@polkadot-api/substrate-bindings");
206
- var ellipsisFn = (str, amount = 6, position = "center") => {
207
- const half = str.length / 2;
208
- if (amount <= 4) {
209
- if (position === "center") {
210
- return str.slice(0, 4) + "..." + str.slice(-4);
211
- }
212
- if (position === "end") {
213
- return str.slice(0, 4) + "...";
214
- }
215
- return "..." + str.slice(-4);
216
- }
217
- if (position === "center") {
218
- return amount >= (str.length - 2) / 2 ? str.slice(0, half - 3) + "..." + str.slice(-(half - 3)) : str.slice(0, amount) + "..." + str.slice(-amount);
219
- }
220
- if (amount >= str.length) {
221
- if (position === "end") {
222
- return str.slice(0, str.length - 3) + "...";
223
- }
224
- return "..." + str.slice(-(str.length - 3));
225
- } else {
226
- if (position === "end") {
227
- return str.slice(0, amount) + "...";
228
- }
229
- return "..." + str.slice(amount);
230
- }
231
- };
232
49
  var rmCommas = (val) => val.replace(/,/g, "");
50
+ var rmDecimals = (str) => str.split(".")[0];
233
51
 
234
52
  // src/unit.ts
235
53
  var import_substrate_bindings2 = require("@polkadot-api/substrate-bindings");
@@ -237,7 +55,7 @@ var planckToUnit = (val, units) => {
237
55
  try {
238
56
  units = Math.max(Math.round(units), 0);
239
57
  const bigIntVal = typeof val === "bigint" ? val : BigInt(
240
- typeof val === "number" ? Math.floor(val).toString() : rmCommas(val)
58
+ typeof val === "number" ? Math.floor(val).toString() : rmDecimals(rmCommas(val))
241
59
  );
242
60
  const divisor = units === 0 ? 1n : BigInt(10) ** BigInt(units);
243
61
  const integerPart = bigIntVal / divisor;
@@ -297,18 +115,6 @@ var isValidAddress = (address) => {
297
115
  return false;
298
116
  }
299
117
  };
300
- var determinePoolDisplay = (address, batchItem) => {
301
- const defaultDisplay = ellipsisFn(address, 6);
302
- let display = batchItem ?? defaultDisplay;
303
- const displayAsBytes = u8aToString(u8aUnwrapBytes(display));
304
- if (displayAsBytes !== "") {
305
- display = displayAsBytes;
306
- }
307
- if (display === "") {
308
- display = defaultDisplay;
309
- }
310
- return display;
311
- };
312
118
  var extractUrlValue = (key, url) => {
313
119
  if (typeof url === "undefined") {
314
120
  url = window.location.href;
@@ -446,7 +252,6 @@ var mergeDeep = (target, ...sources) => {
446
252
  addedTo,
447
253
  applyWidthAsPadding,
448
254
  capitalizeFirstLetter,
449
- determinePoolDisplay,
450
255
  extractUrlValue,
451
256
  inChrome,
452
257
  isValidAddress,
package/unit.d.cts CHANGED
@@ -57,11 +57,6 @@ declare const localStorageOrDefault: <T>(key: string, _default: T, parse?: boole
57
57
  * @summary Return whether an address is valid Substrate address.
58
58
  */
59
59
  declare const isValidAddress: (address: string) => boolean;
60
- /**
61
- * @name determinePoolDisplay
62
- * @summary A pool will be displayed with either its set metadata or its address.
63
- */
64
- declare const determinePoolDisplay: (address: string, batchItem: AnyJson) => any;
65
60
  /**
66
61
  * @name extractUrlValue
67
62
  * @summary Extracts a URL value from a URL string.
@@ -150,4 +145,4 @@ declare const unimplemented: ({ ...props }: {
150
145
  */
151
146
  declare const mergeDeep: (target: AnyObject, ...sources: AnyObject[]) => AnyObject;
152
147
 
153
- export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, determinePoolDisplay, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, unescape, unimplemented, unitToPlanck, varToUrlHash };
148
+ export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, unescape, unimplemented, unitToPlanck, varToUrlHash };
package/unit.d.ts CHANGED
@@ -57,11 +57,6 @@ declare const localStorageOrDefault: <T>(key: string, _default: T, parse?: boole
57
57
  * @summary Return whether an address is valid Substrate address.
58
58
  */
59
59
  declare const isValidAddress: (address: string) => boolean;
60
- /**
61
- * @name determinePoolDisplay
62
- * @summary A pool will be displayed with either its set metadata or its address.
63
- */
64
- declare const determinePoolDisplay: (address: string, batchItem: AnyJson) => any;
65
60
  /**
66
61
  * @name extractUrlValue
67
62
  * @summary Extracts a URL value from a URL string.
@@ -150,4 +145,4 @@ declare const unimplemented: ({ ...props }: {
150
145
  */
151
146
  declare const mergeDeep: (target: AnyObject, ...sources: AnyObject[]) => AnyObject;
152
147
 
153
- export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, determinePoolDisplay, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, unescape, unimplemented, unitToPlanck, varToUrlHash };
148
+ export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, unescape, unimplemented, unitToPlanck, varToUrlHash };
package/unit.js CHANGED
@@ -1,178 +1,7 @@
1
- // ../../node_modules/@polkadot/x-textdecoder/node.js
2
- import util from "node:util";
3
-
4
- // ../../node_modules/@polkadot/x-global/index.js
5
- function evaluateThis(fn) {
6
- return fn("return this");
7
- }
8
- var xglobal = typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : evaluateThis(Function);
9
- function extractGlobal(name, fallback) {
10
- return typeof xglobal[name] === "undefined" ? fallback : xglobal[name];
11
- }
12
-
13
- // ../../node_modules/@polkadot/x-textdecoder/node.js
14
- var TextDecoder = /* @__PURE__ */ extractGlobal("TextDecoder", util.TextDecoder);
15
-
16
- // ../../node_modules/@polkadot/x-textencoder/node.js
17
- import util2 from "node:util";
18
- var Fallback = class {
19
- __internal__encoder;
20
- constructor() {
21
- this.__internal__encoder = new util2.TextEncoder();
22
- }
23
- // For a Jest 26.0.1 environment, Buffer !== Uint8Array
24
- encode(value) {
25
- return Uint8Array.from(this.__internal__encoder.encode(value));
26
- }
27
- };
28
- var TextEncoder = /* @__PURE__ */ extractGlobal("TextEncoder", Fallback);
29
-
30
- // ../../node_modules/@polkadot/util/is/function.js
31
- function isFunction(value) {
32
- return typeof value === "function";
33
- }
34
-
35
- // ../../node_modules/@polkadot/x-bigint/index.js
36
- function invalidFallback() {
37
- return Number.NaN;
38
- }
39
- var BigInt2 = /* @__PURE__ */ extractGlobal("BigInt", invalidFallback);
40
-
41
- // ../../node_modules/@polkadot/util/hex/toU8a.js
42
- var CHR = "0123456789abcdef";
43
- var U8 = new Uint8Array(256);
44
- var U16 = new Uint8Array(256 * 256);
45
- for (let i = 0, count = CHR.length; i < count; i++) {
46
- U8[CHR[i].charCodeAt(0) | 0] = i | 0;
47
- if (i > 9) {
48
- U8[CHR[i].toUpperCase().charCodeAt(0) | 0] = i | 0;
49
- }
50
- }
51
- for (let i = 0; i < 256; i++) {
52
- const s = i << 8;
53
- for (let j = 0; j < 256; j++) {
54
- U16[s | j] = U8[i] << 4 | U8[j];
55
- }
56
- }
57
- function hexToU8a(value, bitLength = -1) {
58
- if (!value) {
59
- return new Uint8Array();
60
- }
61
- let s = value.startsWith("0x") ? 2 : 0;
62
- const decLength = Math.ceil((value.length - s) / 2);
63
- const endLength = Math.ceil(bitLength === -1 ? decLength : bitLength / 8);
64
- const result = new Uint8Array(endLength);
65
- const offset = endLength > decLength ? endLength - decLength : 0;
66
- for (let i = offset; i < endLength; i++, s += 2) {
67
- result[i] = U16[value.charCodeAt(s) << 8 | value.charCodeAt(s + 1)];
68
- }
69
- return result;
70
- }
71
-
72
- // ../../node_modules/@polkadot/util/is/hex.js
73
- var REGEX_HEX_PREFIXED = /^0x[\da-fA-F]+$/;
74
- function isHex(value, bitLength = -1, ignoreLength) {
75
- return typeof value === "string" && (value === "0x" || REGEX_HEX_PREFIXED.test(value)) && (bitLength === -1 ? ignoreLength || value.length % 2 === 0 : value.length === 2 + Math.ceil(bitLength / 4));
76
- }
77
-
78
- // ../../node_modules/@polkadot/util/has.js
79
- var hasBigInt = typeof BigInt2 === "function" && typeof BigInt2.asIntN === "function";
80
- var hasBuffer = typeof xglobal.Buffer === "function" && typeof xglobal.Buffer.isBuffer === "function";
81
- var hasProcess = typeof xglobal.process === "object";
82
-
83
- // ../../node_modules/@polkadot/util/is/buffer.js
84
- function isBuffer(value) {
85
- return hasBuffer && !!value && isFunction(value.readDoubleLE) && xglobal.Buffer.isBuffer(value);
86
- }
87
-
88
- // ../../node_modules/@polkadot/util/is/u8a.js
89
- function isU8a(value) {
90
- return (value && value.constructor) === Uint8Array || value instanceof Uint8Array;
91
- }
92
-
93
- // ../../node_modules/@polkadot/util/string/toU8a.js
94
- var encoder = new TextEncoder();
95
- function stringToU8a(value) {
96
- return value ? encoder.encode(value.toString()) : new Uint8Array();
97
- }
98
-
99
- // ../../node_modules/@polkadot/util/u8a/toU8a.js
100
- function u8aToU8a(value) {
101
- return isU8a(value) ? isBuffer(value) ? new Uint8Array(value) : value : isHex(value) ? hexToU8a(value) : Array.isArray(value) ? new Uint8Array(value) : stringToU8a(value);
102
- }
103
-
104
- // ../../node_modules/@polkadot/util/u8a/eq.js
105
- function u8aEq(a, b) {
106
- const u8aa = u8aToU8a(a);
107
- const u8ab = u8aToU8a(b);
108
- if (u8aa.length === u8ab.length) {
109
- const dvA = new DataView(u8aa.buffer, u8aa.byteOffset);
110
- const dvB = new DataView(u8ab.buffer, u8ab.byteOffset);
111
- const mod = u8aa.length % 4 | 0;
112
- const length = u8aa.length - mod | 0;
113
- for (let i = 0; i < length; i += 4) {
114
- if (dvA.getUint32(i) !== dvB.getUint32(i)) {
115
- return false;
116
- }
117
- }
118
- for (let i = length, count = u8aa.length; i < count; i++) {
119
- if (u8aa[i] !== u8ab[i]) {
120
- return false;
121
- }
122
- }
123
- return true;
124
- }
125
- return false;
126
- }
127
-
128
- // ../../node_modules/@polkadot/util/u8a/toString.js
129
- var decoder = new TextDecoder("utf-8");
130
- function u8aToString(value) {
131
- return value ? decoder.decode(value) : "";
132
- }
133
-
134
- // ../../node_modules/@polkadot/util/u8a/wrap.js
135
- var U8A_WRAP_ETHEREUM = /* @__PURE__ */ u8aToU8a("Ethereum Signed Message:\n");
136
- var U8A_WRAP_PREFIX = /* @__PURE__ */ u8aToU8a("<Bytes>");
137
- var U8A_WRAP_POSTFIX = /* @__PURE__ */ u8aToU8a("</Bytes>");
138
- var WRAP_LEN = U8A_WRAP_PREFIX.length + U8A_WRAP_POSTFIX.length;
139
- function u8aIsWrapped(u8a, withEthereum) {
140
- return u8a.length >= WRAP_LEN && u8aEq(u8a.subarray(0, U8A_WRAP_PREFIX.length), U8A_WRAP_PREFIX) && u8aEq(u8a.slice(-U8A_WRAP_POSTFIX.length), U8A_WRAP_POSTFIX) || withEthereum && u8a.length >= U8A_WRAP_ETHEREUM.length && u8aEq(u8a.subarray(0, U8A_WRAP_ETHEREUM.length), U8A_WRAP_ETHEREUM);
141
- }
142
- function u8aUnwrapBytes(bytes) {
143
- const u8a = u8aToU8a(bytes);
144
- return u8aIsWrapped(u8a, false) ? u8a.subarray(U8A_WRAP_PREFIX.length, u8a.length - U8A_WRAP_POSTFIX.length) : u8a;
145
- }
146
-
147
1
  // src/base.ts
148
2
  import { AccountId } from "@polkadot-api/substrate-bindings";
149
- var ellipsisFn = (str, amount = 6, position = "center") => {
150
- const half = str.length / 2;
151
- if (amount <= 4) {
152
- if (position === "center") {
153
- return str.slice(0, 4) + "..." + str.slice(-4);
154
- }
155
- if (position === "end") {
156
- return str.slice(0, 4) + "...";
157
- }
158
- return "..." + str.slice(-4);
159
- }
160
- if (position === "center") {
161
- return amount >= (str.length - 2) / 2 ? str.slice(0, half - 3) + "..." + str.slice(-(half - 3)) : str.slice(0, amount) + "..." + str.slice(-amount);
162
- }
163
- if (amount >= str.length) {
164
- if (position === "end") {
165
- return str.slice(0, str.length - 3) + "...";
166
- }
167
- return "..." + str.slice(-(str.length - 3));
168
- } else {
169
- if (position === "end") {
170
- return str.slice(0, amount) + "...";
171
- }
172
- return "..." + str.slice(amount);
173
- }
174
- };
175
3
  var rmCommas = (val) => val.replace(/,/g, "");
4
+ var rmDecimals = (str) => str.split(".")[0];
176
5
 
177
6
  // src/unit.ts
178
7
  import { AccountId as AccountId2 } from "@polkadot-api/substrate-bindings";
@@ -180,7 +9,7 @@ var planckToUnit = (val, units) => {
180
9
  try {
181
10
  units = Math.max(Math.round(units), 0);
182
11
  const bigIntVal = typeof val === "bigint" ? val : BigInt(
183
- typeof val === "number" ? Math.floor(val).toString() : rmCommas(val)
12
+ typeof val === "number" ? Math.floor(val).toString() : rmDecimals(rmCommas(val))
184
13
  );
185
14
  const divisor = units === 0 ? 1n : BigInt(10) ** BigInt(units);
186
15
  const integerPart = bigIntVal / divisor;
@@ -240,18 +69,6 @@ var isValidAddress = (address) => {
240
69
  return false;
241
70
  }
242
71
  };
243
- var determinePoolDisplay = (address, batchItem) => {
244
- const defaultDisplay = ellipsisFn(address, 6);
245
- let display = batchItem ?? defaultDisplay;
246
- const displayAsBytes = u8aToString(u8aUnwrapBytes(display));
247
- if (displayAsBytes !== "") {
248
- display = displayAsBytes;
249
- }
250
- if (display === "") {
251
- display = defaultDisplay;
252
- }
253
- return display;
254
- };
255
72
  var extractUrlValue = (key, url) => {
256
73
  if (typeof url === "undefined") {
257
74
  url = window.location.href;
@@ -388,7 +205,6 @@ export {
388
205
  addedTo,
389
206
  applyWidthAsPadding,
390
207
  capitalizeFirstLetter,
391
- determinePoolDisplay,
392
208
  extractUrlValue,
393
209
  inChrome,
394
210
  isValidAddress,
package/conversions.d.cts DELETED
@@ -1,18 +0,0 @@
1
- /**
2
- * Converts a string to a Uint8Array.
3
- *
4
- * @function stringToU8a
5
- * @param {string} input - The string to convert.
6
- * @returns {Uint8Array} The resulting Uint8Array.
7
- */
8
- declare const stringToU8a: (input: string) => Uint8Array;
9
- /**
10
- * Converts a Uint8Array to a string.
11
- *
12
- * @function u8aToString
13
- * @param {Uint8Array} u8a - The Uint8Array to convert.
14
- * @returns {string} The resulting string.
15
- */
16
- declare const u8aToString: (u8a: Uint8Array) => string;
17
-
18
- export { stringToU8a, u8aToString };
package/conversions.d.ts DELETED
@@ -1,18 +0,0 @@
1
- /**
2
- * Converts a string to a Uint8Array.
3
- *
4
- * @function stringToU8a
5
- * @param {string} input - The string to convert.
6
- * @returns {Uint8Array} The resulting Uint8Array.
7
- */
8
- declare const stringToU8a: (input: string) => Uint8Array;
9
- /**
10
- * Converts a Uint8Array to a string.
11
- *
12
- * @function u8aToString
13
- * @param {Uint8Array} u8a - The Uint8Array to convert.
14
- * @returns {string} The resulting string.
15
- */
16
- declare const u8aToString: (u8a: Uint8Array) => string;
17
-
18
- export { stringToU8a, u8aToString };
package/conversions.js DELETED
@@ -1,21 +0,0 @@
1
- // src/conversions.ts
2
- var stringToU8a = (input) => {
3
- const u8a = new Uint8Array(input.length);
4
- for (let i = 0; i < input.length; i++) {
5
- u8a[i] = input.charCodeAt(i);
6
- }
7
- return u8a;
8
- };
9
- var u8aToString = (u8a) => {
10
- const chars = new Array(u8a.length);
11
- for (let i = 0; i < u8a.length; i++) {
12
- chars[i] = String.fromCharCode(u8a[i]);
13
- }
14
- return chars.join("");
15
- };
16
- export {
17
- stringToU8a,
18
- u8aToString
19
- };
20
- /* @license Copyright 2024 w3ux authors & contributors
21
- SPDX-License-Identifier: GPL-3.0-only */