mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-24 16:54:43 +00:00
The reusable base the Capabilities rework sits on:
- lib/{text,time,format,json-format}: consolidate ~30 hand-rolled string/date/
number/JSON helpers behind one set of tested utilities.
- master-detail scaffold (MasterDetail / ListColumn / DetailColumn / DetailPane /
CapRow / ListStrip / ToolChip / ICON_BUTTON) + row-hover; tabs-as-data
PageSearchShell; EmptyState + ErrorBanner; a shared LogTail terminal surface.
- framed CodeEditor + JsonDocumentEditor, wired into every in-app markdown/JSON
edit surface (profile SOUL.md, memory nodes, right-click sidebar profile).
- shared React Query cache helper (writeCache) + per-profile-switch/ debounce hooks.
24 lines
807 B
TypeScript
24 lines
807 B
TypeScript
// THE compact-number formatter — every user-facing count/token figure goes
|
|
// through here. 999 → "999", 1000 → "1k", 1230 → "1.2k", 10000 → "10k",
|
|
// 1_500_000 → "1.5M". Do not hand-roll `/ 1000` display math elsewhere.
|
|
export function compactNumber(value: null | number | undefined): string {
|
|
const num = Number(value ?? 0)
|
|
|
|
if (!Number.isFinite(num) || num <= 0) {
|
|
return '0'
|
|
}
|
|
|
|
const scaled = (v: number, suffix: string) => `${v.toFixed(1).replace(/\.0$/, '')}${suffix}`
|
|
|
|
// Thresholds sit just under the unit boundary so rounding can't produce
|
|
// "1000k" or "1000" — those promote to the next unit instead.
|
|
if (num >= 999_950) {
|
|
return scaled(num / 1_000_000, 'M')
|
|
}
|
|
|
|
if (num >= 999.5) {
|
|
return scaled(num / 1_000, 'k')
|
|
}
|
|
|
|
return `${Math.round(num)}`
|
|
}
|