doxa-maps/library/utils/formatCount.js
Doxa Maps 6cc5542b70 One place decides how a count is punctuated, and it still says en-US
The numerals policy is HELD — whether counts follow the reader's locale is the Driver's decision — so
this changes nothing anyone can see. Every caller renders exactly the digits and separators it
rendered before. What changes is how many places that decision is written down: thirteen call sites
across four bundles becomes one, library/utils/formatCount.js, and eight of the thirteen (mine) now
read it.

That is the whole value while the policy is held. If the answer becomes "follow the locale" it is a
one-line edit in formatCount.js instead of thirteen edits by four owners, each free to pick a
different locale source — and the first divergence in that world would be invisible: two panels in
one dashboard, same number, different separators.

★ IT FORMATS. IT DOES NOT DECIDE WHAT EMPTY MEANS, and that is the bug this fold would otherwise have
shipped. I told dx-shepherd these three helpers were "byte-identical". They are not:
  DashboardDataTable     null/undefined -> ''   and '' falls through to Number('') === 0, so "0"
  DashboardDetailDrawer  null/undefined/'' -> '—'
  useDashboardShell      null/undefined -> '—'  and '' likewise becomes "0"
Three different answers to "what does a missing count look like", inside one dashboard. Folding them
onto one empty policy would have silently changed two of the three — a table cell going from blank to
an em dash, or an em dash where a zero used to be. So each caller KEEPS its own guard and hands
formatCount a value it has already established is real. The locale decision folds; the empty policy
does not, and the difference is written into the helper's header so the next person does not re-merge
them.

Folded: DashboardDataTable, DashboardDetailDrawer, useDashboardShell (its exported fmt keeps working
for the KPI strip), DashboardFacetRail's three inline template calls, people-groups-grid's two.
NOT folded, because they are other owners': regions-dashboard (3) and pplr-data-maps (2). The helper
is theirs to import when they want it; nothing forces them, and no gate demands it — a gate requiring
the helper everywhere would fail on their files today, which is not a thing to land on someone else.

Source only. research-dashboard, dashboard-plus-grid and people-groups-grid need a rebuild.
2026-09-27 06:04:08 +00:00

31 lines
1.9 KiB
JavaScript

/**
* formatCount — the ONE place the fleet decides how a COUNT is punctuated.
*
* ★ IT HOLDS en-US ON PURPOSE. Whether numerals follow the reader's locale is a DRIVER decision and
* it is currently held, so this file changes nothing about what anyone sees: every caller renders
* exactly the digits and separators it rendered before. What it changes is the number of places that
* decision is written down — from thirteen call sites across four bundles to one.
*
* That is the whole value while the policy is held: if the answer becomes "follow the locale", this
* is a one-line edit here (read the same hostLang -> getRuntimeLocale() -> detectLocale() chain the
* text reads) instead of thirteen edits by four owners, each free to pick a different locale source.
* The first divergence in that world would be invisible: two panels in one dashboard, same number,
* different separators.
*
* ★ IT FORMATS. IT DOES NOT DECIDE WHAT EMPTY MEANS, and that distinction is not fastidiousness —
* it is the bug this fold would otherwise have shipped. The three `fmt` helpers it replaced looked
* interchangeable and were not:
* DashboardDataTable null/undefined -> '' and '' falls through to Number('') === 0, so "0"
* DashboardDetailDrawer null/undefined/'' -> '—'
* useDashboardShell null/undefined -> '—' and '' likewise becomes "0"
* Three different answers to "what does a missing count look like", in one dashboard. Folding them
* onto one empty policy would have silently changed two of the three — a table cell going from blank
* to an em dash, or an em dash appearing where a zero used to. So each caller keeps its own guard and
* hands this function a value it has already decided is real.
*/
export const COUNT_LOCALE = 'en-US'
/** @param {number|string} n a value the caller has already established is present */
export const formatCount = (n) => Number(n).toLocaleString(COUNT_LOCALE)
export default formatCount