@talismn/util 0.1.3 → 0.1.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @talismn/util
2
2
 
3
+ ## 0.1.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 4aa691d: feat: new balance modules
8
+ - a63dbb3: feat: formatDecimal allow for BigNumber amount
9
+
10
+ ## 0.1.4
11
+
12
+ ### Patch Changes
13
+
14
+ - fix: a variety of improvements from the wallet integration
15
+
3
16
  ## 0.1.3
4
17
 
5
18
  ### Patch Changes
@@ -1,3 +1,4 @@
1
+ import BigNumber from "bignumber.js";
1
2
  export declare const MAX_DECIMALS_FORMAT = 12;
2
3
  /**
3
4
  * Custom decimal number formatting for Talisman
@@ -8,4 +9,4 @@ export declare const MAX_DECIMALS_FORMAT = 12;
8
9
  * @param options formatting options
9
10
  * @returns the formatted value
10
11
  */
11
- export declare const formatDecimals: (num?: string | number | null, digits?: number, options?: Partial<Intl.NumberFormatOptions>, locale?: string) => string;
12
+ export declare const formatDecimals: (num?: string | number | null | BigNumber, digits?: number, options?: Partial<Intl.NumberFormatOptions>, locale?: string) => string;
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.formatDecimals = exports.MAX_DECIMALS_FORMAT = void 0;
7
7
  const bignumber_js_1 = __importDefault(require("bignumber.js"));
8
+ const MIN_DIGITS = 4; // less truncates more than what compact formating is
8
9
  exports.MAX_DECIMALS_FORMAT = 12;
9
10
  /**
10
11
  * Custom decimal number formatting for Talisman
@@ -15,9 +16,11 @@ exports.MAX_DECIMALS_FORMAT = 12;
15
16
  * @param options formatting options
16
17
  * @returns the formatted value
17
18
  */
18
- const formatDecimals = (num, digits = 4, options = {}, locale = "en-US") => {
19
+ const formatDecimals = (num, digits = MIN_DIGITS, options = {}, locale = "en-US") => {
19
20
  if (num === null || num === undefined)
20
21
  return "";
22
+ if (digits < MIN_DIGITS)
23
+ digits = MIN_DIGITS;
21
24
  const value = new bignumber_js_1.default(num);
22
25
  // very small numbers should display "< 0.0001"
23
26
  const minDisplayVal = 1 / Math.pow(10, digits);
@@ -44,8 +47,11 @@ const formatDecimals = (num, digits = 4, options = {}, locale = "en-US") => {
44
47
  .integerValue()
45
48
  .multipliedBy(excessIntegerDigitsPow10);
46
49
  // format
47
- return Intl.NumberFormat(locale, Object.assign({
50
+ return Intl.NumberFormat(locale, {
48
51
  //compact notation (K, M, B) if above 9999
49
- notation: truncatedValue.gt(9999) ? "compact" : "standard", maximumSignificantDigits: digits + (truncatedValue.lt(1) ? 1 : 0) }, options)).format(truncatedValue.toNumber());
52
+ notation: truncatedValue.gt(9999) ? "compact" : "standard",
53
+ maximumSignificantDigits: digits + (truncatedValue.lt(1) ? 1 : 0),
54
+ ...options,
55
+ }).format(truncatedValue.toNumber());
50
56
  };
51
57
  exports.formatDecimals = formatDecimals;
package/dist/index.d.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  export * from "./BigMath";
2
- export * from "./FunctionPropertyNames";
3
2
  export * from "./blake2Concat";
4
3
  export * from "./decodeAnyAddress";
5
4
  export * from "./encodeAnyAddress";
6
5
  export * from "./formatDecimals";
6
+ export * from "./FunctionPropertyNames";
7
7
  export * from "./getBase64ImageUrl";
8
8
  export * from "./hasOwnProperty";
9
9
  export * from "./isArrayOf";
10
10
  export * from "./planckToTokens";
11
+ export * from "./sleep";
12
+ export * from "./throwAfter";
11
13
  export * from "./tokensToPlanck";
12
14
  export * from "./twox64Concat";
package/dist/index.js CHANGED
@@ -15,14 +15,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./BigMath"), exports);
18
- __exportStar(require("./FunctionPropertyNames"), exports);
19
18
  __exportStar(require("./blake2Concat"), exports);
20
19
  __exportStar(require("./decodeAnyAddress"), exports);
21
20
  __exportStar(require("./encodeAnyAddress"), exports);
22
21
  __exportStar(require("./formatDecimals"), exports);
22
+ __exportStar(require("./FunctionPropertyNames"), exports);
23
23
  __exportStar(require("./getBase64ImageUrl"), exports);
24
24
  __exportStar(require("./hasOwnProperty"), exports);
25
25
  __exportStar(require("./isArrayOf"), exports);
26
26
  __exportStar(require("./planckToTokens"), exports);
27
+ __exportStar(require("./sleep"), exports);
28
+ __exportStar(require("./throwAfter"), exports);
27
29
  __exportStar(require("./tokensToPlanck"), exports);
28
30
  __exportStar(require("./twox64Concat"), exports);
@@ -0,0 +1 @@
1
+ export declare const sleep: (ms: number) => Promise<void>;
package/dist/sleep.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sleep = void 0;
4
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
5
+ exports.sleep = sleep;
@@ -0,0 +1 @@
1
+ export declare const throwAfter: (ms: number, reason: string) => Promise<void>;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throwAfter = void 0;
4
+ const throwAfter = (ms, reason) => new Promise((_, reject) => setTimeout(() => reject(reason), ms));
5
+ exports.throwAfter = throwAfter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talismn/util",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "author": "Talisman",
5
5
  "homepage": "https://talisman.xyz",
6
6
  "license": "UNLICENSED",