@w3ux/utils 0.10.0 → 0.10.1-alpha.1

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
@@ -25,8 +25,6 @@ __export(base_exports, {
25
25
  ellipsisFn: () => ellipsisFn,
26
26
  eqSet: () => eqSet,
27
27
  formatAccountSs58: () => formatAccountSs58,
28
- greaterThanZero: () => greaterThanZero,
29
- isNotZero: () => isNotZero,
30
28
  isSuperset: () => isSuperset,
31
29
  minDecimalPlaces: () => minDecimalPlaces,
32
30
  pageFromUri: () => pageFromUri,
@@ -36,7 +34,6 @@ __export(base_exports, {
36
34
  withTimeout: () => withTimeout
37
35
  });
38
36
  module.exports = __toCommonJS(base_exports);
39
- var import_bignumber = require("bignumber.js");
40
37
  var import_substrate_bindings = require("@polkadot-api/substrate-bindings");
41
38
  var camelize = (str) => {
42
39
  const convertToString = (string) => {
@@ -92,15 +89,15 @@ var ellipsisFn = (str, amount = 6, position = "center") => {
92
89
  return "..." + str.slice(amount);
93
90
  }
94
91
  };
95
- var greaterThanZero = (val) => val.isGreaterThan(0);
96
- var isNotZero = (val) => !val.isZero();
97
92
  var minDecimalPlaces = (val, minDecimals) => {
98
- const whole = new import_bignumber.BigNumber(rmCommas(val).split(".")[0] || 0);
99
- const decimals = val.split(".")[1] || "";
100
- const missingDecimals = new import_bignumber.BigNumber(minDecimals).minus(decimals.length);
101
- return missingDecimals.isGreaterThan(0) ? `${whole.toFormat(0)}.${decimals.toString()}${"0".repeat(
102
- missingDecimals.toNumber()
103
- )}` : val;
93
+ try {
94
+ const whole = BigInt(rmCommas(val).split(".")[0] || "0");
95
+ const decimals = val.split(".")[1] || "";
96
+ const missingDecimals = minDecimals - decimals.length;
97
+ return missingDecimals > 0 ? `${whole.toString()}.${decimals}${"0".repeat(missingDecimals)}` : val;
98
+ } catch (e) {
99
+ return "0";
100
+ }
104
101
  };
105
102
  var pageFromUri = (pathname, fallback) => {
106
103
  const lastUriItem = pathname.substring(pathname.lastIndexOf("/") + 1);
@@ -160,8 +157,6 @@ var isSuperset = (set, subset) => {
160
157
  ellipsisFn,
161
158
  eqSet,
162
159
  formatAccountSs58,
163
- greaterThanZero,
164
- isNotZero,
165
160
  isSuperset,
166
161
  minDecimalPlaces,
167
162
  pageFromUri,
package/base.d.cts CHANGED
@@ -1,4 +1,3 @@
1
- import { BigNumber } from 'bignumber.js';
2
1
  import { AnyFunction } from '@w3ux/types';
3
2
 
4
3
  /**
@@ -15,16 +14,6 @@ declare const camelize: (str: string) => string;
15
14
  * same for beginning and end; if "start" or "end" then its only once the amount; defaults to "start"
16
15
  */
17
16
  declare const ellipsisFn: (str: string, amount?: number, position?: "start" | "end" | "center") => string;
18
- /**
19
- * @name greaterThanZero
20
- * @summary Returns whether a BigNumber is greater than zero.
21
- */
22
- declare const greaterThanZero: (val: BigNumber) => boolean;
23
- /**
24
- * @name isNotZero
25
- * @summary Returns whether a BigNumber is zero.
26
- */
27
- declare const isNotZero: (val: BigNumber) => boolean;
28
17
  /**
29
18
  * @name minDecimalPlaces
30
19
  * @summary Forces a number to have at least the provided decimal places.
@@ -76,4 +65,4 @@ declare const removeHexPrefix: (str: string) => string;
76
65
  declare const eqSet: (xs: Set<any>, ys: Set<any>) => boolean;
77
66
  declare const isSuperset: (set: Set<any>, subset: Set<any>) => boolean;
78
67
 
79
- export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, greaterThanZero, isNotZero, isSuperset, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout };
68
+ export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout };
package/base.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { BigNumber } from 'bignumber.js';
2
1
  import { AnyFunction } from '@w3ux/types';
3
2
 
4
3
  /**
@@ -15,16 +14,6 @@ declare const camelize: (str: string) => string;
15
14
  * same for beginning and end; if "start" or "end" then its only once the amount; defaults to "start"
16
15
  */
17
16
  declare const ellipsisFn: (str: string, amount?: number, position?: "start" | "end" | "center") => string;
18
- /**
19
- * @name greaterThanZero
20
- * @summary Returns whether a BigNumber is greater than zero.
21
- */
22
- declare const greaterThanZero: (val: BigNumber) => boolean;
23
- /**
24
- * @name isNotZero
25
- * @summary Returns whether a BigNumber is zero.
26
- */
27
- declare const isNotZero: (val: BigNumber) => boolean;
28
17
  /**
29
18
  * @name minDecimalPlaces
30
19
  * @summary Forces a number to have at least the provided decimal places.
@@ -76,4 +65,4 @@ declare const removeHexPrefix: (str: string) => string;
76
65
  declare const eqSet: (xs: Set<any>, ys: Set<any>) => boolean;
77
66
  declare const isSuperset: (set: Set<any>, subset: Set<any>) => boolean;
78
67
 
79
- export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, greaterThanZero, isNotZero, isSuperset, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout };
68
+ export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout };
package/base.js CHANGED
@@ -1,5 +1,4 @@
1
1
  // src/base.ts
2
- import { BigNumber } from "bignumber.js";
3
2
  import { AccountId } from "@polkadot-api/substrate-bindings";
4
3
  var camelize = (str) => {
5
4
  const convertToString = (string) => {
@@ -55,15 +54,15 @@ var ellipsisFn = (str, amount = 6, position = "center") => {
55
54
  return "..." + str.slice(amount);
56
55
  }
57
56
  };
58
- var greaterThanZero = (val) => val.isGreaterThan(0);
59
- var isNotZero = (val) => !val.isZero();
60
57
  var minDecimalPlaces = (val, minDecimals) => {
61
- const whole = new BigNumber(rmCommas(val).split(".")[0] || 0);
62
- const decimals = val.split(".")[1] || "";
63
- const missingDecimals = new BigNumber(minDecimals).minus(decimals.length);
64
- return missingDecimals.isGreaterThan(0) ? `${whole.toFormat(0)}.${decimals.toString()}${"0".repeat(
65
- missingDecimals.toNumber()
66
- )}` : val;
58
+ try {
59
+ const whole = BigInt(rmCommas(val).split(".")[0] || "0");
60
+ const decimals = val.split(".")[1] || "";
61
+ const missingDecimals = minDecimals - decimals.length;
62
+ return missingDecimals > 0 ? `${whole.toString()}.${decimals}${"0".repeat(missingDecimals)}` : val;
63
+ } catch (e) {
64
+ return "0";
65
+ }
67
66
  };
68
67
  var pageFromUri = (pathname, fallback) => {
69
68
  const lastUriItem = pathname.substring(pathname.lastIndexOf("/") + 1);
@@ -122,8 +121,6 @@ export {
122
121
  ellipsisFn,
123
122
  eqSet,
124
123
  formatAccountSs58,
125
- greaterThanZero,
126
- isNotZero,
127
124
  isSuperset,
128
125
  minDecimalPlaces,
129
126
  pageFromUri,
package/index.cjs CHANGED
@@ -41,9 +41,7 @@ __export(src_exports, {
41
41
  evalUnits: () => evalUnits,
42
42
  extractUrlValue: () => extractUrlValue,
43
43
  formatAccountSs58: () => formatAccountSs58,
44
- greaterThanZero: () => greaterThanZero,
45
44
  inChrome: () => inChrome,
46
- isNotZero: () => isNotZero,
47
45
  isSuperset: () => isSuperset,
48
46
  isValidAddress: () => isValidAddress,
49
47
  isValidHttpUrl: () => isValidHttpUrl,
@@ -74,7 +72,6 @@ __export(src_exports, {
74
72
  module.exports = __toCommonJS(src_exports);
75
73
 
76
74
  // src/base.ts
77
- var import_bignumber = require("bignumber.js");
78
75
  var import_substrate_bindings = require("@polkadot-api/substrate-bindings");
79
76
  var camelize = (str) => {
80
77
  const convertToString = (string) => {
@@ -130,15 +127,15 @@ var ellipsisFn = (str, amount = 6, position = "center") => {
130
127
  return "..." + str.slice(amount);
131
128
  }
132
129
  };
133
- var greaterThanZero = (val) => val.isGreaterThan(0);
134
- var isNotZero = (val) => !val.isZero();
135
130
  var minDecimalPlaces = (val, minDecimals) => {
136
- const whole = new import_bignumber.BigNumber(rmCommas(val).split(".")[0] || 0);
137
- const decimals = val.split(".")[1] || "";
138
- const missingDecimals = new import_bignumber.BigNumber(minDecimals).minus(decimals.length);
139
- return missingDecimals.isGreaterThan(0) ? `${whole.toFormat(0)}.${decimals.toString()}${"0".repeat(
140
- missingDecimals.toNumber()
141
- )}` : val;
131
+ try {
132
+ const whole = BigInt(rmCommas(val).split(".")[0] || "0");
133
+ const decimals = val.split(".")[1] || "";
134
+ const missingDecimals = minDecimals - decimals.length;
135
+ return missingDecimals > 0 ? `${whole.toString()}.${decimals}${"0".repeat(missingDecimals)}` : val;
136
+ } catch (e) {
137
+ return "0";
138
+ }
142
139
  };
143
140
  var pageFromUri = (pathname, fallback) => {
144
141
  const lastUriItem = pathname.substring(pathname.lastIndexOf("/") + 1);
@@ -229,7 +226,7 @@ function isFunction(value) {
229
226
  function invalidFallback() {
230
227
  return Number.NaN;
231
228
  }
232
- var BigInt = /* @__PURE__ */ extractGlobal("BigInt", invalidFallback);
229
+ var BigInt2 = /* @__PURE__ */ extractGlobal("BigInt", invalidFallback);
233
230
 
234
231
  // ../../node_modules/@polkadot/util/hex/toU8a.js
235
232
  var CHR = "0123456789abcdef";
@@ -269,7 +266,7 @@ function isHex(value, bitLength = -1, ignoreLength) {
269
266
  }
270
267
 
271
268
  // ../../node_modules/@polkadot/util/has.js
272
- var hasBigInt = typeof BigInt === "function" && typeof BigInt.asIntN === "function";
269
+ var hasBigInt = typeof BigInt2 === "function" && typeof BigInt2.asIntN === "function";
273
270
  var hasBuffer = typeof xglobal.Buffer === "function" && typeof xglobal.Buffer.isBuffer === "function";
274
271
  var hasProcess = typeof xglobal.process === "object";
275
272
 
@@ -338,15 +335,15 @@ function u8aUnwrapBytes(bytes) {
338
335
  }
339
336
 
340
337
  // src/unit.ts
341
- var import_bignumber2 = require("bignumber.js");
338
+ var import_bignumber = require("bignumber.js");
342
339
  var import_substrate_bindings2 = require("@polkadot-api/substrate-bindings");
343
340
  var remToUnit = (rem) => Number(rem.slice(0, rem.length - 3)) * parseFloat(getComputedStyle(document.documentElement).fontSize);
344
- var planckToUnit = (val, units) => new import_bignumber2.BigNumber(
345
- val.dividedBy(new import_bignumber2.BigNumber(10).exponentiatedBy(units)).toFixed(units)
341
+ var planckToUnit = (val, units) => new import_bignumber.BigNumber(
342
+ val.dividedBy(new import_bignumber.BigNumber(10).exponentiatedBy(units)).toFixed(units)
346
343
  );
347
344
  var unitToPlanck = (val, units) => {
348
- const init = new import_bignumber2.BigNumber(!val.length || !val ? "0" : val);
349
- return (!init.isNaN() ? init : new import_bignumber2.BigNumber(0)).multipliedBy(new import_bignumber2.BigNumber(10).exponentiatedBy(units)).integerValue();
345
+ const init = new import_bignumber.BigNumber(!val.length || !val ? "0" : val);
346
+ return (!init.isNaN() ? init : new import_bignumber.BigNumber(0)).multipliedBy(new import_bignumber.BigNumber(10).exponentiatedBy(units)).integerValue();
350
347
  };
351
348
  var capitalizeFirstLetter = (string) => string.charAt(0).toUpperCase() + string.slice(1);
352
349
  var snakeToCamel = (str) => str.toLowerCase().replace(
@@ -498,7 +495,7 @@ var makeCancelable = (promise) => {
498
495
  }
499
496
  };
500
497
  };
501
- var getSiValue = (si2) => new import_bignumber2.BigNumber(10).pow(new import_bignumber2.BigNumber(si2));
498
+ var getSiValue = (si2) => new import_bignumber.BigNumber(10).pow(new import_bignumber.BigNumber(si2));
502
499
  var si = [
503
500
  { value: getSiValue(24), symbol: "y", isMil: true },
504
501
  { value: getSiValue(21), symbol: "z", isMil: true },
@@ -508,7 +505,7 @@ var si = [
508
505
  { value: getSiValue(9), symbol: "n", isMil: true },
509
506
  { value: getSiValue(6), symbol: "\u03BC", isMil: true },
510
507
  { value: getSiValue(3), symbol: "m", isMil: true },
511
- { value: new import_bignumber2.BigNumber(1), symbol: "" },
508
+ { value: new import_bignumber.BigNumber(1), symbol: "" },
512
509
  { value: getSiValue(3), symbol: "k" },
513
510
  { value: getSiValue(6), symbol: "M" },
514
511
  { value: getSiValue(9), symbol: "G" },
@@ -533,25 +530,25 @@ var evalUnits = (input, chainDecimals) => {
533
530
  const symbol = input.replace(/[0-9.,]/g, "");
534
531
  const siVal = si.find((s) => s.symbol === symbol);
535
532
  const numberStr = input.replace(symbol, "").replace(",", ".");
536
- let numeric = new import_bignumber2.BigNumber(0);
533
+ let numeric = new import_bignumber.BigNumber(0);
537
534
  if (!siVal) {
538
535
  return [null, "Provided symbol is not correct" /* SYMBOL_ERROR */];
539
536
  }
540
- const decimalsBn = new import_bignumber2.BigNumber(10).pow(new import_bignumber2.BigNumber(chainDecimals));
537
+ const decimalsBn = new import_bignumber.BigNumber(10).pow(new import_bignumber.BigNumber(chainDecimals));
541
538
  const containDecimal = numberStr.includes(".");
542
539
  const [decPart, fracPart] = numberStr.split(".");
543
540
  const fracDecimals = fracPart?.length || 0;
544
- const fracExp = new import_bignumber2.BigNumber(10).pow(new import_bignumber2.BigNumber(fracDecimals));
545
- numeric = containDecimal ? new import_bignumber2.BigNumber(
546
- new import_bignumber2.BigNumber(decPart).multipliedBy(fracExp).plus(new import_bignumber2.BigNumber(fracPart))
547
- ) : new import_bignumber2.BigNumber(new import_bignumber2.BigNumber(numberStr));
541
+ const fracExp = new import_bignumber.BigNumber(10).pow(new import_bignumber.BigNumber(fracDecimals));
542
+ numeric = containDecimal ? new import_bignumber.BigNumber(
543
+ new import_bignumber.BigNumber(decPart).multipliedBy(fracExp).plus(new import_bignumber.BigNumber(fracPart))
544
+ ) : new import_bignumber.BigNumber(new import_bignumber.BigNumber(numberStr));
548
545
  numeric = numeric.multipliedBy(decimalsBn);
549
546
  if (containDecimal) {
550
547
  numeric = siVal.isMil ? numeric.dividedBy(siVal.value).dividedBy(fracExp) : numeric.multipliedBy(siVal.value).dividedBy(fracExp);
551
548
  } else {
552
549
  numeric = siVal.isMil ? numeric.dividedBy(siVal.value) : numeric.multipliedBy(siVal.value);
553
550
  }
554
- if (numeric.eq(new import_bignumber2.BigNumber(0))) {
551
+ if (numeric.eq(new import_bignumber.BigNumber(0))) {
555
552
  return [null, "You cannot send 0 funds" /* ZERO */];
556
553
  }
557
554
  return [numeric, "" /* SUCCESS */];
@@ -598,7 +595,7 @@ var mergeDeep = (target, ...sources) => {
598
595
  }
599
596
  return mergeDeep(target, ...sources);
600
597
  };
601
- var stringToBigNumber = (value) => new import_bignumber2.BigNumber(rmCommas(value));
598
+ var stringToBigNumber = (value) => new import_bignumber.BigNumber(rmCommas(value));
602
599
  // Annotate the CommonJS export names for ESM import in node:
603
600
  0 && (module.exports = {
604
601
  addedTo,
@@ -613,9 +610,7 @@ var stringToBigNumber = (value) => new import_bignumber2.BigNumber(rmCommas(valu
613
610
  evalUnits,
614
611
  extractUrlValue,
615
612
  formatAccountSs58,
616
- greaterThanZero,
617
613
  inChrome,
618
- isNotZero,
619
614
  isSuperset,
620
615
  isValidAddress,
621
616
  isValidHttpUrl,
package/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, greaterThanZero, isNotZero, isSuperset, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout } from './base.cjs';
1
+ export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout } from './base.cjs';
2
2
  export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, determinePoolDisplay, evalUnits, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, stringToBigNumber, transformToBaseUnit, unescape, unimplemented, unitToPlanck, varToUrlHash } from './unit.cjs';
3
- import 'bignumber.js';
4
3
  import '@w3ux/types';
4
+ import 'bignumber.js';
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, greaterThanZero, isNotZero, isSuperset, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout } from './base.js';
1
+ export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout } from './base.js';
2
2
  export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, determinePoolDisplay, evalUnits, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, stringToBigNumber, transformToBaseUnit, unescape, unimplemented, unitToPlanck, varToUrlHash } from './unit.js';
3
- import 'bignumber.js';
4
3
  import '@w3ux/types';
4
+ import 'bignumber.js';
5
5
  import 'react';
6
6
  import './types.js';
package/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  // src/base.ts
2
- import { BigNumber } from "bignumber.js";
3
2
  import { AccountId } from "@polkadot-api/substrate-bindings";
4
3
  var camelize = (str) => {
5
4
  const convertToString = (string) => {
@@ -55,15 +54,15 @@ var ellipsisFn = (str, amount = 6, position = "center") => {
55
54
  return "..." + str.slice(amount);
56
55
  }
57
56
  };
58
- var greaterThanZero = (val) => val.isGreaterThan(0);
59
- var isNotZero = (val) => !val.isZero();
60
57
  var minDecimalPlaces = (val, minDecimals) => {
61
- const whole = new BigNumber(rmCommas(val).split(".")[0] || 0);
62
- const decimals = val.split(".")[1] || "";
63
- const missingDecimals = new BigNumber(minDecimals).minus(decimals.length);
64
- return missingDecimals.isGreaterThan(0) ? `${whole.toFormat(0)}.${decimals.toString()}${"0".repeat(
65
- missingDecimals.toNumber()
66
- )}` : val;
58
+ try {
59
+ const whole = BigInt(rmCommas(val).split(".")[0] || "0");
60
+ const decimals = val.split(".")[1] || "";
61
+ const missingDecimals = minDecimals - decimals.length;
62
+ return missingDecimals > 0 ? `${whole.toString()}.${decimals}${"0".repeat(missingDecimals)}` : val;
63
+ } catch (e) {
64
+ return "0";
65
+ }
67
66
  };
68
67
  var pageFromUri = (pathname, fallback) => {
69
68
  const lastUriItem = pathname.substring(pathname.lastIndexOf("/") + 1);
@@ -154,7 +153,7 @@ function isFunction(value) {
154
153
  function invalidFallback() {
155
154
  return Number.NaN;
156
155
  }
157
- var BigInt = /* @__PURE__ */ extractGlobal("BigInt", invalidFallback);
156
+ var BigInt2 = /* @__PURE__ */ extractGlobal("BigInt", invalidFallback);
158
157
 
159
158
  // ../../node_modules/@polkadot/util/hex/toU8a.js
160
159
  var CHR = "0123456789abcdef";
@@ -194,7 +193,7 @@ function isHex(value, bitLength = -1, ignoreLength) {
194
193
  }
195
194
 
196
195
  // ../../node_modules/@polkadot/util/has.js
197
- var hasBigInt = typeof BigInt === "function" && typeof BigInt.asIntN === "function";
196
+ var hasBigInt = typeof BigInt2 === "function" && typeof BigInt2.asIntN === "function";
198
197
  var hasBuffer = typeof xglobal.Buffer === "function" && typeof xglobal.Buffer.isBuffer === "function";
199
198
  var hasProcess = typeof xglobal.process === "object";
200
199
 
@@ -263,15 +262,15 @@ function u8aUnwrapBytes(bytes) {
263
262
  }
264
263
 
265
264
  // src/unit.ts
266
- import { BigNumber as BigNumber2 } from "bignumber.js";
265
+ import { BigNumber } from "bignumber.js";
267
266
  import { AccountId as AccountId2 } from "@polkadot-api/substrate-bindings";
268
267
  var remToUnit = (rem) => Number(rem.slice(0, rem.length - 3)) * parseFloat(getComputedStyle(document.documentElement).fontSize);
269
- var planckToUnit = (val, units) => new BigNumber2(
270
- val.dividedBy(new BigNumber2(10).exponentiatedBy(units)).toFixed(units)
268
+ var planckToUnit = (val, units) => new BigNumber(
269
+ val.dividedBy(new BigNumber(10).exponentiatedBy(units)).toFixed(units)
271
270
  );
272
271
  var unitToPlanck = (val, units) => {
273
- const init = new BigNumber2(!val.length || !val ? "0" : val);
274
- return (!init.isNaN() ? init : new BigNumber2(0)).multipliedBy(new BigNumber2(10).exponentiatedBy(units)).integerValue();
272
+ const init = new BigNumber(!val.length || !val ? "0" : val);
273
+ return (!init.isNaN() ? init : new BigNumber(0)).multipliedBy(new BigNumber(10).exponentiatedBy(units)).integerValue();
275
274
  };
276
275
  var capitalizeFirstLetter = (string) => string.charAt(0).toUpperCase() + string.slice(1);
277
276
  var snakeToCamel = (str) => str.toLowerCase().replace(
@@ -423,7 +422,7 @@ var makeCancelable = (promise) => {
423
422
  }
424
423
  };
425
424
  };
426
- var getSiValue = (si2) => new BigNumber2(10).pow(new BigNumber2(si2));
425
+ var getSiValue = (si2) => new BigNumber(10).pow(new BigNumber(si2));
427
426
  var si = [
428
427
  { value: getSiValue(24), symbol: "y", isMil: true },
429
428
  { value: getSiValue(21), symbol: "z", isMil: true },
@@ -433,7 +432,7 @@ var si = [
433
432
  { value: getSiValue(9), symbol: "n", isMil: true },
434
433
  { value: getSiValue(6), symbol: "\u03BC", isMil: true },
435
434
  { value: getSiValue(3), symbol: "m", isMil: true },
436
- { value: new BigNumber2(1), symbol: "" },
435
+ { value: new BigNumber(1), symbol: "" },
437
436
  { value: getSiValue(3), symbol: "k" },
438
437
  { value: getSiValue(6), symbol: "M" },
439
438
  { value: getSiValue(9), symbol: "G" },
@@ -458,25 +457,25 @@ var evalUnits = (input, chainDecimals) => {
458
457
  const symbol = input.replace(/[0-9.,]/g, "");
459
458
  const siVal = si.find((s) => s.symbol === symbol);
460
459
  const numberStr = input.replace(symbol, "").replace(",", ".");
461
- let numeric = new BigNumber2(0);
460
+ let numeric = new BigNumber(0);
462
461
  if (!siVal) {
463
462
  return [null, "Provided symbol is not correct" /* SYMBOL_ERROR */];
464
463
  }
465
- const decimalsBn = new BigNumber2(10).pow(new BigNumber2(chainDecimals));
464
+ const decimalsBn = new BigNumber(10).pow(new BigNumber(chainDecimals));
466
465
  const containDecimal = numberStr.includes(".");
467
466
  const [decPart, fracPart] = numberStr.split(".");
468
467
  const fracDecimals = fracPart?.length || 0;
469
- const fracExp = new BigNumber2(10).pow(new BigNumber2(fracDecimals));
470
- numeric = containDecimal ? new BigNumber2(
471
- new BigNumber2(decPart).multipliedBy(fracExp).plus(new BigNumber2(fracPart))
472
- ) : new BigNumber2(new BigNumber2(numberStr));
468
+ const fracExp = new BigNumber(10).pow(new BigNumber(fracDecimals));
469
+ numeric = containDecimal ? new BigNumber(
470
+ new BigNumber(decPart).multipliedBy(fracExp).plus(new BigNumber(fracPart))
471
+ ) : new BigNumber(new BigNumber(numberStr));
473
472
  numeric = numeric.multipliedBy(decimalsBn);
474
473
  if (containDecimal) {
475
474
  numeric = siVal.isMil ? numeric.dividedBy(siVal.value).dividedBy(fracExp) : numeric.multipliedBy(siVal.value).dividedBy(fracExp);
476
475
  } else {
477
476
  numeric = siVal.isMil ? numeric.dividedBy(siVal.value) : numeric.multipliedBy(siVal.value);
478
477
  }
479
- if (numeric.eq(new BigNumber2(0))) {
478
+ if (numeric.eq(new BigNumber(0))) {
480
479
  return [null, "You cannot send 0 funds" /* ZERO */];
481
480
  }
482
481
  return [numeric, "" /* SUCCESS */];
@@ -523,7 +522,7 @@ var mergeDeep = (target, ...sources) => {
523
522
  }
524
523
  return mergeDeep(target, ...sources);
525
524
  };
526
- var stringToBigNumber = (value) => new BigNumber2(rmCommas(value));
525
+ var stringToBigNumber = (value) => new BigNumber(rmCommas(value));
527
526
  export {
528
527
  addedTo,
529
528
  appendOr,
@@ -537,9 +536,7 @@ export {
537
536
  evalUnits,
538
537
  extractUrlValue,
539
538
  formatAccountSs58,
540
- greaterThanZero,
541
539
  inChrome,
542
- isNotZero,
543
540
  isSuperset,
544
541
  isValidAddress,
545
542
  isValidHttpUrl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@w3ux/utils",
3
- "version": "0.10.0",
3
+ "version": "0.10.1-alpha.1",
4
4
  "license": "GPL-3.0-only",
5
5
  "dependencies": {
6
6
  "@polkadot-api/substrate-bindings": "^0.9.3",
package/unit.cjs CHANGED
@@ -96,7 +96,7 @@ function isFunction(value) {
96
96
  function invalidFallback() {
97
97
  return Number.NaN;
98
98
  }
99
- var BigInt = /* @__PURE__ */ extractGlobal("BigInt", invalidFallback);
99
+ var BigInt2 = /* @__PURE__ */ extractGlobal("BigInt", invalidFallback);
100
100
 
101
101
  // ../../node_modules/@polkadot/util/hex/toU8a.js
102
102
  var CHR = "0123456789abcdef";
@@ -136,7 +136,7 @@ function isHex(value, bitLength = -1, ignoreLength) {
136
136
  }
137
137
 
138
138
  // ../../node_modules/@polkadot/util/has.js
139
- var hasBigInt = typeof BigInt === "function" && typeof BigInt.asIntN === "function";
139
+ var hasBigInt = typeof BigInt2 === "function" && typeof BigInt2.asIntN === "function";
140
140
  var hasBuffer = typeof xglobal.Buffer === "function" && typeof xglobal.Buffer.isBuffer === "function";
141
141
  var hasProcess = typeof xglobal.process === "object";
142
142
 
@@ -205,10 +205,9 @@ function u8aUnwrapBytes(bytes) {
205
205
  }
206
206
 
207
207
  // src/unit.ts
208
- var import_bignumber2 = require("bignumber.js");
208
+ var import_bignumber = require("bignumber.js");
209
209
 
210
210
  // src/base.ts
211
- var import_bignumber = require("bignumber.js");
212
211
  var import_substrate_bindings = require("@polkadot-api/substrate-bindings");
213
212
  var ellipsisFn = (str, amount = 6, position = "center") => {
214
213
  const half = str.length / 2;
@@ -241,12 +240,12 @@ var rmCommas = (val) => val.replace(/,/g, "");
241
240
  // src/unit.ts
242
241
  var import_substrate_bindings2 = require("@polkadot-api/substrate-bindings");
243
242
  var remToUnit = (rem) => Number(rem.slice(0, rem.length - 3)) * parseFloat(getComputedStyle(document.documentElement).fontSize);
244
- var planckToUnit = (val, units) => new import_bignumber2.BigNumber(
245
- val.dividedBy(new import_bignumber2.BigNumber(10).exponentiatedBy(units)).toFixed(units)
243
+ var planckToUnit = (val, units) => new import_bignumber.BigNumber(
244
+ val.dividedBy(new import_bignumber.BigNumber(10).exponentiatedBy(units)).toFixed(units)
246
245
  );
247
246
  var unitToPlanck = (val, units) => {
248
- const init = new import_bignumber2.BigNumber(!val.length || !val ? "0" : val);
249
- return (!init.isNaN() ? init : new import_bignumber2.BigNumber(0)).multipliedBy(new import_bignumber2.BigNumber(10).exponentiatedBy(units)).integerValue();
247
+ const init = new import_bignumber.BigNumber(!val.length || !val ? "0" : val);
248
+ return (!init.isNaN() ? init : new import_bignumber.BigNumber(0)).multipliedBy(new import_bignumber.BigNumber(10).exponentiatedBy(units)).integerValue();
250
249
  };
251
250
  var capitalizeFirstLetter = (string) => string.charAt(0).toUpperCase() + string.slice(1);
252
251
  var snakeToCamel = (str) => str.toLowerCase().replace(
@@ -398,7 +397,7 @@ var makeCancelable = (promise) => {
398
397
  }
399
398
  };
400
399
  };
401
- var getSiValue = (si2) => new import_bignumber2.BigNumber(10).pow(new import_bignumber2.BigNumber(si2));
400
+ var getSiValue = (si2) => new import_bignumber.BigNumber(10).pow(new import_bignumber.BigNumber(si2));
402
401
  var si = [
403
402
  { value: getSiValue(24), symbol: "y", isMil: true },
404
403
  { value: getSiValue(21), symbol: "z", isMil: true },
@@ -408,7 +407,7 @@ var si = [
408
407
  { value: getSiValue(9), symbol: "n", isMil: true },
409
408
  { value: getSiValue(6), symbol: "\u03BC", isMil: true },
410
409
  { value: getSiValue(3), symbol: "m", isMil: true },
411
- { value: new import_bignumber2.BigNumber(1), symbol: "" },
410
+ { value: new import_bignumber.BigNumber(1), symbol: "" },
412
411
  { value: getSiValue(3), symbol: "k" },
413
412
  { value: getSiValue(6), symbol: "M" },
414
413
  { value: getSiValue(9), symbol: "G" },
@@ -433,25 +432,25 @@ var evalUnits = (input, chainDecimals) => {
433
432
  const symbol = input.replace(/[0-9.,]/g, "");
434
433
  const siVal = si.find((s) => s.symbol === symbol);
435
434
  const numberStr = input.replace(symbol, "").replace(",", ".");
436
- let numeric = new import_bignumber2.BigNumber(0);
435
+ let numeric = new import_bignumber.BigNumber(0);
437
436
  if (!siVal) {
438
437
  return [null, "Provided symbol is not correct" /* SYMBOL_ERROR */];
439
438
  }
440
- const decimalsBn = new import_bignumber2.BigNumber(10).pow(new import_bignumber2.BigNumber(chainDecimals));
439
+ const decimalsBn = new import_bignumber.BigNumber(10).pow(new import_bignumber.BigNumber(chainDecimals));
441
440
  const containDecimal = numberStr.includes(".");
442
441
  const [decPart, fracPart] = numberStr.split(".");
443
442
  const fracDecimals = fracPart?.length || 0;
444
- const fracExp = new import_bignumber2.BigNumber(10).pow(new import_bignumber2.BigNumber(fracDecimals));
445
- numeric = containDecimal ? new import_bignumber2.BigNumber(
446
- new import_bignumber2.BigNumber(decPart).multipliedBy(fracExp).plus(new import_bignumber2.BigNumber(fracPart))
447
- ) : new import_bignumber2.BigNumber(new import_bignumber2.BigNumber(numberStr));
443
+ const fracExp = new import_bignumber.BigNumber(10).pow(new import_bignumber.BigNumber(fracDecimals));
444
+ numeric = containDecimal ? new import_bignumber.BigNumber(
445
+ new import_bignumber.BigNumber(decPart).multipliedBy(fracExp).plus(new import_bignumber.BigNumber(fracPart))
446
+ ) : new import_bignumber.BigNumber(new import_bignumber.BigNumber(numberStr));
448
447
  numeric = numeric.multipliedBy(decimalsBn);
449
448
  if (containDecimal) {
450
449
  numeric = siVal.isMil ? numeric.dividedBy(siVal.value).dividedBy(fracExp) : numeric.multipliedBy(siVal.value).dividedBy(fracExp);
451
450
  } else {
452
451
  numeric = siVal.isMil ? numeric.dividedBy(siVal.value) : numeric.multipliedBy(siVal.value);
453
452
  }
454
- if (numeric.eq(new import_bignumber2.BigNumber(0))) {
453
+ if (numeric.eq(new import_bignumber.BigNumber(0))) {
455
454
  return [null, "You cannot send 0 funds" /* ZERO */];
456
455
  }
457
456
  return [numeric, "" /* SUCCESS */];
@@ -498,7 +497,7 @@ var mergeDeep = (target, ...sources) => {
498
497
  }
499
498
  return mergeDeep(target, ...sources);
500
499
  };
501
- var stringToBigNumber = (value) => new import_bignumber2.BigNumber(rmCommas(value));
500
+ var stringToBigNumber = (value) => new import_bignumber.BigNumber(rmCommas(value));
502
501
  // Annotate the CommonJS export names for ESM import in node:
503
502
  0 && (module.exports = {
504
503
  addedTo,
package/unit.js CHANGED
@@ -36,7 +36,7 @@ function isFunction(value) {
36
36
  function invalidFallback() {
37
37
  return Number.NaN;
38
38
  }
39
- var BigInt = /* @__PURE__ */ extractGlobal("BigInt", invalidFallback);
39
+ var BigInt2 = /* @__PURE__ */ extractGlobal("BigInt", invalidFallback);
40
40
 
41
41
  // ../../node_modules/@polkadot/util/hex/toU8a.js
42
42
  var CHR = "0123456789abcdef";
@@ -76,7 +76,7 @@ function isHex(value, bitLength = -1, ignoreLength) {
76
76
  }
77
77
 
78
78
  // ../../node_modules/@polkadot/util/has.js
79
- var hasBigInt = typeof BigInt === "function" && typeof BigInt.asIntN === "function";
79
+ var hasBigInt = typeof BigInt2 === "function" && typeof BigInt2.asIntN === "function";
80
80
  var hasBuffer = typeof xglobal.Buffer === "function" && typeof xglobal.Buffer.isBuffer === "function";
81
81
  var hasProcess = typeof xglobal.process === "object";
82
82
 
@@ -145,10 +145,9 @@ function u8aUnwrapBytes(bytes) {
145
145
  }
146
146
 
147
147
  // src/unit.ts
148
- import { BigNumber as BigNumber2 } from "bignumber.js";
148
+ import { BigNumber } from "bignumber.js";
149
149
 
150
150
  // src/base.ts
151
- import { BigNumber } from "bignumber.js";
152
151
  import { AccountId } from "@polkadot-api/substrate-bindings";
153
152
  var ellipsisFn = (str, amount = 6, position = "center") => {
154
153
  const half = str.length / 2;
@@ -181,12 +180,12 @@ var rmCommas = (val) => val.replace(/,/g, "");
181
180
  // src/unit.ts
182
181
  import { AccountId as AccountId2 } from "@polkadot-api/substrate-bindings";
183
182
  var remToUnit = (rem) => Number(rem.slice(0, rem.length - 3)) * parseFloat(getComputedStyle(document.documentElement).fontSize);
184
- var planckToUnit = (val, units) => new BigNumber2(
185
- val.dividedBy(new BigNumber2(10).exponentiatedBy(units)).toFixed(units)
183
+ var planckToUnit = (val, units) => new BigNumber(
184
+ val.dividedBy(new BigNumber(10).exponentiatedBy(units)).toFixed(units)
186
185
  );
187
186
  var unitToPlanck = (val, units) => {
188
- const init = new BigNumber2(!val.length || !val ? "0" : val);
189
- return (!init.isNaN() ? init : new BigNumber2(0)).multipliedBy(new BigNumber2(10).exponentiatedBy(units)).integerValue();
187
+ const init = new BigNumber(!val.length || !val ? "0" : val);
188
+ return (!init.isNaN() ? init : new BigNumber(0)).multipliedBy(new BigNumber(10).exponentiatedBy(units)).integerValue();
190
189
  };
191
190
  var capitalizeFirstLetter = (string) => string.charAt(0).toUpperCase() + string.slice(1);
192
191
  var snakeToCamel = (str) => str.toLowerCase().replace(
@@ -338,7 +337,7 @@ var makeCancelable = (promise) => {
338
337
  }
339
338
  };
340
339
  };
341
- var getSiValue = (si2) => new BigNumber2(10).pow(new BigNumber2(si2));
340
+ var getSiValue = (si2) => new BigNumber(10).pow(new BigNumber(si2));
342
341
  var si = [
343
342
  { value: getSiValue(24), symbol: "y", isMil: true },
344
343
  { value: getSiValue(21), symbol: "z", isMil: true },
@@ -348,7 +347,7 @@ var si = [
348
347
  { value: getSiValue(9), symbol: "n", isMil: true },
349
348
  { value: getSiValue(6), symbol: "\u03BC", isMil: true },
350
349
  { value: getSiValue(3), symbol: "m", isMil: true },
351
- { value: new BigNumber2(1), symbol: "" },
350
+ { value: new BigNumber(1), symbol: "" },
352
351
  { value: getSiValue(3), symbol: "k" },
353
352
  { value: getSiValue(6), symbol: "M" },
354
353
  { value: getSiValue(9), symbol: "G" },
@@ -373,25 +372,25 @@ var evalUnits = (input, chainDecimals) => {
373
372
  const symbol = input.replace(/[0-9.,]/g, "");
374
373
  const siVal = si.find((s) => s.symbol === symbol);
375
374
  const numberStr = input.replace(symbol, "").replace(",", ".");
376
- let numeric = new BigNumber2(0);
375
+ let numeric = new BigNumber(0);
377
376
  if (!siVal) {
378
377
  return [null, "Provided symbol is not correct" /* SYMBOL_ERROR */];
379
378
  }
380
- const decimalsBn = new BigNumber2(10).pow(new BigNumber2(chainDecimals));
379
+ const decimalsBn = new BigNumber(10).pow(new BigNumber(chainDecimals));
381
380
  const containDecimal = numberStr.includes(".");
382
381
  const [decPart, fracPart] = numberStr.split(".");
383
382
  const fracDecimals = fracPart?.length || 0;
384
- const fracExp = new BigNumber2(10).pow(new BigNumber2(fracDecimals));
385
- numeric = containDecimal ? new BigNumber2(
386
- new BigNumber2(decPart).multipliedBy(fracExp).plus(new BigNumber2(fracPart))
387
- ) : new BigNumber2(new BigNumber2(numberStr));
383
+ const fracExp = new BigNumber(10).pow(new BigNumber(fracDecimals));
384
+ numeric = containDecimal ? new BigNumber(
385
+ new BigNumber(decPart).multipliedBy(fracExp).plus(new BigNumber(fracPart))
386
+ ) : new BigNumber(new BigNumber(numberStr));
388
387
  numeric = numeric.multipliedBy(decimalsBn);
389
388
  if (containDecimal) {
390
389
  numeric = siVal.isMil ? numeric.dividedBy(siVal.value).dividedBy(fracExp) : numeric.multipliedBy(siVal.value).dividedBy(fracExp);
391
390
  } else {
392
391
  numeric = siVal.isMil ? numeric.dividedBy(siVal.value) : numeric.multipliedBy(siVal.value);
393
392
  }
394
- if (numeric.eq(new BigNumber2(0))) {
393
+ if (numeric.eq(new BigNumber(0))) {
395
394
  return [null, "You cannot send 0 funds" /* ZERO */];
396
395
  }
397
396
  return [numeric, "" /* SUCCESS */];
@@ -438,7 +437,7 @@ var mergeDeep = (target, ...sources) => {
438
437
  }
439
438
  return mergeDeep(target, ...sources);
440
439
  };
441
- var stringToBigNumber = (value) => new BigNumber2(rmCommas(value));
440
+ var stringToBigNumber = (value) => new BigNumber(rmCommas(value));
442
441
  export {
443
442
  addedTo,
444
443
  applyWidthAsPadding,