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

Added ES6 local support for formatNumber helper as per #2951 #3099

Merged
merged 6 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions js/dist-typings/common/utils/formatNumber.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* The `formatNumber` utility localizes a number into a string with the
* appropriate punctuation.
* appropriate punctuation based on the provided locale otherwise will default to the users locale.
*
* @example
* formatNumber(1234);
* formatNumber(1234, 'en-US');
* // 1,234
*/
export default function formatNumber(number: number): string;
export default function formatNumber(number: number, locale?: string): string;
14 changes: 10 additions & 4 deletions js/src/common/utils/formatNumber.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
/**
* The `formatNumber` utility localizes a number into a string with the
* appropriate punctuation.
* appropriate punctuation based on the provided locale otherwise will default to the users locale.
*
* @example
* formatNumber(1234);
* formatNumber(1234, 'en-US');
* // 1,234
*/
export default function formatNumber(number: number): string {
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
export default function formatNumber(number: number, locale?: string): string {
if (typeof locale === 'undefined') {
const locale: string = app.data.locale;
}
Braunson marked this conversation as resolved.
Show resolved Hide resolved

return new Intl
.NumberFormat(locale)
.format(number);
}