[ChromeWebStoreUsers] Fix 1M+ counts rendering as "12000,000" not "12M" (#12028)

* [ChromeWebStoreUsers] Fix 1M+ counts rendering as "12000,000" not "12M"

The Chrome Web Store reports counts with thousands separators, e.g.
"12,000,000". The handler stripped them with a string argument to
String.prototype.replace, which only removes the first match, leaving
"12000,000". metric() then coerced that to NaN and printed it verbatim.
Counts below 1M have a single separator, so they were unaffected.

Use a global regex so every separator is removed, and extract the logic
into a testable static transform() (mirroring ChromeWebStoreSize) with
deterministic unit tests for the millions case.

* [ChromeWebStoreUsers] Address review: use replaceAll, drop redundant metric test
This commit is contained in:
TheConfax authored and GitHub committed 2026-07-21 08:32:55 +00:00
1 parent bd23e5fce6
commit 4aa38bdd5f
2 files changed
+20 -1

No files matched your search

@@ -23,6 +23,10 @@ class ChromeWebStoreUsers extends BaseChromeWebStoreService {
static defaultBadgeData = { label: 'users' }
static transform(users) {
return String(users.replaceAll(',', ''))
}
async handle({ storeId }) {
const chromeWebStore = await this.fetch({ storeId })
const downloads = chromeWebStore.users()
@@ -30,7 +34,7 @@ class ChromeWebStoreUsers extends BaseChromeWebStoreService {
throw new NotFound({ prettyMessage: 'not found' })
}
return renderDownloadsBadge({
downloads: String(downloads.replace(',', '')),
downloads: this.constructor.transform(downloads),
})
}
}
@@ -0,0 +1,15 @@
import { test, given } from 'sazerac'
import { ChromeWebStoreUsers } from './chrome-web-store-users.service.js'
describe('ChromeWebStoreUsers', function () {
describe('transform', function () {
it('strips every thousands separator, not just the first', function () {
test(ChromeWebStoreUsers.transform, () => {
given('8,000').expect('8000')
given('500,000').expect('500000')
given('3,000,000').expect('3000000')
given('12,000,000').expect('12000000')
})
})
})
})