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

intlFormat: use single combined options parameter #3807

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Renegade334
Copy link
Contributor

@Renegade334 Renegade334 commented May 18, 2024

The current implementation of intlFormat currently supports three different call signatures for providing options: calling with format options, calling with locale options, or calling with both as separate arguments.

When the newer intlFormatDistance was implemented, it used a much simpler call signature, with all options bundled into one parameter.

Having different paradigms for the two functions seems odd, and so this proposal would change the canonical signature for passing options to intlFormat to

intlFormat(date: DateType | number | string, options: IntlFormatOptions);

where IntlFormatOptions accepts both DateTimeFormat options and the locale property.

This signature is already compatible with both of the old two-parameter signatures, and so just replaces them. The old three-parameter call signature would be deprecated, but remain supported for the time being.

This PR contains a supplementary change to add options destructuring to intlFormatDistance, in the same way that it's used in this update to intlFormat. The current implementation of intlFormatDistance from #3796 doesn't remove the locales and unit properties from the options argument before passing it to Intl.RelativeTimeFormat; although these are ignored by the constructor, it's probably best practice not to include cruft with the passed RelativeTimeFormat options.

@Renegade334 Renegade334 marked this pull request as ready for review May 18, 2024 08:04
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.

None yet

1 participant