lbry-desktop/ui/util/string.js
infinite-persistence 3719a73c81
Add announcement modal and open it after prefs sync'd.
- Don't want to show it in Incognito.
- Only show it in when entered from homepage, or in the Help page.
- Record the hash of the viewed announcement and update the wallet with it.
2022-05-20 00:04:06 +08:00

32 lines
967 B
JavaScript

// @flow
export function toCapitalCase(string: string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
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);
}
}
export function stripLeadingAtSign(str: ?string) {
return str && str.charAt(0) === '@' ? str.slice(1) : str;
}
export function getSimpleStrHash(s: string) {
return String(s.split('').reduce((a, b) => ((a << 5) - a + b.charCodeAt(0)) | 0, 0));
}