Skip to content

bytesToSize Byte Unit Conversion Utility ​

Function List ​

bytesToSize(bytes) => string ​

Converts a byte count into a readable unit string, automatically selecting the appropriate unit (b/KB/MB/GB).

Parameters

NameTypeRequiredDefaultDescription
bytesnumberYes-Byte size

Return Value

TypeDescription
stringThe converted readable unit string (b/KB/MB/GB)

Example

typescript
import { bytesToSize } from '@hy-app/ui';

const num = bytesToSize(1024);
console.log(num); // 1KB