2019-07-17 16:49:06 -04:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
export function toCapitalCase(string: string) {
|
|
|
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
|
|
}
|
2022-01-10 10:35:34 +08:00
|
|
|
|
2022-02-26 22:55:49 +08:00
|
|
|
export function toCompactNotation(number: string | number, lang: ?string, minThresholdToApply?: number) {
|
2022-01-11 08:42:12 -08:00
|
|
|
const locale = lang || 'en';
|
2022-02-26 22:55:49 +08:00
|
|
|
const useCompactNotation = !minThresholdToApply || Number(number) >= minThresholdToApply;
|
2022-01-11 08:42:12 -08:00
|
|
|
|
2022-02-26 22:55:49 +08:00
|
|
|
if (useCompactNotation) {
|
2022-01-11 08:42:12 -08:00
|
|
|
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-10 10:35:34 +08:00
|
|
|
}
|
|
|
|
}
|
2022-02-23 04:42:43 -08:00
|
|
|
|
|
|
|
export function stripLeadingAtSign(str: ?string) {
|
|
|
|
return str && str.charAt(0) === '@' ? str.slice(1) : str;
|
|
|
|
}
|