✨ 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) {
|
||||
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'],
|
||||
i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
|
||||
|
||||
@ -11,13 +11,13 @@ export function unitConversion(
|
||||
case 'dollarsToCents':
|
||||
return evaluate(`${value} * 100`);
|
||||
case 'bitsToMb':
|
||||
return evaluate(`${value} / 1000 / 1000`);
|
||||
return evaluate(`${value} / 1024 / 1024`);
|
||||
case 'mbToBits':
|
||||
return evaluate(`${value} * 1000 * 1000`);
|
||||
return evaluate(`${value} * 1024 * 1024`);
|
||||
case 'bytesToGb':
|
||||
return evaluate(`${value} / 1000 / 1000 / 1000`);
|
||||
return evaluate(`${value} / 1024 / 1024 / 1024`);
|
||||
case 'gbToBytes':
|
||||
return evaluate(`${value} * 1000 * 1000 * 1000`);
|
||||
return evaluate(`${value} * 1024 * 1024 * 1024`);
|
||||
default:
|
||||
throw new Error('Invalid conversion type');
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user