Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738/** * What the app prints when it has a number and the thing that number counts. * * A count is the one piece of text in this app that is written by arithmetic and read out loud. * Every other string is fixed prose somebody chose; the digits in `12,304 tracks` arrive from a * `length`, and the noun beside them has to agree with them anyway, in a language where agreement * is a suffix. Left to itself the plural form wins by being shorter, and the bug is invisible to * whoever writes it and to whoever reviews it, because both of them have a library of thousands * of songs: the singular only appears on the one machine with one album on it, in the one screen * nobody opens twice, in the string nobody quoted in the issue. * * So the agreement lives here, once, and takes the irregulars as an argument. Deriving `many` * from `one` is the part deliberately *not* automated: `copy` becomes `copies`, `song page` * becomes `song pages` (not `song ses`), and the two words worth getting wrong are exactly the * compound and the irregular ones a naive `+ "s"` eats. */
/** Library-scale counts are grouped the way the harvest's own status line groups them. */const thousands = new Intl.NumberFormat("en-US");
/** * A count and its noun, agreeing: `1 track`, `2 tracks`, `12,304 tracks`. * * Zero keeps its digit. `0 files` is grammatical, and several of these lines are ledgers where * the digit is the fact — `3 tracks, 0 records` is a diagnosis, and `no records` would be the same * diagnosis in a font the reader has to translate. `zero` is there for the places that genuinely * mean the words (`no matches`), and nowhere else. */export function count( n: number, one: string, many: string = `${one}s`, zero: string | undefined = undefined,): string { if (n === 0 && zero !== undefined) return zero; return `${thousands.format(n)} ${n === 1 ? one : many}`;}