Jobs, stops and drivers with pure helpers: late and at-risk against windows, a stop's status as High Command's five, priority order and tone, driver ranking by distance, load and skills, and moving a stop without crossing work done or under way.
Part of High Command Pro. The preview and props are open to everyone; installing it needs your license key. Set up your key · Pricing
$ npx shadcn@latest add @highcommand/dispatch-libCopies the source into your project and pulls in what it needs (3 other items). First time? Add the registry to components.json.
isStopLate(s: DispatchStop, now: number): booleanLate: arrived after the window, failed, or (not there yet) the ETA or now past the window's end.
isStopAtRisk(s: DispatchStop, now: number, marginMs?: number): booleanStill open, ETA within `marginMs` of the window's end, not late yet.
stopTone(s: DispatchStop, now: number): StatusColorA stop's status: failed blocked, late, at risk, skipped neutral, otherwise on track.
stopCounts(stops: readonly DispatchStop[]): { total: number; done: number; failed: number; closed: number; remaining: number; }Counts a route's stops: total, done, failed, closed (done, failed or skipped) and remaining (not closed).
sortJobs<T extends Job>(jobs: readonly T[]): T[]Urgent first, then the earliest window end, then id.
distanceM(a: LngLat, b: LngLat): numberGreat-circle metres between two points.
distanceText(m: number): stringMiles for US fleets: "0.4 mi", "12 mi".
rankDrivers(job: Job, drivers: readonly DispatchDriver[], distance?: (a: LngLat, b: LngLat) => number, kmPerStop?: number): DriverCandidate[]Ranks on-duty drivers for a job: distance plus `kmPerStop` per stop still open (lower is better). Drivers who lack what the job needs sort after the ones who can do it, full ones after those; off-duty drivers are left out. Pass a road distance when you have one.
moveStop<T extends DispatchStop>(stops: readonly T[], from: number, to: number): T[]Moves the stop at `from` to `to`, unless either end is locked (never resequence ahead of work already done or under way).
isClosed(s: DispatchStop): booleanTrue for a stop that is done, failed or skipped.
isLocked(s: DispatchStop): booleanOn site or closed: the driver is committed, so the stop cannot move in the sequence.
clock(ms: number): string"09:30" (24-hour, as High Command's tables read).
windowText(w: TimeWindow): string"09:30–11:30".