readme and test update
This commit is contained in:
@@ -1,5 +1,38 @@
|
||||
# fetch-blob
|
||||
|
||||
fetch-blob
|
||||
==========
|
||||
|
||||
[![npm version][npm-image]][npm-url]
|
||||
[![build status][travis-image]][travis-url]
|
||||
[![coverage status][codecov-image]][codecov-url]
|
||||
[![install size][install-size-image]][install-size-url]
|
||||
|
||||
A Blob implementation on node.js, originally from node-fetch
|
||||
|
||||
See [MDN doc](https://developer.mozilla.org/en-US/docs/Web/API/Blob) and [Tests](https://github.com/bitinn/fetch-blob/blob/master/test.js) for details
|
||||
## Usage
|
||||
|
||||
```sh
|
||||
$ npm install fetch-blob
|
||||
```
|
||||
|
||||
```js
|
||||
const Blob = require('fetch-blob');
|
||||
const fetch = require('node-fetch');
|
||||
fetch('https://httpbin.org/post', {
|
||||
method: 'POST',
|
||||
body: new Blob(['hello'], { type: 'text/plain' })
|
||||
})
|
||||
.then(res => res.json()) // expecting a json response
|
||||
.then(json => console.log(json));
|
||||
```
|
||||
|
||||
See [MDN doc](https://developer.mozilla.org/en-US/docs/Web/API/Blob) and [Tests](https://github.com/bitinn/fetch-blob/blob/master/test.js) for more details.
|
||||
|
||||
[npm-image]: https://flat.badgen.net/npm/v/fetch-blob
|
||||
[npm-url]: https://www.npmjs.com/package/fetch-blob
|
||||
[travis-image]: https://flat.badgen.net/travis/bitinn/fetch-blob
|
||||
[travis-url]: https://travis-ci.org/bitinn/fetch-blob
|
||||
[codecov-image]: https://flat.badgen.net/codecov/c/github/bitinn/fetch-blob/master
|
||||
[codecov-url]: https://codecov.io/gh/bitinn/fetch-blob
|
||||
[install-size-image]: https://flat.badgen.net/packagephobia/install/fetch-blob
|
||||
[install-size-url]: https://packagephobia.now.sh/result?p=fetch-blob
|
||||
|
||||
@@ -68,7 +68,7 @@ test('Blob slice()', async t => {
|
||||
t.is(await blob2.text(), data.slice(0, 1));
|
||||
});
|
||||
|
||||
test('Blob works with node-fetch Response', async t => {
|
||||
test('Blob works with node-fetch Response.blob()', async t => {
|
||||
let data = 'a=1';
|
||||
let type = 'text/plain';
|
||||
let blob = new Blob([data], { type });
|
||||
@@ -76,3 +76,12 @@ test('Blob works with node-fetch Response', async t => {
|
||||
let blob2 = await res.blob();
|
||||
t.is(await blob2.text(), data);
|
||||
});
|
||||
|
||||
test('Blob works with node-fetch Response.text()', async t => {
|
||||
let data = 'a=1';
|
||||
let type = 'text/plain';
|
||||
let blob = new Blob([data], { type });
|
||||
let res = new Response(blob);
|
||||
let text = await res.text();
|
||||
t.is(text, data);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user