Skip to content

Use Intl.ListFormat for formatList and locale for duration labels - #239

Open
jrmybtlr wants to merge 1 commit into
mainfrom
cursor/formatters-native-intl-cde2
Open

Use Intl.ListFormat for formatList and locale for duration labels#239
jrmybtlr wants to merge 1 commit into
mainfrom
cursor/formatters-native-intl-cde2

Conversation

@jrmybtlr

@jrmybtlr jrmybtlr commented Sep 8, 2026

Copy link
Copy Markdown
Owner

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 locale option.

Changes

  • formatList: uses Intl.ListFormat for full lists (and → conjunction, or → disjunction). Default locale is en-GB so existing no-Oxford-comma English output stays stable. Truncation (limit / "N more") remains custom.
  • formatDurationLabels: accepts locale and threads it into formatUnit / Intl.NumberFormat unit style.
  • Docs and tests updated for the new options.

Verification

  • pnpm exec vitest run src/* — 339 tests passed
  • ESLint clean on src/formatters.ts
Open in Web Open in Cursor 

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>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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

@jrmybtlr
jrmybtlr marked this pull request as ready for review September 8, 2026 22:05
@jrmybtlr
jrmybtlr requested a lite review from Copilot September 8, 2026 22:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 formatDurationLabels to accept locale and pass it through to formatUnit for localized unit labels.
  • Rework formatList to use Intl.ListFormat for full lists (with and/or mapped to conjunction/disjunction), keeping the existing truncation (limit / "N more") behavior custom.
  • Update docs and tests to cover the new locale options 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.

Comment thread src/formatters.ts
Comment on lines +486 to +491
// 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`
}
Comment thread docs/pages/formatters.md
### `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.
Comment thread src/formatters.ts
Comment on lines +464 to +465
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants