format
constformat:object
Defined in: utils/format.ts:171
Format namespace object for convenient access.
Type Declaration
Section titled “Type Declaration”bytes()
Section titled “bytes()”
readonlybytes: (bytes,decimals) =>string=formatBytes
Format bytes as human-readable string.
Parameters
Section titled “Parameters”number
Number of bytes
decimals
Section titled “decimals”number = 1
Number of decimal places (default: 1)
Returns
Section titled “Returns”string
Formatted string (e.g., “1.5 KB”, “2.3 MB”)
Example
Section titled “Example”formatBytes(0); // "0 B"formatBytes(1024); // "1 KB"formatBytes(1536); // "1.5 KB"formatBytes(1048576); // "1 MB"date()
Section titled “date()”
readonlydate: (isoDate,options) =>string=formatDate
Format ISO date string as human-readable date.
Parameters
Section titled “Parameters”isoDate
Section titled “isoDate”string
ISO date string (e.g., “2024-01-15T10:30:00Z”)
options
Section titled “options”DateTimeFormatOptions = ...
Intl.DateTimeFormat options
Returns
Section titled “Returns”string
Formatted date string
Example
Section titled “Example”formatDate("2024-01-15T10:30:00Z");// "Jan 15, 2024, 10:30 AM" (in local timezone)
formatDate("2024-01-15T10:30:00Z", { dateStyle: "short" });// "1/15/24"duration()
Section titled “duration()”
readonlyduration: (ms,options) =>string=formatDuration
Format duration in milliseconds as human-readable string.
Parameters
Section titled “Parameters”number
Duration in milliseconds
options
Section titled “options”Formatting options
compact?
Section titled “compact?”boolean
Returns
Section titled “Returns”string
Formatted duration string
Example
Section titled “Example”formatDuration(500); // "500ms"formatDuration(1500); // "1.5s"formatDuration(65000); // "1m 5s"formatDuration(3725000); // "1h 2m 5s"truncate()
Section titled “truncate()”truncate: (
text,maxLength,suffix) =>string
Truncate text to a maximum length, adding suffix if truncated.
Parameters
Section titled “Parameters”string
Text to truncate
maxLength
Section titled “maxLength”number
Maximum length including suffix
suffix
Section titled “suffix”string = "..."
Suffix to append when truncated (default: ”…”)
Returns
Section titled “Returns”string
Truncated text
Example
Section titled “Example”truncate("Hello, World!", 10); // "Hello, ..."truncate("Short", 10); // "Short"truncate("Custom", 6, "…"); // "Custo…"Example
Section titled “Example”import { format } from "llmist";
format.truncate("text", 5);format.bytes(1024);format.date("2024-01-15");format.duration(5000);