Skip to content

fix(format): compact counts of a million or more as "1.2M"#63

Merged
Younesfdj merged 1 commit into
Younesfdj:masterfrom
eeshsaxena:fix/format-millions
Jul 14, 2026
Merged

fix(format): compact counts of a million or more as "1.2M"#63
Younesfdj merged 1 commit into
Younesfdj:masterfrom
eeshsaxena:fix/format-millions

Conversation

@eeshsaxena

Copy link
Copy Markdown
Contributor

What

formatCount only had a thousands tier, so any value at or above a million rendered as a four-digit thousands string:

formatCount(999_999)     -> "1000k"     (should roll over)
formatCount(1_000_000)   -> "1000k"
formatCount(1_250_000)   -> "1200k"     (should be "1.3M")
formatCount(12_300_000)  -> "12300k"    (should be "12M")

That is neither compact nor readable, and a five-character string like 12300k overflows the fixed-width slots it feeds (the card, the Scout Report metric bars, and the duel comparison rows).

This is reachable in practice: totals for the biggest accounts land in this range, and they get bigger once organization-owned repositories are counted (see #31 / #32) - "stars earned" for a top author is a six-figure number today and clears a million for the very top of the list.

Change

  • Add a millions tier that reuses the existing precision rule (one decimal below ten units, none above), so 1_250_000 -> "1.3M" and 12_300_000 -> "12M".
  • Roll 999_950+ over to "1M" rather than rounding up to "1000k", so a four-digit thousands value can never be printed.
  • Behaviour below a million is unchanged (1240 -> "1.2k", 248723 -> "249k", 9999 -> "10k", 999 -> "999").

Tests

lib/format.ts had no test file, and CONTRIBUTING asks for tests on pure logic, so this adds tests/format.test.ts covering formatCount (small values, the thousands tier, the decimal-drop at ten thousands, the new millions tier, and the rollover boundary) plus round1 / round2.

  • The two new millions assertions fail on master (expected '1000k' to be '1M') and pass with this change.
  • Full suite green: 18 files, 168 tests. npm run lint reports 0 errors.

An AI assistant helped spot and implement this; I reviewed the change and ran the tests and linter locally.

formatCount only had a thousands tier, so any value at or above a million
rendered as a four-digit thousands string: 1,250,000 became "1200k" and
12,300,000 became "12300k", which is neither compact nor readable and
overflows the fixed-width card slots. Totals reach that range for top
accounts once organization-owned repositories are counted.

Add a millions tier reusing the existing precision rule (one decimal below
ten units, none above), and roll 999,950+ over to "1M" instead of rounding
up to "1000k". Add tests for lib/format.ts, which had none.
@Younesfdj

Copy link
Copy Markdown
Owner

Hello @eeshsaxena thanks for your interest in contributing to gitfut, good catch

@Younesfdj
Younesfdj merged commit c109867 into Younesfdj:master Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants