@autonomys/auto-consensus 1.2.6 → 1.2.8
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/utils/format.d.ts +8 -0
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/format.js +24 -8
- package/package.json +3 -3
package/dist/utils/format.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
export declare const formatSpaceToBinaryAsObject: (value: number, decimals?: number) => {
|
|
2
|
+
value: number;
|
|
3
|
+
unit: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const formatSpaceToDecimalAsObject: (value: number, decimals?: number) => {
|
|
6
|
+
value: number;
|
|
7
|
+
unit: string;
|
|
8
|
+
};
|
|
1
9
|
export declare const formatSpaceToBinary: (value: number, decimals?: number) => string;
|
|
2
10
|
export declare const formatSpaceToDecimal: (value: number, decimals?: number) => string;
|
|
3
11
|
//# sourceMappingURL=format.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/utils/format.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,mBAAmB,UAAW,MAAM,
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/utils/format.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,2BAA2B,UAC/B,MAAM,wBAEZ;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAU/B,CAAA;AAGD,eAAO,MAAM,4BAA4B,UAChC,MAAM,wBAEZ;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAU/B,CAAA;AAGD,eAAO,MAAM,mBAAmB,UAAW,MAAM,wBAAiB,MAKjE,CAAA;AAGD,eAAO,MAAM,oBAAoB,UAAW,MAAM,wBAAiB,MAKlE,CAAA"}
|
package/dist/utils/format.js
CHANGED
|
@@ -1,25 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatSpaceToDecimal = exports.formatSpaceToBinary = void 0;
|
|
3
|
+
exports.formatSpaceToDecimal = exports.formatSpaceToBinary = exports.formatSpaceToDecimalAsObject = exports.formatSpaceToBinaryAsObject = void 0;
|
|
4
4
|
// Binary format (powers of 2)
|
|
5
|
-
const
|
|
5
|
+
const formatSpaceToBinaryAsObject = (value, decimals = 2) => {
|
|
6
6
|
if (value === 0)
|
|
7
|
-
return
|
|
7
|
+
return { value: 0, unit: 'Bytes' };
|
|
8
8
|
const k = 1024;
|
|
9
9
|
const dm = decimals < 0 ? 0 : decimals;
|
|
10
10
|
const sizes = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
|
|
11
11
|
const i = Math.floor(Math.log(value) / Math.log(k));
|
|
12
|
-
return parseFloat((value / Math.pow(k, i)).toFixed(dm))
|
|
12
|
+
return { value: parseFloat((value / Math.pow(k, i)).toFixed(dm)), unit: sizes[i] };
|
|
13
13
|
};
|
|
14
|
-
exports.
|
|
14
|
+
exports.formatSpaceToBinaryAsObject = formatSpaceToBinaryAsObject;
|
|
15
15
|
// Decimal format (powers of 10)
|
|
16
|
-
const
|
|
16
|
+
const formatSpaceToDecimalAsObject = (value, decimals = 2) => {
|
|
17
17
|
if (value === 0)
|
|
18
|
-
return
|
|
18
|
+
return { value: 0, unit: 'Bytes' };
|
|
19
19
|
const k = 1000;
|
|
20
20
|
const dm = decimals < 0 ? 0 : decimals;
|
|
21
21
|
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
22
22
|
const i = Math.floor(Math.log(value) / Math.log(k));
|
|
23
|
-
return parseFloat((value / Math.pow(k, i)).toFixed(dm))
|
|
23
|
+
return { value: parseFloat((value / Math.pow(k, i)).toFixed(dm)), unit: sizes[i] };
|
|
24
|
+
};
|
|
25
|
+
exports.formatSpaceToDecimalAsObject = formatSpaceToDecimalAsObject;
|
|
26
|
+
// Binary format (powers of 2)
|
|
27
|
+
const formatSpaceToBinary = (value, decimals = 2) => {
|
|
28
|
+
if (value === 0)
|
|
29
|
+
return '0 Bytes';
|
|
30
|
+
const { value: formattedValue, unit } = (0, exports.formatSpaceToBinaryAsObject)(value, decimals);
|
|
31
|
+
return `${formattedValue} ${unit}`;
|
|
32
|
+
};
|
|
33
|
+
exports.formatSpaceToBinary = formatSpaceToBinary;
|
|
34
|
+
// Decimal format (powers of 10)
|
|
35
|
+
const formatSpaceToDecimal = (value, decimals = 2) => {
|
|
36
|
+
if (value === 0)
|
|
37
|
+
return '0 Bytes';
|
|
38
|
+
const { value: formattedValue, unit } = (0, exports.formatSpaceToDecimalAsObject)(value, decimals);
|
|
39
|
+
return `${formattedValue} ${unit}`;
|
|
24
40
|
};
|
|
25
41
|
exports.formatSpaceToDecimal = formatSpaceToDecimal;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autonomys/auto-consensus",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"README.md"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@autonomys/auto-utils": "^1.2.
|
|
28
|
+
"@autonomys/auto-utils": "^1.2.8"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/jest": "^29.5.12",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"ts-jest": "^29.1.4",
|
|
36
36
|
"typescript": "^5.4.5"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "680433a2a62e23fad2bb5cc40706be259dcf51c5"
|
|
39
39
|
}
|