refactor: tidy composables
This commit is contained in:
parent
bf8070c4b9
commit
e0741d58a9
14 changed files with 177 additions and 175 deletions
38
composables/misc.ts
Normal file
38
composables/misc.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
import type { Emoji } 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: Emoji[]) {
|
||||
return Object.fromEntries(emojis.map(i => [i.shortcode, i]))
|
||||
}
|
||||
|
||||
export function noop() {}
|
||||
|
||||
export const useIsMac = () => computed(() =>
|
||||
useRequestHeaders(['user-agent'])['user-agent']?.includes('Macintosh')
|
||||
?? navigator?.platform?.includes('Mac') ?? false)
|
||||
|
||||
export const isEmptyObject = (object: Object) => Object.keys(object).length === 0
|
||||
|
||||
export function removeHTMLTags(str: string) {
|
||||
return str.replaceAll(HTMLTagRE, '')
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue