@uxf/core 11.47.0 → 11.51.0
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/README.md +8 -0
- package/package.json +1 -1
- package/utils/format-bytes.d.ts +1 -0
- package/utils/format-bytes.js +10 -0
- package/utils/format-bytes.test.d.ts +1 -0
- package/utils/format-bytes.test.js +9 -0
package/README.md
CHANGED
|
@@ -405,6 +405,14 @@ const submitHandler: FormEventHandler<HTMLFormElement> = () => {
|
|
|
405
405
|
};
|
|
406
406
|
```
|
|
407
407
|
|
|
408
|
+
### formatBytes
|
|
409
|
+
|
|
410
|
+
Appends suitable unit to the byte value of data size.
|
|
411
|
+
```ts
|
|
412
|
+
formatBytes(17.5 * 1024);
|
|
413
|
+
//=> "17.5 kB"
|
|
414
|
+
```
|
|
415
|
+
|
|
408
416
|
## Validators
|
|
409
417
|
```tsx
|
|
410
418
|
import { Validator } from "@uxf/core";
|
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatBytes(bytes: number, decimals?: number): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatBytes = formatBytes;
|
|
4
|
+
function formatBytes(bytes, decimals = 2) {
|
|
5
|
+
const k = 1024;
|
|
6
|
+
const dm = decimals < 0 ? 0 : decimals;
|
|
7
|
+
const sizes = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
8
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
9
|
+
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const format_bytes_1 = require("./format-bytes");
|
|
4
|
+
test("format-bytes", () => {
|
|
5
|
+
expect((0, format_bytes_1.formatBytes)(1)).toEqual("1 B");
|
|
6
|
+
expect((0, format_bytes_1.formatBytes)(1024)).toEqual("1 kB");
|
|
7
|
+
expect((0, format_bytes_1.formatBytes)(1024 * 1024)).toEqual("1 MB");
|
|
8
|
+
expect((0, format_bytes_1.formatBytes)(17.55 * 1024)).toEqual("17.55 kB");
|
|
9
|
+
});
|