Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of displayList #388

Open
staab opened this issue Jul 19, 2024 · 1 comment
Open

Get rid of displayList #388

staab opened this issue Jul 19, 2024 · 1 comment
Labels
enhancement New feature or request help wanted Good issue for non-core contributors to help with

Comments

@staab
Copy link
Collaborator

staab commented Jul 19, 2024

Use new Intl.ListFormat(getLocale(), {style: "long", type: "conjunction"}) instead. Stick it in a utility function.

@staab staab added enhancement New feature or request help wanted Good issue for non-core contributors to help with labels Jul 19, 2024
@zmjohnso
Copy link
Contributor

zmjohnso commented Sep 2, 2024

Been thinking about this one. Using Intl.ListFormat() feels like a good idea and would work well but alone it does not cover the same functionality as your displayLists library function. Notably this part of the logic:

else if (xs.length > n + 2) {
    return `${xs.slice(0, n).join(", ")}, ${conj} ${xs.length - n} others`
  }

Utilizing Intl.ListFormat() the updated logic could look something like this:

export default <T>(xs: T[], conj = "and", n = 6, locale = "en-US") => {
if (xs.length > n + 2) {
  const formattedList = new Intl.ListFormat(locale, { style: "long", type: "conjunction" }).format(xs.slice(0, n));
  return `${formattedList}, ${conj} ${xs.length - n} others`;
}

return new Intl.ListFormat(locale, { style: "long", type: "conjunction" }).format(xs);
}

Do you think it makes more sense to move this logic into the project via a utility function, or update it in your hurdak library method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Good issue for non-core contributors to help with
Projects
None yet
Development

No branches or pull requests

2 participants