mirror of
https://codeberg.org/SafeTwitch/safetwitch.git
synced 2024-12-22 05:12:57 -05:00
Cleanup
This commit is contained in:
parent
d7d4132b9b
commit
b3b121ba31
1 changed files with 18 additions and 7 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue