Socket
Socket
Sign inDemoInstall

node-fetch

Package Overview
Dependencies
Maintainers
2
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-fetch - npm Package Compare versions

Comparing version 2.4.1 to 2.5.0

8

CHANGELOG.md

@@ -8,2 +8,10 @@

## v2.5.0
- Enhance: `Response` object now includes `redirected` property.
- Enhance: `fetch()` now accepts third-party `Blob` implementation as body.
- Other: disable `package-lock.json` generation as we never commit them.
- Other: dev dependency update.
- Other: readme update.
## v2.4.1

@@ -10,0 +18,0 @@

58

lib/index.es.js

@@ -191,6 +191,3 @@ process.emitWarning("The .es.js file is deprecated. Use .mjs instead.");

body = Buffer.from(body.toString());
} else if (body instanceof Blob) {
// body is blob
body = body[BUFFER];
} else if (Buffer.isBuffer(body)) ; else if (Object.prototype.toString.call(body) === '[object ArrayBuffer]') {
} else if (isBlob(body)) ; else if (Buffer.isBuffer(body)) ; else if (Object.prototype.toString.call(body) === '[object ArrayBuffer]') {
// body is ArrayBuffer

@@ -352,14 +349,21 @@ body = Buffer.from(body);

let body = this.body;
// body is null
if (this.body === null) {
if (body === null) {
return Body.Promise.resolve(Buffer.alloc(0));
}
// body is blob
if (isBlob(body)) {
body = body.stream();
}
// body is buffer
if (Buffer.isBuffer(this.body)) {
return Body.Promise.resolve(this.body);
if (Buffer.isBuffer(body)) {
return Body.Promise.resolve(body);
}
// istanbul ignore if: should never happen
if (!(this.body instanceof Stream)) {
if (!(body instanceof Stream)) {
return Body.Promise.resolve(Buffer.alloc(0));

@@ -386,3 +390,3 @@ }

// handle stream errors
_this4.body.on('error', function (err) {
body.on('error', function (err) {
if (err.name === 'AbortError') {

@@ -398,3 +402,3 @@ // if the request was aborted, reject with this Error

_this4.body.on('data', function (chunk) {
body.on('data', function (chunk) {
if (abort || chunk === null) {

@@ -414,3 +418,3 @@ return;

_this4.body.on('end', function () {
body.on('end', function () {
if (abort) {

@@ -509,2 +513,11 @@ return;

/**
* Check if `obj` is a W3C `Blob` object (which `File` inherits from)
* @param {*} obj
* @return {boolean}
*/
function isBlob(obj) {
return typeof obj === 'object' && typeof obj.arrayBuffer === 'function' && typeof obj.type === 'string' && typeof obj.stream === 'function' && typeof obj.constructor === 'function' && typeof obj.constructor.name === 'string' && /^(Blob|File)$/.test(obj.constructor.name) && /^(Blob|File)$/.test(obj[Symbol.toStringTag]);
}
/**
* Clone body given Res/Req instance

@@ -561,3 +574,3 @@ *

return 'application/x-www-form-urlencoded;charset=UTF-8';
} else if (body instanceof Blob) {
} else if (isBlob(body)) {
// body is blob

@@ -604,2 +617,4 @@ return body.type || null;

return 0;
} else if (isBlob(body)) {
return body.size;
} else if (Buffer.isBuffer(body)) {

@@ -618,4 +633,3 @@ // body is buffer

// body is stream
// can't really do much about this
return null;
return instance.size || null;
}

@@ -637,2 +651,4 @@ }

dest.end();
} else if (isBlob(body)) {
body.stream().pipe(dest);
} else if (Buffer.isBuffer(body)) {

@@ -1062,3 +1078,4 @@ // body is buffer

statusText: opts.statusText || STATUS_CODES[status],
headers
headers,
counter: opts.counter
};

@@ -1082,2 +1099,6 @@ }

get redirected() {
return this[INTERNALS$1].counter > 0;
}
get statusText() {

@@ -1102,3 +1123,4 @@ return this[INTERNALS$1].statusText;

headers: this.headers,
ok: this.ok
ok: this.ok,
redirected: this.redirected
});

@@ -1114,2 +1136,3 @@ }

ok: { enumerable: true },
redirected: { enumerable: true },
statusText: { enumerable: true },

@@ -1535,3 +1558,4 @@ headers: { enumerable: true },

size: request.size,
timeout: request.timeout
timeout: request.timeout,
counter: request.counter
};

@@ -1538,0 +1562,0 @@

@@ -195,6 +195,3 @@ 'use strict';

body = Buffer.from(body.toString());
} else if (body instanceof Blob) {
// body is blob
body = body[BUFFER];
} else if (Buffer.isBuffer(body)) ; else if (Object.prototype.toString.call(body) === '[object ArrayBuffer]') {
} else if (isBlob(body)) ; else if (Buffer.isBuffer(body)) ; else if (Object.prototype.toString.call(body) === '[object ArrayBuffer]') {
// body is ArrayBuffer

@@ -356,14 +353,21 @@ body = Buffer.from(body);

let body = this.body;
// body is null
if (this.body === null) {
if (body === null) {
return Body.Promise.resolve(Buffer.alloc(0));
}
// body is blob
if (isBlob(body)) {
body = body.stream();
}
// body is buffer
if (Buffer.isBuffer(this.body)) {
return Body.Promise.resolve(this.body);
if (Buffer.isBuffer(body)) {
return Body.Promise.resolve(body);
}
// istanbul ignore if: should never happen
if (!(this.body instanceof Stream)) {
if (!(body instanceof Stream)) {
return Body.Promise.resolve(Buffer.alloc(0));

@@ -390,3 +394,3 @@ }

// handle stream errors
_this4.body.on('error', function (err) {
body.on('error', function (err) {
if (err.name === 'AbortError') {

@@ -402,3 +406,3 @@ // if the request was aborted, reject with this Error

_this4.body.on('data', function (chunk) {
body.on('data', function (chunk) {
if (abort || chunk === null) {

@@ -418,3 +422,3 @@ return;

_this4.body.on('end', function () {
body.on('end', function () {
if (abort) {

@@ -513,2 +517,11 @@ return;

/**
* Check if `obj` is a W3C `Blob` object (which `File` inherits from)
* @param {*} obj
* @return {boolean}
*/
function isBlob(obj) {
return typeof obj === 'object' && typeof obj.arrayBuffer === 'function' && typeof obj.type === 'string' && typeof obj.stream === 'function' && typeof obj.constructor === 'function' && typeof obj.constructor.name === 'string' && /^(Blob|File)$/.test(obj.constructor.name) && /^(Blob|File)$/.test(obj[Symbol.toStringTag]);
}
/**
* Clone body given Res/Req instance

@@ -565,3 +578,3 @@ *

return 'application/x-www-form-urlencoded;charset=UTF-8';
} else if (body instanceof Blob) {
} else if (isBlob(body)) {
// body is blob

@@ -608,2 +621,4 @@ return body.type || null;

return 0;
} else if (isBlob(body)) {
return body.size;
} else if (Buffer.isBuffer(body)) {

@@ -622,4 +637,3 @@ // body is buffer

// body is stream
// can't really do much about this
return null;
return instance.size || null;
}

@@ -641,2 +655,4 @@ }

dest.end();
} else if (isBlob(body)) {
body.stream().pipe(dest);
} else if (Buffer.isBuffer(body)) {

@@ -1066,3 +1082,4 @@ // body is buffer

statusText: opts.statusText || STATUS_CODES[status],
headers
headers,
counter: opts.counter
};

@@ -1086,2 +1103,6 @@ }

get redirected() {
return this[INTERNALS$1].counter > 0;
}
get statusText() {

@@ -1106,3 +1127,4 @@ return this[INTERNALS$1].statusText;

headers: this.headers,
ok: this.ok
ok: this.ok,
redirected: this.redirected
});

@@ -1118,2 +1140,3 @@ }

ok: { enumerable: true },
redirected: { enumerable: true },
statusText: { enumerable: true },

@@ -1539,3 +1562,4 @@ headers: { enumerable: true },

size: request.size,
timeout: request.timeout
timeout: request.timeout,
counter: request.counter
};

@@ -1542,0 +1566,0 @@

{
"name": "node-fetch",
"version": "2.4.1",
"version": "2.5.0",
"description": "A light-weight module that brings window.fetch to node.js",

@@ -20,3 +20,3 @@ "main": "lib/index",

"prepare": "npm run build",
"test": "cross-env BABEL_ENV=test mocha --require babel-register test/test.js",
"test": "cross-env BABEL_ENV=test mocha --require babel-register --throw-deprecation test/test.js",
"report": "cross-env BABEL_ENV=coverage nyc --reporter lcov --reporter text mocha -R spec test/test.js",

@@ -41,2 +41,3 @@ "coverage": "cross-env BABEL_ENV=coverage nyc --reporter json --reporter text mocha -R spec test/test.js && codecov -f coverage/coverage-final.json"

"devDependencies": {
"@ungap/url-search-params": "^0.1.2",
"abort-controller": "^1.1.0",

@@ -64,3 +65,2 @@ "abortcontroller-polyfill": "^1.3.0",

"string-to-arraybuffer": "^1.0.2",
"url-search-params": "^1.0.2",
"whatwg-url": "^5.0.0"

@@ -67,0 +67,0 @@ },

@@ -384,3 +384,2 @@ node-fetch

- `type`
- `redirected`
- `trailer`

@@ -405,2 +404,8 @@

#### response.redirected
<small>*(spec-compliant)*</small>
Convenience property representing if the request has been redirected at least once. Will evaluate to true if the internal redirect counter is greater than 0.
<a id="class-headers"></a>

@@ -515,3 +520,3 @@ ### Class: Headers

`node-fetch` v1 was maintained by [@bitinn](https://github.com/bitinn), v2 is currently maintained by [@TimothyGu](https://github.com/timothygu), v2 readme is written by [@jkantr](https://github.com/jkantr).
`node-fetch` v1 was maintained by [@bitinn](https://github.com/bitinn); v2 was maintained by [@TimothyGu](https://github.com/timothygu), [@bitinn](https://github.com/bitinn) and [@jimmywarting](https://github.com/jimmywarting); v2 readme is written by [@jkantr](https://github.com/jkantr).

@@ -522,7 +527,7 @@ ## License

[npm-image]: https://img.shields.io/npm/v/node-fetch.svg?style=flat-square
[npm-image]: https://flat.badgen.net/npm/v/node-fetch
[npm-url]: https://www.npmjs.com/package/node-fetch
[travis-image]: https://img.shields.io/travis/bitinn/node-fetch.svg?style=flat-square
[travis-image]: https://flat.badgen.net/travis/bitinn/node-fetch
[travis-url]: https://travis-ci.org/bitinn/node-fetch
[codecov-image]: https://img.shields.io/codecov/c/github/bitinn/node-fetch.svg?style=flat-square
[codecov-image]: https://flat.badgen.net/codecov/c/github/bitinn/node-fetch/master
[codecov-url]: https://codecov.io/gh/bitinn/node-fetch

@@ -529,0 +534,0 @@ [install-size-image]: https://flat.badgen.net/packagephobia/install/node-fetch

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc