Repository navigation
refactor(web): share display formatters and HTTP status colours - #547
Open
sisantaChhatoi wants to merge 1 commit into
Open
sisantaChhatoi wants to merge 1 commit into
sisantaChhatoi wants to merge 1 commit into
Conversation
The same helpers were copied across the frontend: fmtBytes / fmtSize / formatArchiveBytes (10 copies, 5 behaviours), fmtTokens (7 copies, 3 behaviours), fmtTime / fmtDateTime (11 copies), fmtDuration and statusTone (4 identical copies). They now live in one place: - src/lib/format.ts: formatBytes, formatTokens, formatDurationMs, formatShortDateTime (with seconds / year / empty options) - src/lib/status.ts: httpStatusTone Intentionally distinct formats stay local (ISO log timestamps, full-locale finding date, the translated seconds-based task duration, unix task times). Visible changes from using one canonical output each: - sizes of 1 GiB and up show as GB instead of thousands of MB - dashboard / intercept token counts show "25k" instead of "25.0k" - LLM records show "2.5M" instead of "2500.0k" Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sisantaChhatoi
force-pushed
the
refactor/shared-formatters
branch
from
November 25, 2026 20:36
131e41c to
a183871
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 1 of the series described in #546.
Problem
Display helpers were copied across the frontend, and the copies drifted apart:
fmtBytes/fmtSize/formatArchiveBytes: 10 copies with 5 different behaviours (some stopped at MB, so 2 GiB showed as "2048.0 MB"; empty values showed as "—" or "0 B")fmtTokens: 7 copies with 3 behaviours ("25k" vs "25.0k"; one had no "M", so 2.5M showed as "2500.0k")fmtTime/fmtDateTime: 11 copies of the same month-day-time formatfmtDuration(ms): 2 identical copies, plus 1 unused copy in the chat pagestatusTone(HTTP status → text colour): 4 identical copies, one of them exported fromhttp-code-blockChange
src/lib/format.ts:formatBytes(with anemptyoption),formatTokens,formatDurationMs,formatShortDateTime(seconds/year/emptyoptions)src/lib/status.ts:httpStatusTone, next to the other status-to-colour mappingsKept local on purpose, because their formats are genuinely different: the ISO timestamps in logs, the full-locale date on the finding detail page, the translated seconds-based task duration, and the unix-seconds task time. The dashboard's
statusColoris also unchanged (different shades).Behaviour change
Each value now renders the same way everywhere:
Tested
npx tsc --noEmitnpm run test:polling,test:replay,test:upload,test:traffic-stream,test:tamper-hooks,test:i18n,test:bash, andnode --test src/lib/*.test.mjsnext build🤖 Generated with Claude Code