0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch.git synced 2025-01-03 11:20:07 -05:00

Add mixins

This commit is contained in:
dragongoose 2023-06-18 23:42:40 -04:00
parent 6fb581f7fe
commit 2687a5d292
No known key found for this signature in database
GPG key ID: 50DB99B921579009

40
src/mixins.ts Normal file
View file

@ -0,0 +1,40 @@
export function truncate(value: string, length: number) {
if (value.length > length) {
return value.substring(0, length) + '...'
} else {
return value
}
}
export function abbreviate(text: number) {
return Intl.NumberFormat('en-US', {
//@ts-ignore
notation: 'compact',
maximumFractionDigits: 1
}).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}`
export async function getEndpoint(endpoint: string) {
let data
try {
const res = await fetch(rootBackendUrl + endpoint)
const rawData = await res.json()
if (rawData.status === 'ok') {
data = rawData.data
} else {
data = { status: 'error' }
}
} catch (error) {
console.error(error)
data = { status: 'error' }
}
return data
}