lbry-desktop/ui/util/string.js

29 lines
830 B
JavaScript
Raw Normal View History

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