node-fetch
Advanced tools
Comparing version 1.6.3 to 2.0.0-alpha.1
@@ -6,2 +6,31 @@ | ||
# 2.x release | ||
## v2.0.0-alpha.1 | ||
This is a major release. Check [our upgrade guide](https://github.com/bitinn/node-fetch/blob/master/UPGRADE-GUIDE.md) for an overview on some key differences between v1 and v2. | ||
- Major: Node.js 0.10.x support is dropped | ||
- Major: rewrite in transpiled ES2015 | ||
- Major: internal methods are no longer exposed | ||
- Major: throw error when a GET/HEAD Request is constructed with a non-null body (per spec) | ||
- Major: `response.text()` no longer attempts to detect encoding, instead always opting for UTF-8 (per spec); use `response.textConverted()` for the old behavior | ||
- Major: make `response.json()` throw error instead of returning an empty object on 204 no-content respose (per spec; reverts behavior set in v1.6.2) | ||
- Major: arrays as parameters to `headers.append` and `headers.set` are joined as a string (per spec) | ||
- Enhance: start testing on Node.js 4, 6, 7 | ||
- Enhance: use Rollup to produce a distributed bundle (less memory overhead and faster startup) | ||
- Enhance: make `toString()` on Headers, Requests, and Responses return correct IDL class strings | ||
- Enhance: add an option to conform to latest spec at the expense of reduced compatibility | ||
- Enhance: set `Content-Length` header for Buffers as well | ||
- Enhance: add `response.arrayBuffer()` (also applies to Requests) | ||
- Enhance: add experimental `response.blob()` (also applies to Requests) | ||
- Enhance: make Headers iterable | ||
- Enhance: make Headers constructor accept an array of tuples | ||
- Enhance: make sure header names and values are valid in HTTP | ||
- Fix: coerce Headers prototype function parameters to strings, where applicable | ||
- Fix: fix Request and Response with `null` body | ||
- Fix: support WHATWG URL objects, created by `whatwg-url` package or `require('url').URL` in Node.js 7+ | ||
- Other: use Codecov for code coverage tracking | ||
# 1.x release | ||
@@ -8,0 +37,0 @@ |
{ | ||
"name": "node-fetch", | ||
"version": "1.6.3", | ||
"description": "A light-weight module that brings window.fetch to node.js and io.js", | ||
"main": "index.js", | ||
"version": "2.0.0-alpha.1", | ||
"description": "A light-weight module that brings window.fetch to node.js", | ||
"main": "lib/index.js", | ||
"jsnext:main": "lib/index.es.js", | ||
"files": [ | ||
"lib/index.js", | ||
"lib/index.es.js" | ||
], | ||
"scripts": { | ||
"test": "mocha test/test.js", | ||
"report": "istanbul cover _mocha -- -R spec test/test.js", | ||
"coverage": "istanbul cover _mocha --report lcovonly -- -R spec test/test.js && cat ./coverage/lcov.info | coveralls" | ||
"build": "cross-env BABEL_ENV=rollup rollup -c", | ||
"prepublish": "npm run build", | ||
"test": "cross-env BABEL_ENV=test mocha --compilers js:babel-register test/test.js", | ||
"report": "cross-env BABEL_ENV=coverage nyc --reporter lcov --reporter text mocha -R spec test/test.js", | ||
"coverage": "cross-env BABEL_ENV=coverage nyc --reporter json --reporter text mocha -R spec test/test.js && codecov -f coverage/coverage-final.json" | ||
}, | ||
@@ -27,14 +34,28 @@ "repository": { | ||
"devDependencies": { | ||
"babel-plugin-istanbul": "^3.0.0", | ||
"babel-plugin-transform-runtime": "^6.15.0", | ||
"babel-preset-es2015": "^6.16.0", | ||
"babel-register": "^6.16.3", | ||
"bluebird": "^3.3.4", | ||
"chai": "^3.5.0", | ||
"chai-as-promised": "^5.2.0", | ||
"coveralls": "^2.11.2", | ||
"chai-as-promised": "^6.0.0", | ||
"chai-iterator": "^1.1.1", | ||
"chai-string": "^1.3.0", | ||
"codecov": "^1.0.1", | ||
"cross-env": "2.0.1", | ||
"form-data": ">=1.0.0", | ||
"istanbul": "^0.4.2", | ||
"mocha": "^2.1.0", | ||
"is-builtin-module": "^1.0.0", | ||
"mocha": "^3.1.2", | ||
"nyc": "^10.0.0", | ||
"parted": "^0.1.1", | ||
"promise": "^7.1.1", | ||
"resumer": "0.0.0" | ||
"resumer": "0.0.0", | ||
"rollup": "^0.37.0", | ||
"rollup-plugin-babel": "^2.6.1", | ||
"rollup-plugin-node-resolve": "^2.0.0", | ||
"whatwg-url": "^4.0.0" | ||
}, | ||
"dependencies": { | ||
"babel-runtime": "^6.11.6", | ||
"buffer-to-arraybuffer": "0.0.4", | ||
"encoding": "^0.1.11", | ||
@@ -41,0 +62,0 @@ "is-stream": "^1.0.1" |
122
README.md
@@ -7,3 +7,3 @@ | ||
[![build status][travis-image]][travis-url] | ||
[![coverage status][coveralls-image]][coveralls-url] | ||
[![coverage status][codecov-image]][codecov-url] | ||
@@ -45,15 +45,16 @@ A light-weight module that brings `window.fetch` to Node.js | ||
```javascript | ||
var fetch = require('node-fetch'); | ||
import fetch from 'node-fetch'; | ||
// or | ||
// const fetch = require('node-fetch'); | ||
// if you are on node v0.10, set a Promise library first, eg. | ||
// fetch.Promise = require('bluebird'); | ||
// if you are using your own Promise library, set it through fetch.Promise. Eg. | ||
// import Bluebird from 'bluebird'; | ||
// fetch.Promise = Bluebird; | ||
// plain text or html | ||
fetch('https://github.com/') | ||
.then(function(res) { | ||
return res.text(); | ||
}).then(function(body) { | ||
console.log(body); | ||
}); | ||
.then(res => res.text()) | ||
.then(body => console.log(body)); | ||
@@ -63,7 +64,4 @@ // json | ||
fetch('https://api.github.com/users/github') | ||
.then(function(res) { | ||
return res.json(); | ||
}).then(function(json) { | ||
console.log(json); | ||
}); | ||
.then(res => res.json()) | ||
.then(json => console.log(json)); | ||
@@ -75,5 +73,3 @@ // catching network error | ||
fetch('http://domain.invalid/') | ||
.catch(function(err) { | ||
console.log(err); | ||
}); | ||
.catch(err => console.error(err)); | ||
@@ -84,4 +80,4 @@ // stream | ||
fetch('https://assets-cdn.github.com/images/modules/logos_page/Octocat.png') | ||
.then(function(res) { | ||
var dest = fs.createWriteStream('./octocat.png'); | ||
.then(res => { | ||
const dest = fs.createWriteStream('./octocat.png'); | ||
res.body.pipe(dest); | ||
@@ -94,9 +90,8 @@ }); | ||
var fileType = require('file-type'); | ||
import fileType from 'file-type'; | ||
fetch('https://assets-cdn.github.com/images/modules/logos_page/Octocat.png') | ||
.then(function(res) { | ||
return res.buffer(); | ||
}).then(function(buffer) { | ||
fileType(buffer); | ||
}); | ||
.then(res => res.buffer()) | ||
.then(buffer => fileType(buffer)) | ||
.then(type => { /* ... */ }); | ||
@@ -106,3 +101,3 @@ // meta | ||
fetch('https://github.com/') | ||
.then(function(res) { | ||
.then(res => { | ||
console.log(res.ok); | ||
@@ -118,30 +113,34 @@ console.log(res.status); | ||
fetch('http://httpbin.org/post', { method: 'POST', body: 'a=1' }) | ||
.then(function(res) { | ||
return res.json(); | ||
}).then(function(json) { | ||
console.log(json); | ||
}); | ||
.then(res => res.json()) | ||
.then(json => console.log(json)); | ||
// post with stream from resumer | ||
// post with stream from file | ||
var resumer = require('resumer'); | ||
var stream = resumer().queue('a=1').end(); | ||
import { createReadStream } from 'fs'; | ||
const stream = createReadStream('input.txt'); | ||
fetch('http://httpbin.org/post', { method: 'POST', body: stream }) | ||
.then(function(res) { | ||
return res.json(); | ||
}).then(function(json) { | ||
console.log(json); | ||
}); | ||
.then(res => res.json()) | ||
.then(json => console.log(json)); | ||
// post with JSON | ||
var body = { a: 1 }; | ||
fetch('http://httpbin.org/post', { | ||
method: 'POST', | ||
body: JSON.stringify(body), | ||
headers: { 'Content-Type': 'application/json' }, | ||
}) | ||
.then(res => res.json()) | ||
.then(json => console.log(json)); | ||
// post with form-data (detect multipart) | ||
var FormData = require('form-data'); | ||
var form = new FormData(); | ||
import FormData from 'form-data'; | ||
const form = new FormData(); | ||
form.append('a', 1); | ||
fetch('http://httpbin.org/post', { method: 'POST', body: form }) | ||
.then(function(res) { | ||
return res.json(); | ||
}).then(function(json) { | ||
console.log(json); | ||
}); | ||
.then(res => res.json()) | ||
.then(json => console.log(json)); | ||
@@ -151,20 +150,17 @@ // post with form-data (custom headers) | ||
var FormData = require('form-data'); | ||
var form = new FormData(); | ||
import FormData from 'form-data'; | ||
const form = new FormData(); | ||
form.append('a', 1); | ||
fetch('http://httpbin.org/post', { method: 'POST', body: form, headers: form.getHeaders() }) | ||
.then(function(res) { | ||
return res.json(); | ||
}).then(function(json) { | ||
console.log(json); | ||
}); | ||
.then(res => res.json()) | ||
.then(json => console.log(json)); | ||
// node 0.12+, yield with co | ||
// node 7+ with async function | ||
var co = require('co'); | ||
co(function *() { | ||
var res = yield fetch('https://api.github.com/users/github'); | ||
var json = yield res.json(); | ||
console.log(res); | ||
}); | ||
(async function () { | ||
const res = await fetch('https://api.github.com/users/github'); | ||
const json = await res.json(); | ||
console.log(json); | ||
})(); | ||
``` | ||
@@ -187,3 +183,3 @@ | ||
default values are shown, note that only `method`, `headers`, `redirect` and `body` are allowed in `window.fetch`, others are node.js extensions. | ||
Note that only `method`, `headers`, `redirect` and `body` are allowed in `window.fetch`. Other options are node.js extensions. The default values are shown after each option key. | ||
@@ -219,3 +215,3 @@ ``` | ||
[travis-url]: https://travis-ci.org/bitinn/node-fetch | ||
[coveralls-image]: https://img.shields.io/coveralls/bitinn/node-fetch.svg?style=flat-square | ||
[coveralls-url]: https://coveralls.io/r/bitinn/node-fetch | ||
[codecov-image]: https://img.shields.io/codecov/c/github/bitinn/node-fetch.svg?style=flat-square | ||
[codecov-url]: https://codecov.io/gh/bitinn/node-fetch |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
92040
2542
0
27
4
22
6
1
207
+ Addedbabel-runtime@^6.11.6
+ Addedbuffer-to-arraybuffer@0.0.4
+ Addedbabel-runtime@6.26.0(transitive)
+ Addedbuffer-to-arraybuffer@0.0.4(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addedregenerator-runtime@0.11.1(transitive)