Use Intl.ListFormat for formatList and locale for duration labels - #239
Use Intl.ListFormat for formatList and locale for duration labels#239jrmybtlr wants to merge 1 commit into
Conversation
Replace hand-rolled English list joining with Intl.ListFormat (default en-GB to preserve no-Oxford-comma output), keep custom limit/"N more" truncation, and thread a locale option through formatDurationLabels. Co-authored-by: Jeremy Butler <jrmybtlr@users.noreply.github.com>
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
usemods | 61aea43 | Commit Preview URL Branch Preview URL |
Sep 08 2026, 08:23 PM |
There was a problem hiding this comment.
🟡 Changes recommended
formatList truncation currently produces incorrect/awkward output for limit <= 0, and the updated docs still claim “comma-separated” despite Intl.ListFormat being locale-dependent.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR continues the Intl-based formatter cleanup by switching formatList to native Intl.ListFormat for locale-aware joining and by adding a locale option to formatDurationLabels so duration unit labels can be localized consistently with other formatters.
Changes:
- Update
formatDurationLabelsto acceptlocaleand pass it through toformatUnitfor localized unit labels. - Rework
formatListto useIntl.ListFormatfor full lists (withand/ormapped to conjunction/disjunction), keeping the existing truncation (limit/"N more") behavior custom. - Update docs and tests to cover the new
localeoptions and list formatting behavior.
File summaries
| File | Description |
|---|---|
src/formatters.ts |
Adds locale handling for duration labels and switches full-list joining to Intl.ListFormat. |
src/formatters.test.ts |
Adds/updates tests for localized duration labels and Intl.ListFormat list output. |
nuxt-web/pages/docs/formatters.vue |
Updates docs-site function signatures to include the new locale options. |
docs/pages/formatters.md |
Updates public docs for the new locale options and Intl.ListFormat behavior. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // ListFormat has no "N more" equivalent — keep truncation English-literal. | ||
| if (list.length > effectiveLimit) { | ||
| const listedItems = list.slice(0, effectiveLimit).join(', ') | ||
| const remaining = list.length - effectiveLimit | ||
| return `${listedItems} ${conj} ${remaining} more` | ||
| } |
| ### `formatList(items: string | object | string[], options?: { limit?: number, conjunction?: string, locale?: string }): string` | ||
|
|
||
| Create a string of comma-separated values from an array, object, or string with an optional limit and conjunction. | ||
| Create a string of comma-separated values from an array, object, or string with an optional limit and conjunction. Full lists use `Intl.ListFormat`; truncation (`limit` / "N more") stays custom. |
| * Create a string of comma-separated values from an array, object, or string with an optional limit and conjunction. | ||
| * Uses Intl.ListFormat for locale-aware joining; truncation (`limit` / "N more") stays custom. |
Summary
Follow-up to the dates Intl cleanup: lean on native Intl in formatters for the remaining hand-rolled list joining, and align duration labels with sibling formatters via a
localeoption.Changes
formatList: usesIntl.ListFormatfor full lists (and→ conjunction,or→ disjunction). Default locale isen-GBso existing no-Oxford-comma English output stays stable. Truncation (limit/"N more") remains custom.formatDurationLabels: acceptslocaleand threads it intoformatUnit/Intl.NumberFormatunit style.Verification
pnpm exec vitest run src/*— 339 tests passedsrc/formatters.ts