FileSize
Class: FileSize
Defined in: packages/utils/src/filesize.ts:17
Represents a file size that can be created from a number of bytes or a human-readable string.
Schema:
@schema number | string@minimum 0@pattern ^([0-9]*\.?[0-9]+)\s*(B|KB|MB|GB|TB|PB|O|KO|MO|GO|TO|PO)?$
Supported inputs:
- Numeric bytes:
1024 - Strings with units:
"1 KB","1MB","1.5 GB" - Octet aliases (translated to
B):O,KO,MO,GO,TO,PO
Output formatting chooses the most suitable unit and prints with 0 decimals for values >= 100, otherwise 2 decimals.
Constructors
Constructor
new FileSize(
value):FileSize
Defined in: packages/utils/src/filesize.ts:23
Create a FileSize.
Parameters
value
string | number
Bytes as a number or a unit string.
Returns
FileSize
Properties
value
value:
number
Defined in: packages/utils/src/filesize.ts:18
Methods
[toPrimitive]()
[toPrimitive](
hint):string|number
Defined in: packages/utils/src/filesize.ts:83
Allow implicit conversion to string or number depending on the hint.
Parameters
hint
"string" | "number" | "default"
Coercion hint: "string" returns a formatted size string, otherwise returns the raw byte count.
Returns
string | number
A formatted string (e.g. "1.23 MB") or the numeric byte count.
toString()
toString():
string
Defined in: packages/utils/src/filesize.ts:59
Format bytes using the most suitable unit with a fixed precision.
Returns
string
Human readable size string like "1.23 MB".
valueOf()
valueOf():
number
Defined in: packages/utils/src/filesize.ts:51
Primitive numeric representation returns the number of bytes.
Returns
number
Bytes as a number.