Skip to content

parseSize

parseSize(size): number

Defined in: packages/storage/src/schema.ts:31

Parse a human-readable size string into bytes.

Supports b, kb, mb, and gb units (case-insensitive). Decimal values are supported and the result is rounded to the nearest byte.

string

Size string (e.g. "10mb", "1.5kb", "500b", "1gb").

number

The size in bytes.

If the format is invalid.

import { parseSize } from "@cfast/storage";
parseSize("2mb"); // 2097152
parseSize("1.5kb"); // 1536
parseSize("500b"); // 500