mirror of
https://codeberg.org/SafeTwitch/safetwitch.git
synced 2025-01-03 11:20:07 -05:00
Add mixins
This commit is contained in:
parent
6fb581f7fe
commit
2687a5d292
1 changed files with 40 additions and 0 deletions
40
src/mixins.ts
Normal file
40
src/mixins.ts
Normal 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
|
||||
}
|
Loading…
Reference in a new issue