From a8c43d37e4fd056a66af1bfc1ffe5e01649971db Mon Sep 17 00:00:00 2001 From: David Frank Date: Thu, 16 May 2019 16:15:58 +0800 Subject: [PATCH] readme and test update --- README.md | 37 +++++++++++++++++++++++++++++++++++-- test.js | 11 ++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9f2ff5d..5994639 100644 --- a/README.md +++ b/README.md @@ -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 \ No newline at end of file +## 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 diff --git a/test.js b/test.js index f6ad57a..91fed6f 100644 --- a/test.js +++ b/test.js @@ -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); +});