Status and money types, formatters, road snapping and CSV/Excel export used by High Command components.
| Call | Output |
|---|---|
| fmtMoney(m) | $31,462 |
| fmtMoney(m, { cents: true }) | $31,461.53 |
| fmtMoney(m, { compact: true }) | $31,462 |
| delayText(12) | +12 min |
| durationText(12) | 12 min |
| ago(now − 12 min, now) | 12 min ago |
| fmtDate("2026-10-01") | Oct 01 |
| fmtDateTime(…20:00Z, "America/Chicago") | Oct 01 15:00 CDT |
| snapToRoad(route R-07, near UT) | 14.84 km along · 129 m off |
Shipment,Customer,Promised,Slip (min),Order value SHP-48213,Atlas Foods Co.,2026-10-02,34,48210 SHP-48245,Summit Auto Parts,2026-10-03,12,31440 SHP-48251,'=Harbor & Pine,2026-10-03,0,18620.5 SHP-48260,"Bluestem Packaging, Inc.",2026-10-04,-5,3120.5
The CSV is what Export writes: amounts as plain dollars, dates ISO, a comma-holding name quoted, and the formula-looking customer prefixed with ' so a spreadsheet never runs it.
$ npx shadcn@latest add @highcommand/libCopies the source into your project and pulls in what it needs. First time? Add the registry to components.json.
delayText(min: number | null): stringDelay in words: "+12 min" behind plan, "-3 min" ahead, "On plan".
durationText(min: number): string"2 h 05 min", "45 min", "0 min".
fmtMoney(m: MoneyJson, o?: { cents?: boolean | undefined; compact?: boolean | undefined; }): stringMoney on the wire is a decimal string of minor units; never a float. Without cents it rounds half up to whole dollars.
fmtSV(v: string | number | MoneyJson | null, o?: { cents?: boolean | undefined; compact?: boolean | undefined; }): stringA SourcedValue's value as text: "—" for null, an integer with commas, other numbers to one decimal, a string as is, money through `fmtMoney` (`cents`: show cents; `compact`: $1.23M / $450k from $100,000 up).
fmtDate(iso: string | null | undefined): stringA calendar date as "Oct 01" (month and day, read in UTC so a date-only string never shifts a day); "—" when empty.
zoneAbbr(d: Date, timeZone?: string | undefined): stringThe viewer's time zone abbreviation at that instant ("EDT", "PST"; "GMT+2" where the zone has none).
fmtDateTime(iso: string | null | undefined, timeZone?: string | undefined): stringAn instant in the viewer's own time zone, with the zone named: "Oct 01 20:00 EDT". Business dates (due dates, promised dates) are calendar days and go through fmtDate instead. `timeZone` is for tests.
fmtClock(iso: string): stringThe simulated clock: the simulated day is a UTC day (due dates turn past due at UTC midnight), so the clock reads UTC and says so.
ago(iso: string | null, nowIso: string): stringHow long ago (or ahead) `iso` is from `nowIso`, as a phrase: "just now", "12 min ago", "3 h ago", "2 days ago", "in 3 days". Both are simulated instants when the caller passes the simulated clock.
agoShort(iso: string | null, nowIso: string): stringThe compact form for narrow columns: "now", "12m", "3h", "2d".
isMoney(v: unknown): v is MoneyJsonTrue for a money object on the wire (has `amount_minor` and `currency`).
moneyNumber(m: MoneyJson): numberMoney as a JS number of dollars (minor units / 100); fine for charts and sorting, not for arithmetic you display.
fmtTime(iso: string | null | undefined, timeZone?: string | undefined): stringTime of day in the viewer's zone: "20:00 EDT".
hhmm(ms: number): stringEpoch ms as local 24-hour "HH:MM" ("09:30", midnight "00:05").
titleCase(s: string): string"past_due" becomes "Past due": underscores to spaces, first letter capitalised.
haversineM(a: readonly [number, number], b: readonly [number, number]): numberGreat-circle distance in metres between two [lng, lat] points.
roadPath(pts: [number, number][]): RoadPathWraps [lng, lat] points as a RoadPath with the running metres at each point and the total length.
pointAlong(p: RoadPath, d: number): [number, number]The point `d` metres along the road (clamped to its ends).
snapToRoad(p: RoadPath, q: readonly [number, number], fromM?: number, toM?: number): Snap | nullThe nearest point of the road to `q`, searched between `fromM` and `toM` metres along it (the whole road by default). Segment by segment on a local flat projection: exact enough for the tens of metres that decide a match.
sliceRoad(p: RoadPath, aM: number, bM: number): [number, number][]The road between two distances along it (in either order, so a truck that backs up still draws), as [lng, lat] points.
endpointKey(lat: number, lng: number): string"lat,lng" rounded to 4 decimals.
pathKey(from: { lat: number; lng: number; }, to: { lat: number; lng: number; }): stringThe key of the road from one endpoint to the other.
rawOf(kind: ExportKind, v: ExportValue): string | number | nullThe value a cell holds: a number, a date (ISO string kept for its kind), text, or empty.
toCsv(t: ExportTable): stringCSV with a UTF-8 byte-order mark (Excel opens it as UTF-8), CRLF line ends. Dates stay ISO (2026-10-01, 2026-10-01T14:00:00Z).
toXlsx(t: ExportTable): Uint8Array<ArrayBufferLike>The table as an .xlsx workbook (one sheet named after the table, with an autofilter on the header row), built with no library.
crc32(b: Uint8Array<ArrayBufferLike>): numberCRC-32 (the zip checksum) of the bytes.
zipStore(entries: [string, Uint8Array<ArrayBufferLike>][]): Uint8Array<ArrayBufferLike>A zip archive of the given [name, bytes] entries, stored without compression and with a fixed timestamp so the same input gives the same bytes.
download(t: ExportTable, format: "csv" | "xlsx", asOf?: string | undefined): stringSaves the table in the browser as a .csv or .xlsx file named from the table and `asOf` (see `fileBase`); returns the file name. Browser only.
dollars(v: { amount_minor: string; }): numberDollars as a number, exact to the cent (amounts are integer cents on the wire).
excelSerial(iso: string): number | nullA date or date-time as an Excel serial day number (UTC, as every time on screen).
fileBase(name: string, asOf?: string | undefined): string"AR past due 2026-10-01": a file name from the table's name and the as-of date, safe on every system.
Install this free piece now; the Pro pieces drop in on top of it, in the same app. Pro is $79 once.