diff options
author | mat <github@matdoes.dev> | 2022-03-04 18:32:23 +0000 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-03-04 18:32:23 +0000 |
commit | bdec09128e134238e3e0efdaa7cf6e7c46c19c94 (patch) | |
tree | a083c5f2354ac15d4771eb168267d49d55e84076 /src/lib/utils.ts | |
parent | 8168f3807966913640e95e074248f31e7444416c (diff) | |
download | skyblock-stats-bdec09128e134238e3e0efdaa7cf6e7c46c19c94.tar.gz skyblock-stats-bdec09128e134238e3e0efdaa7cf6e7c46c19c94.tar.bz2 skyblock-stats-bdec09128e134238e3e0efdaa7cf6e7c46c19c94.zip |
add leaderboards
Diffstat (limited to 'src/lib/utils.ts')
-rw-r--r-- | src/lib/utils.ts | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/utils.ts b/src/lib/utils.ts index c581af0..aabd981 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -114,6 +114,13 @@ export function cleanId(id: string) { .replace(/_/g, ' ') } +export function toTitleCase(s: string) { + return s.replace( + /\w\S*/g, + w => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase() + ) +} + export function toRomanNumerals(number: number) { return ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X', 'XI', 'XII', 'XIII', 'XIV', 'XV', 'XVI', 'XVII', 'XVIII', 'XIX', 'XX'][number] } @@ -151,4 +158,17 @@ export function formatNumber(n: number, digits = 3) { ] const item = numberSymbolsLookup.slice().reverse().find(item => n >= item.value) return (n / (item?.value ?? 1)).toPrecision(digits).replace(/\.0+$|(\.[0-9]*[1-9])0+$/, '$1') + (item?.symbol ?? '') +} + +export function formatNumberFromUnit(n: number, unit: null | 'date' | 'time' | string) { + switch (unit) { + case null: + return n.toLocaleString() + case 'date': + return (new Date(n * 1000)).toUTCString() + case 'time': + return millisecondsToTime(Math.abs(n)) + default: + return `${n.toLocaleString()} ${unit}` + } }
\ No newline at end of file |