aboutsummaryrefslogtreecommitdiff
path: root/src/lib/utils.ts
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-02-15 21:58:20 +0000
committermat <github@matdoes.dev>2022-02-15 21:58:20 +0000
commitc060d60ba1d5f3ad9f37b48b50b694a2d19240d1 (patch)
tree23fb02b54c16c878675f47052eb4c2d5e6c7829c /src/lib/utils.ts
parent235fac70c745973f0fe3f18ea900922fa4b199f8 (diff)
downloadskyblock-stats-c060d60ba1d5f3ad9f37b48b50b694a2d19240d1.tar.gz
skyblock-stats-c060d60ba1d5f3ad9f37b48b50b694a2d19240d1.tar.bz2
skyblock-stats-c060d60ba1d5f3ad9f37b48b50b694a2d19240d1.zip
start adding profile
Diffstat (limited to 'src/lib/utils.ts')
-rw-r--r--src/lib/utils.ts37
1 files changed, 15 insertions, 22 deletions
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index e6f85ff..5d8ecc8 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -70,12 +70,14 @@ export function formattingCodeToHtml(formatted: string): string {
export function removeFormattingCode(formatted: string): string {
return formatted.replace(new RegExp(colorCodeCharacter + '.', 'g'), '')
}
-function moveStringToEnd(word: string, thing: string) {
+
+function moveToEndOfId(word: string, thing: string) {
if (thing.startsWith(`${word}_`))
- thing = thing.substr(`${word}_`.length) + `_${word}`
+ thing = thing.slice(`${word}_`.length) + `_${word}`
return thing
}
-function millisecondsToTime(totalMilliseconds: number) {
+
+export function millisecondsToTime(totalMilliseconds: number) {
const totalSeconds = totalMilliseconds / 1000
const totalMinutes = totalSeconds / 60
const totalHours = totalMinutes / 60
@@ -98,29 +100,20 @@ function millisecondsToTime(totalMilliseconds: number) {
else if (milliseconds == 1) stringUnits.push(`${milliseconds} millisecond`)
return stringUnits.slice(0, 2).join(' and ')
}
-export function cleanNumber(number: number, unit?: string): string {
- switch (unit) {
- case 'time':
- return millisecondsToTime(number)
- case 'date':
- return (new Date(number * 1000)).toUTCString()
- }
- return number.toLocaleString() + (unit ? (' ' + unit) : '')
-}
-export function clean(thing: string | number) {
- if (typeof thing === 'number') {
- return cleanNumber(thing)
- } else {
- for (const string of ['deaths', 'kills', 'collection', 'skill'])
- thing = moveStringToEnd(string, thing)
- return thing
- .replace(/^./, thing[0].toUpperCase())
- .replace(/_/g, ' ')
- }
+
+export function cleanId(id: string) {
+ for (const string of ['deaths', 'kills', 'collection', 'skill'])
+ id = moveToEndOfId(string, id)
+
+ return id
+ .replace(/^./, id[0].toUpperCase())
+ .replace(/_/g, ' ')
}
+
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]
}
+
export function shuffle<T>(a: T[]): T[] {
for (let i = a.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1))