Number Formatting: add new function to format a number to a short format
This function is to solve issue #24554 utilizing the Intl.NumberFormat function to shorten long numbers to a specific locale. Similarly to the wp-calypso implementation it will output numbers with 1 decimal if less than 3 digits.
Changes proposed in this Pull Request:
- Adds function to return large numbers formatted as a short string
Does this pull request change what data or activity we track or use?
This is pulling the user locale from getUserLocale, but other than that no.
Testing instructions
- import shortNumberFormat from @automattic/jetpack-components
- Call shortNumberFormat(number) with different WP locales set to get formatted string
I'm new to developing for Jetpack, I'm not sure the best way to test this.
Thank you for your PR!
When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
- :white_check_mark: Include a description of your PR changes.
- :white_check_mark: All commits were linted before commit.
- :white_check_mark: Add a "[Status]" label (In Progress, Needs Team Review, ...).
- :white_check_mark: Add testing instructions.
- :white_check_mark: Specify whether this PR includes any changes to data or privacy.
- :white_check_mark: Add changelog entries to affected projects
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation :robot:
The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.
Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped. Then, add the "[Status] Needs Team review" label and ask someone from your team review the code. Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.
Thinking about this some more, I wonder if a new function is the way to go. Maybe we could expand
numberFormatto support an additional, optional, formatting parameter?
It already has an options parameter: https://github.com/Automattic/jetpack/blob/trunk/projects/js-packages/components/components/number-format/index.ts