✨ feat(config): FormatBytes
This commit is contained in:
parent
8f322fbcbe
commit
9251a09232
@ -2,7 +2,7 @@ import { intlFormat } from '@shadcn/ui/lib/date-fns';
|
|||||||
|
|
||||||
export function formatBytes(bytes: number) {
|
export function formatBytes(bytes: number) {
|
||||||
if (bytes === 0) return '0 B';
|
if (bytes === 0) return '0 B';
|
||||||
const k = 1000, // or 1024
|
const k = 1024, // or 1000
|
||||||
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
|
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
|
||||||
i = Math.floor(Math.log(bytes) / Math.log(k));
|
i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||||
|
|
||||||
|
|||||||
@ -11,13 +11,13 @@ export function unitConversion(
|
|||||||
case 'dollarsToCents':
|
case 'dollarsToCents':
|
||||||
return evaluate(`${value} * 100`);
|
return evaluate(`${value} * 100`);
|
||||||
case 'bitsToMb':
|
case 'bitsToMb':
|
||||||
return evaluate(`${value} / 1000 / 1000`);
|
return evaluate(`${value} / 1024 / 1024`);
|
||||||
case 'mbToBits':
|
case 'mbToBits':
|
||||||
return evaluate(`${value} * 1000 * 1000`);
|
return evaluate(`${value} * 1024 * 1024`);
|
||||||
case 'bytesToGb':
|
case 'bytesToGb':
|
||||||
return evaluate(`${value} / 1000 / 1000 / 1000`);
|
return evaluate(`${value} / 1024 / 1024 / 1024`);
|
||||||
case 'gbToBytes':
|
case 'gbToBytes':
|
||||||
return evaluate(`${value} * 1000 * 1000 * 1000`);
|
return evaluate(`${value} * 1024 * 1024 * 1024`);
|
||||||
default:
|
default:
|
||||||
throw new Error('Invalid conversion type');
|
throw new Error('Invalid conversion type');
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user