bytes function

Converts bytes to a human-readable string with appropriate units (KB, MB, GB, etc.).

Signatures

bytes (1/2) function

Signature

(bytes: number): string

Example

bytes(1024) // "1 KB"
bytes(1048576) // "1 MB"
bytes(123456789) // "117.74 MB"

Parameters

bytes

The number of bytes

Returns

A human-readable string representing the size in appropriate units

bytes (2/2) function

Signature

(str: string): number

Example

bytes("1 KB") // 1024
bytes("1 MB") // 1048576
bytes("117.74 MB") // 123456789

Parameters

str

The string to convert

Returns

The number of bytes represented by the string