|
@@ -76,5 +76,26 @@ export default {
|
|
|
const hour = `${date.getHours()}`.padStart(2, "0");
|
|
|
const minute = `${date.getMinutes()}`.padStart(2, "0");
|
|
|
return `${year}-${month}-${day} ${hour}:${minute}`;
|
|
|
+ },
|
|
|
+ // Turns for example 125953 into 125.95K
|
|
|
+ getNumberRounded: (number: number) => {
|
|
|
+ if (number > 1000000000 - 1)
|
|
|
+ return `${(number / 1000000000).toFixed(2)}B`;
|
|
|
+ if (number > 1000000 - 1) return `${(number / 1000000).toFixed(2)}M`;
|
|
|
+ if (number > 1000 - 1) return `${(number / 1000).toFixed(2)}K`;
|
|
|
+ return number;
|
|
|
+ },
|
|
|
+ // Based on https://stackoverflow.com/a/42235254 - ported to JavaScript
|
|
|
+ getEmojiFlagForCountryCode: (countryCode: string) => {
|
|
|
+ const flagOffset = 0x1f1e6;
|
|
|
+ const asciiOffset = 0x41;
|
|
|
+
|
|
|
+ const firstChar = countryCode.codePointAt(0) - asciiOffset + flagOffset;
|
|
|
+ const secondChar =
|
|
|
+ countryCode.codePointAt(1) - asciiOffset + flagOffset;
|
|
|
+
|
|
|
+ return (
|
|
|
+ String.fromCodePoint(firstChar) + String.fromCodePoint(secondChar)
|
|
|
+ );
|
|
|
}
|
|
|
};
|