1
0
Fork 1
mirror of https://github.com/elk-zone/elk.git synced 2024-11-19 07:19:58 +00:00
elk/composables/misc.ts
renovate[bot] 3c43a1cdd1
chore(deps): update lint (#1928)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
2023-03-30 19:01:24 +00:00

43 lines
1.2 KiB
TypeScript

import type { mastodon } from 'masto'
export const UserLinkRE = /^https?:\/\/([^/]+)\/@([^/]+)$/
export const TagLinkRE = /^https?:\/\/([^/]+)\/tags\/([^/]+)$/
export const HTMLTagRE = /<[^>]+>/g
export function getDataUrlFromArr(arr: Uint8ClampedArray, w: number, h: number) {
if (typeof w === 'undefined' || typeof h === 'undefined')
w = h = Math.sqrt(arr.length / 4)
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')!
canvas.width = w
canvas.height = h
const imgData = ctx.createImageData(w, h)
imgData.data.set(arr)
ctx.putImageData(imgData, 0, 0)
return canvas.toDataURL()
}
export function emojisArrayToObject(emojis: mastodon.v1.CustomEmoji[]) {
return Object.fromEntries(emojis.map(i => [i.shortcode, i]))
}
export function noop() {}
export function useIsMac() {
const headers = useRequestHeaders(['user-agent'])
return computed(() => headers['user-agent']?.includes('Macintosh')
?? navigator?.platform?.includes('Mac') ?? false)
}
export function isEmptyObject(object: Object) {
return Object.keys(object).length === 0
}
export function removeHTMLTags(str: string) {
return str.replaceAll(HTMLTagRE, '')
}