From b3b121ba31e8334060ea67ac5002d880285740b0 Mon Sep 17 00:00:00 2001 From: dragongoose Date: Sat, 4 Nov 2023 19:49:20 -0400 Subject: [PATCH] Cleanup --- src/mixins.ts | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/mixins.ts b/src/mixins.ts index f1a2c97..6638e5a 100644 --- a/src/mixins.ts +++ b/src/mixins.ts @@ -1,3 +1,9 @@ +const language = localStorage.getItem('language') || 'en-us' +const https = import.meta.env.SAFETWITCH_HTTPS.slice() === 'true' +const protocol = https ? 'https://' : 'http://' +const rootBackendUrl = `${protocol}${import.meta.env.SAFETWITCH_BACKEND_DOMAIN}/` + + export function truncate(value: string, length: number) { if (value.length > length) { return value.substring(0, length) + '...' @@ -6,8 +12,6 @@ export function truncate(value: string, length: number) { } } -const language = localStorage.getItem('language') || 'en-us' - export function abbreviate(text: number) { return Intl.NumberFormat(language, { //@ts-ignore @@ -16,10 +20,11 @@ export function abbreviate(text: number) { }).format(text) } -const https = import.meta.env.SAFETWITCH_HTTPS.slice() === 'true' -const protocol = https ? 'https://' : 'http://' -const rootBackendUrl = `${protocol}${import.meta.env.SAFETWITCH_BACKEND_DOMAIN}/` - +/** + * Gets the response from an endpoint from the backend + * @param endpoint The endpoint to get data from + * @returns The data from the enpoint + */ export async function getEndpoint(endpoint: string) { const res = await fetch(rootBackendUrl + endpoint, { method: 'GET', @@ -41,6 +46,11 @@ export async function getEndpoint(endpoint: string) { return data } +/** + * Converts a twitch timestamp (0h0m0s) to seconds + * @param query 0h0m0s + * @returns the seconds of the timestamp + */ export function getTimeFromQuery(query: string) { // H, M, S const x = query.split(/[^0-9.]/g); @@ -51,4 +61,5 @@ export function getTimeFromQuery(query: string) { time += times[1] * 60 time += times[2] return time -} \ No newline at end of file +} +