Skip to content

perf: use Intl.NumberFormat instead of toLocaleString#13949

Merged
patak-cat merged 1 commit intomainfrom
perf/use-intl-number-formatter
Jul 25, 2023
Merged

perf: use Intl.NumberFormat instead of toLocaleString#13949
patak-cat merged 1 commit intomainfrom
perf/use-intl-number-formatter

Conversation

@patak-cat
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

@bolt-new-by-stackblitz
Copy link

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

@patak-cat patak-cat added the performance Performance related enhancement label Jul 25, 2023
@patak-cat patak-cat merged commit a48bf88 into main Jul 25, 2023
@patak-cat patak-cat 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
Contributor

@privatenumber privatenumber Jul 26, 2023

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.

3 participants