mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-04 05:19:12 -04:00
added enum to use base 2 or base 10 for calcs
This commit is contained in:
parent
c5ba4f356f
commit
ea6b3d0c38
1 changed files with 7 additions and 2 deletions
|
@ -1,9 +1,14 @@
|
|||
export function formatBytes(bytes: number, decimals = 2) {
|
||||
export enum UNIT_BASE {
|
||||
BASE_2 = 1024,
|
||||
BASE_10 = 1000
|
||||
}
|
||||
|
||||
export function formatBytes(bytes: number, decimals = 2, base: UNIT_BASE = UNIT_BASE.BASE_2) {
|
||||
if (bytes === 0) {
|
||||
return '0 Bytes';
|
||||
}
|
||||
|
||||
const k = 1024;
|
||||
const k = base;
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue