@autonomys/auto-utils 0.6.6 → 0.6.7

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.
@@ -1,5 +1,6 @@
1
1
  export * from './domain';
2
2
  export * from './network';
3
+ export * from './number';
3
4
  export * from './token';
4
5
  export * from './wallet';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAEA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAEA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA"}
@@ -17,5 +17,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  __exportStar(require("./domain"), exports);
19
19
  __exportStar(require("./network"), exports);
20
+ __exportStar(require("./number"), exports);
20
21
  __exportStar(require("./token"), exports);
21
22
  __exportStar(require("./wallet"), exports);
@@ -0,0 +1,2 @@
1
+ export declare const BIGINT_ZERO: bigint;
2
+ //# sourceMappingURL=number.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../src/constants/number.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,QAAY,CAAA"}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BIGINT_ZERO = void 0;
4
+ exports.BIGINT_ZERO = BigInt(0);
package/dist/number.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export declare const parseTokenAmount: (amount: string | bigint, decimals?: number) => number | bigint;
2
2
  export declare const formatTokenAmount: (amount: number | bigint, decimals?: number) => number | bigint;
3
+ export declare const formatSpacePledged: (value: bigint, decimals?: number) => string;
3
4
  //# sourceMappingURL=number.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../src/number.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,WACnB,MAAM,GAAG,MAAM,aACb,MAAM,oBAIjB,CAAA;AAED,eAAO,MAAM,iBAAiB,WACpB,MAAM,GAAG,MAAM,aACb,MAAM,oBAIjB,CAAA"}
1
+ {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../src/number.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,gBAAgB,WACnB,MAAM,GAAG,MAAM,aACb,MAAM,oBAIjB,CAAA;AAED,eAAO,MAAM,iBAAiB,WACpB,MAAM,GAAG,MAAM,aACb,MAAM,oBAIjB,CAAA;AAED,eAAO,MAAM,kBAAkB,UAAW,MAAM,8BAU/C,CAAA"}
package/dist/number.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatTokenAmount = exports.parseTokenAmount = void 0;
3
+ exports.formatSpacePledged = exports.formatTokenAmount = exports.parseTokenAmount = void 0;
4
+ const number_1 = require("./constants/number");
4
5
  const token_1 = require("./constants/token");
5
6
  const parseTokenAmount = (amount, decimals = token_1.DEFAULT_TOKEN_DECIMALS) => {
6
7
  if (typeof amount === 'bigint')
@@ -14,3 +15,13 @@ const formatTokenAmount = (amount, decimals = token_1.DEFAULT_TOKEN_DECIMALS) =>
14
15
  return amount * Math.pow(10, decimals);
15
16
  };
16
17
  exports.formatTokenAmount = formatTokenAmount;
18
+ const formatSpacePledged = (value, decimals = 2) => {
19
+ if (typeof value !== 'bigint' || value === number_1.BIGINT_ZERO)
20
+ return '0 Bytes';
21
+ const k = 1024;
22
+ const dm = decimals < 0 ? 0 : decimals;
23
+ const sizes = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
24
+ const i = Math.floor(Math.log(Number(value)) / Math.log(k));
25
+ return (Number(value) / Math.pow(k, i)).toFixed(dm) + ' ' + sizes[i];
26
+ };
27
+ exports.formatSpacePledged = formatSpacePledged;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autonomys/auto-utils",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -38,5 +38,5 @@
38
38
  "browser": {
39
39
  "fs": false
40
40
  },
41
- "gitHead": "94646ea042d018cd883558fb6ca750ed49d95dae"
41
+ "gitHead": "2ba65337aa923eaac7269aaea70db97112bfc033"
42
42
  }