Skip to content

Commit 5829e95

Browse files
committed
fix(abbreviateCount): return placeholder for non-numeric input instead of unguarded padStart
padStart only pads, never truncates — a non-numeric raw string would pass through at its original width and break column alignment. Return ' ?' instead to keep COL_COUNT width while visually flagging the unexpected input.
1 parent c4dfd99 commit 5829e95

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/lib/formatters/human.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,12 @@ const QUANTIFIERS = ["", "K", "M", "B", "T", "P", "E"];
330330
*/
331331
function abbreviateCount(raw: string): string {
332332
const n = Number(raw);
333-
if (Number.isNaN(n) || n < 10_000) {
333+
if (Number.isNaN(n)) {
334+
// Non-numeric input: use a placeholder rather than passing through an
335+
// arbitrarily wide string that would break column alignment
336+
return " ?";
337+
}
338+
if (n < 10_000) {
334339
return raw.padStart(COL_COUNT);
335340
}
336341
const tier = Math.min(Math.floor(Math.log10(n) / 3), QUANTIFIERS.length - 1);

0 commit comments

Comments
 (0)