Last change
on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | const { FetchError, Headers, Request, Response } = require('minipass-fetch')
|
---|
2 |
|
---|
3 | const configureOptions = require('./options.js')
|
---|
4 | const fetch = require('./fetch.js')
|
---|
5 |
|
---|
6 | const makeFetchHappen = (url, opts) => {
|
---|
7 | const options = configureOptions(opts)
|
---|
8 |
|
---|
9 | const request = new Request(url, options)
|
---|
10 | return fetch(request, options)
|
---|
11 | }
|
---|
12 |
|
---|
13 | makeFetchHappen.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 |
|
---|
36 | module.exports = makeFetchHappen
|
---|
37 | module.exports.FetchError = FetchError
|
---|
38 | module.exports.Headers = Headers
|
---|
39 | module.exports.Request = Request
|
---|
40 | module.exports.Response = Response
|
---|
Note:
See
TracBrowser
for help on using the repository browser.