source: trip-planner-front/node_modules/make-fetch-happen/lib/index.js@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.0 KB
Line 
1const { FetchError, Headers, Request, Response } = require('minipass-fetch')
2
3const configureOptions = require('./options.js')
4const fetch = require('./fetch.js')
5
6const makeFetchHappen = (url, opts) => {
7 const options = configureOptions(opts)
8
9 const request = new Request(url, options)
10 return fetch(request, options)
11}
12
13makeFetchHappen.defaults = (defaultUrl, defaultOptions = {}) => {
14 if (typeof defaultUrl === 'object') {
15 defaultOptions = defaultUrl
16 defaultUrl = null
17 }
18
19 const defaultedFetch = (url, options = {}) => {
20 const finalUrl = url || defaultUrl
21 const finalOptions = {
22 ...defaultOptions,
23 ...options,
24 headers: {
25 ...defaultOptions.headers,
26 ...options.headers,
27 },
28 }
29 return makeFetchHappen(finalUrl, finalOptions)
30 }
31
32 defaultedFetch.defaults = makeFetchHappen.defaults
33 return defaultedFetch
34}
35
36module.exports = makeFetchHappen
37module.exports.FetchError = FetchError
38module.exports.Headers = Headers
39module.exports.Request = Request
40module.exports.Response = Response
Note: See TracBrowser for help on using the repository browser.