@autonomys/auto-utils 0.6.5 → 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.
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/index.js +1 -0
- package/dist/constants/number.d.ts +2 -0
- package/dist/constants/number.d.ts.map +1 -0
- package/dist/constants/number.js +4 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/number.d.ts +1 -0
- package/dist/number.d.ts.map +1 -1
- package/dist/number.js +12 -1
- package/dist/string.d.ts +5 -0
- package/dist/string.d.ts.map +1 -0
- package/dist/string.js +19 -0
- package/package.json +2 -2
|
@@ -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"}
|
package/dist/constants/index.js
CHANGED
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../src/constants/number.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,QAAY,CAAA"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,WAAW,CAAA;AACzB,cAAc,OAAO,CAAA;AACrB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AAExB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,WAAW,CAAA;AACzB,cAAc,OAAO,CAAA;AACrB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AAExB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __exportStar(require("./network"), exports);
|
|
|
23
23
|
__exportStar(require("./number"), exports);
|
|
24
24
|
__exportStar(require("./read"), exports);
|
|
25
25
|
__exportStar(require("./save"), exports);
|
|
26
|
+
__exportStar(require("./string"), exports);
|
|
26
27
|
__exportStar(require("./wallet"), exports);
|
|
27
28
|
__exportStar(require("./constants"), exports);
|
|
28
29
|
__exportStar(require("./types"), exports);
|
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
|
package/dist/number.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../src/number.ts"],"names":[],"mappings":"
|
|
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/dist/string.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const stringify: (value: any) => string;
|
|
2
|
+
export declare const shortString: (value: string, initialLength?: number, endLength?: number) => string;
|
|
3
|
+
export declare const capitalizeFirstLetter: (string: string) => string;
|
|
4
|
+
export declare const fixLengthEntryId: (blockHeight: bigint, indexInBlock?: bigint) => string;
|
|
5
|
+
//# sourceMappingURL=string.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,UAAW,GAAG,WACyD,CAAA;AAE7F,eAAO,MAAM,WAAW,UAAW,MAAM,iDAAsC,MACf,CAAA;AAEhE,eAAO,MAAM,qBAAqB,WAAY,MAAM,WACY,CAAA;AAEhE,eAAO,MAAM,gBAAgB,gBAAiB,MAAM,iBAAiB,MAAM,KAAG,MAQ7E,CAAA"}
|
package/dist/string.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// file: src/string.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.fixLengthEntryId = exports.capitalizeFirstLetter = exports.shortString = exports.stringify = void 0;
|
|
5
|
+
const stringify = (value) => JSON.stringify(value, (_, value) => (typeof value === 'bigint' ? value.toString() : value));
|
|
6
|
+
exports.stringify = stringify;
|
|
7
|
+
const shortString = (value, initialLength = 6, endLength = -4) => `${value.slice(0, initialLength)}...${value.slice(endLength)}`;
|
|
8
|
+
exports.shortString = shortString;
|
|
9
|
+
const capitalizeFirstLetter = (string) => string ? string.charAt(0).toUpperCase() + string.slice(1) : '';
|
|
10
|
+
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
11
|
+
const fixLengthEntryId = (blockHeight, indexInBlock) => {
|
|
12
|
+
const totalLength = 32;
|
|
13
|
+
const str1 = blockHeight.toString().padStart(totalLength, '0');
|
|
14
|
+
if (indexInBlock === undefined)
|
|
15
|
+
return str1;
|
|
16
|
+
const str2 = indexInBlock.toString().padStart(totalLength, '0');
|
|
17
|
+
return `${str1}-${str2}`;
|
|
18
|
+
};
|
|
19
|
+
exports.fixLengthEntryId = fixLengthEntryId;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autonomys/auto-utils",
|
|
3
|
-
"version": "0.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": "
|
|
41
|
+
"gitHead": "2ba65337aa923eaac7269aaea70db97112bfc033"
|
|
42
42
|
}
|