1
0
mirror of https://github.com/flarum/core.git synced 2025-07-16 14:26:25 +02:00

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

This commit is contained in:
Braunson Yager
2021-10-13 14:48:37 -04:00
committed by GitHub
parent 894707c61a
commit 7fa4189fc1

View File

@ -1,11 +1,13 @@
import app from '../../forum/app';
/**
* 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);
* // 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 = app.data.locale): string {
return new Intl.NumberFormat(locale).format(number);
}