response-to-data-url
v0.1.0
Published
Turn a fetch() response into a `data:` URL.
Downloads
6
Readme
response-to-data-url
Tiny javascript module that, given a Response object (returned by e.g.
fetch()
), returns (a Promise of) the response body as a data:
URL.
Install
npm install response-to-data-url
Use
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'
})
API
responseToDataUrl(response)
Arguments:
- response: a Response
Returns a Promise that resolves with a string.