Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fetch-link

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-link - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

20

index.js
'use strict';
const parseLink = require('parse-link-header');
let localFetch;
const getFetchFunction = function () {
return localFetch || fetch
}
class FetchAll {

@@ -26,2 +31,4 @@ constructor(url, options) {

fetch (url, direction) {

@@ -32,3 +39,3 @@

const request = fetchOptionsPromise
.then(options => fetch(url, options))
.then(options => getFetchFunction()(url, options))

@@ -107,19 +114,22 @@ this.promises[direction === 'next' ? 'push' : 'unshift'](request);

},
setFetchImplementation: function (func) {
localFetch = func;
},
next: function (res, options) {
const link = extractLink(res);
console.log(link.next.url)
return link.next ? fetch(link.next.url, options) : Promise.reject('No next link');
return link.next ? getFetchFunction()(link.next.url, options) : Promise.reject('No next link');
},
prev: function (res, options) {
const link = extractLink(res);
return link.prev ? fetch(link.prev.url, options) : Promise.reject('No prev link');
return link.prev ? getFetchFunction()(link.prev.url, options) : Promise.reject('No prev link');
},
last: function (res, options) {
const link = extractLink(res);
return link.last ? fetch(link.last.url, options) : Promise.reject('No last link');
return link.last ? getFetchFunction()(link.last.url, options) : Promise.reject('No last link');
},
first: function (res, options) {
const link = extractLink(res);
return link.first ? fetch(link.first.url, options) : Promise.reject('No first link');
return link.first ? getFetchFunction()(link.first.url, options) : Promise.reject('No first link');
}
};
{
"name": "fetch-link",
"version": "1.2.0",
"version": "1.3.0",
"description": "Fetch related content by following Link headers",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -7,3 +7,3 @@ #fetch-link

# next, prev, first, last
# `next`, `prev`, `first`, `last`
Methods that will fetch the given linked resource if specified in the 'Link' header. Each function accepts two parameters `(res, options)` and returns a promise for a `Response`

@@ -13,3 +13,3 @@ - `res` Either a `Response` instance or the value of the `Link` header extracted from a `Response` object

# all(url, options)
# `all(url, options)`
Recursively fetches all linked resources, beginning with the given url. Returns a promise for an array of `Response` instances

@@ -22,1 +22,4 @@ - `url` The url to fetch

- `failGracefully` By default a single failed response will cause `all()` to reject with the error thrown. If `failGracefully` is true then it will continue to follow links in the opposite direction to the one which has errored and eventually resolve with a promise for an array of responses with the error returned in the first/last place. This only applies to javascript errors thrown by fetch; http errors (503 etc) count as succesful responses and if the response specifies a Link header then it will be followed as normal.
# `setFetchImplementation(func)`
Use a custom implementation of `fetch`
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