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 1 commit
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
Prev Previous commit
Next Next commit
Made locale an optional parameter, default to user locale
  • Loading branch information
Braunson committed Oct 8, 2021
commit 17b7154b6dbffdd4ac31e30a6ab53e6520b9ebe3
4 changes: 2 additions & 2 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 based on the provided locale.
* appropriate punctuation based on the provided locale otherwise will default to the users locale.
*
* @example
* formatNumber(1234, 'en-US');
* // 1,234
*/
export default function formatNumber(number: number, locale: string): string;
export default function formatNumber(number: number, locale?: string): string;
Braunson marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 6 additions & 2 deletions js/src/common/utils/formatNumber.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
/**
* The `formatNumber` utility localizes a number into a string with the
* appropriate punctuation based on the provided locale.
* appropriate punctuation based on the provided locale otherwise will default to the users locale.
*
* @example
* formatNumber(1234, 'en-US');
* // 1,234
*/
export default function formatNumber(number: number, locale: string = 'en-US'): string {
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);
Expand Down