fix(format): compact counts of a million or more as "1.2M"#63
Merged
Conversation
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.
Owner
|
Hello @eeshsaxena thanks for your interest in contributing to gitfut, good catch |
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.
What
formatCountonly had a thousands tier, so any value at or above a million rendered as a four-digit thousands string:That is neither compact nor readable, and a five-character string like
12300koverflows 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
1_250_000 -> "1.3M"and12_300_000 -> "12M".999_950+over to"1M"rather than rounding up to"1000k", so a four-digit thousands value can never be printed.1240 -> "1.2k",248723 -> "249k",9999 -> "10k",999 -> "999").Tests
lib/format.tshad no test file, and CONTRIBUTING asks for tests on pure logic, so this addstests/format.test.tscoveringformatCount(small values, the thousands tier, the decimal-drop at ten thousands, the new millions tier, and the rollover boundary) plusround1/round2.master(expected '1000k' to be '1M') and pass with this change.npm run lintreports 0 errors.An AI assistant helped spot and implement this; I reviewed the change and ran the tests and linter locally.