koel/resources/assets/js/composables/useFileReader.ts

13 lines
327 B
TypeScript
Raw Normal View History

2024-03-19 22:48:12 +00:00
export const useFileReader = () => {
const reader = new FileReader()
const readAsDataUrl = (file: File, callback: (result: string) => void | Promise<void>) => {
reader.addEventListener('load', async () => await callback(reader.result as string))
reader.readAsDataURL(file)
}
return {
readAsDataUrl,
2024-03-19 22:48:12 +00:00
}
}