This commit is contained in:
dragongoose 2023-11-04 19:49:20 -04:00
parent d7d4132b9b
commit b3b121ba31
No known key found for this signature in database
GPG Key ID: 01397EEC371CDAA5

View File

@ -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) { export function truncate(value: string, length: number) {
if (value.length > length) { if (value.length > length) {
return value.substring(0, 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) { export function abbreviate(text: number) {
return Intl.NumberFormat(language, { return Intl.NumberFormat(language, {
//@ts-ignore //@ts-ignore
@ -16,10 +20,11 @@ export function abbreviate(text: number) {
}).format(text) }).format(text)
} }
const https = import.meta.env.SAFETWITCH_HTTPS.slice() === 'true' /**
const protocol = https ? 'https://' : 'http://' * Gets the response from an endpoint from the backend
const rootBackendUrl = `${protocol}${import.meta.env.SAFETWITCH_BACKEND_DOMAIN}/` * @param endpoint The endpoint to get data from
* @returns The data from the enpoint
*/
export async function getEndpoint(endpoint: string) { export async function getEndpoint(endpoint: string) {
const res = await fetch(rootBackendUrl + endpoint, { const res = await fetch(rootBackendUrl + endpoint, {
method: 'GET', method: 'GET',
@ -41,6 +46,11 @@ export async function getEndpoint(endpoint: string) {
return data return data
} }
/**
* Converts a twitch timestamp (0h0m0s) to seconds
* @param query 0h0m0s
* @returns the seconds of the timestamp
*/
export function getTimeFromQuery(query: string) { export function getTimeFromQuery(query: string) {
// H, M, S // H, M, S
const x = query.split(/[^0-9.]/g); const x = query.split(/[^0-9.]/g);
@ -51,4 +61,5 @@ export function getTimeFromQuery(query: string) {
time += times[1] * 60 time += times[1] * 60
time += times[2] time += times[2]
return time return time
} }