Tiny javascript module that, given a Response object (returned by e.g.
fetch()
), returns (a Promise of) the response body as a data:
URL.
npm install response-to-data-url
Example case, fetching some resources:
import responseToDataUrl from 'response-to-data-url'
fetch('https://example.com/pic.png')
.then(responseToDataUrl)
.then(dataUrl => {
// dataUrl === 'data:image/png;base64,somelongstringofdatahere'
})
responseToDataUrl(response)
Arguments:
- response: a Response
Returns a Promise that resolves with a string.