mirror of
https://codeberg.org/SafeTwitch/safetwitch.git
synced 2025-01-24 05:08:42 -05:00
40 lines
No EOL
998 B
TypeScript
40 lines
No EOL
998 B
TypeScript
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
|
|
} |