(url: string)
| 17 | } |
| 18 | |
| 19 | const readBase64WithFetch = (url: string) => { |
| 20 | return new Promise<string>((resolve, reject) => { |
| 21 | const xhr = new XMLHttpRequest() |
| 22 | xhr.onload = () => { |
| 23 | const reader = new FileReader() |
| 24 | reader.onloadend = () => { |
| 25 | resolve(reader.result as string) |
| 26 | } |
| 27 | reader.onerror = error => { |
| 28 | reject(error) |
| 29 | } |
| 30 | reader.readAsDataURL(xhr.response) |
| 31 | } |
| 32 | xhr.open('GET', url) |
| 33 | xhr.responseType = 'blob' |
| 34 | xhr.send() |
| 35 | }) |
| 36 | } |
| 37 | |
| 38 | export const readBase64 = (file: File | string) => { |
| 39 | return typeof file === 'string' ? readBase64WithFetch(file) : readBase64WithFileReader(file) |
no outgoing calls
no test coverage detected
searching dependent graphs…