2019-07-17 22:49:06 +02:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
export function toCapitalCase(string: string) {
|
|
|
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
|
|
}
|
2022-01-26 00:16:28 +01:00
|
|
|
|
2022-01-27 16:20:21 +01:00
|
|
|
export function toCompactNotation(number: string | number, lang: ?string, minThresholdToApply?: string | number) {
|
|
|
|
const locale = lang || 'en';
|
|
|
|
|
|
|
|
if (minThresholdToApply && Number(number) >= Number(minThresholdToApply)) {
|
|
|
|
try {
|
|
|
|
return Number(number).toLocaleString(locale, {
|
|
|
|
compactDisplay: 'short',
|
|
|
|
notation: 'compact',
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
// Not all browsers support the additional options.
|
|
|
|
return Number(number).toLocaleString(locale);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return Number(number).toLocaleString(locale);
|
2022-01-26 00:16:28 +01:00
|
|
|
}
|
|
|
|
}
|