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

perf: use Intl.NumberFormat instead of toLocaleString #13949

Merged
merged 1 commit into from Jul 25, 2023

Conversation

patak-dev
Copy link
Member

Description

See @Jarred-Sumner thread: https://twitter.com/jarredsumner/status/1683809307987697670


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

@stackblitz
Copy link

stackblitz bot commented Jul 25, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@patak-dev patak-dev added the performance Performance related enhancement label Jul 25, 2023
@patak-dev patak-dev merged commit a48bf88 into main Jul 25, 2023
20 checks passed
@patak-dev patak-dev deleted the perf/use-intl-number-formatter branch July 25, 2023 13:22
minimumFractionDigits: 2,
})
const displaySize = (bytes: number) => {
return `${numberFormatter.format(bytes / 1000)} kB`
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

FYI Intl.NumberFormat comes with a byte unit that you can pass in and it will automatically format it to the appropriate unit: https://v8.dev/features/intl-numberformat#units

const displaySize = Intl.NumberFormat('en', {
	notation: 'compact',
	style: 'unit',
	unit: 'byte',
	unitDisplay: 'narrow',
	minimumFractionDigits: 1,
	maximumFractionDigits: 2,
}).format;

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice! PR welcome to improve this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance related enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants