Repository URL to install this package:
|
Version:
7.1.2-patch-delete ▾
|
import { URL, URLSearchParams } from 'url'
import realFetch from 'node-fetch'
const REALM = global as any
// this was in universal-fetch, not sure it is needed
// function mockFetch(
// this: typeof realFetch,
// url: Request | string,
// options: any
// ) {
// // add https if it is `//`
// const finalUrl =
// typeof url === 'string' && /^\/\//.test(url) ? 'https:' + url : url
// // validate when using url direct
// // otherwise node-fetch will validate
// if (typeof finalUrl === 'string' && finalUrl.startsWith('http') === false) {
// throw new TypeError('Only absolute URLs are supported: ' + url)
// }
// return realFetch.call(this, finalUrl, options)
// }
// set on global
if (!global.fetch) {
global.fetch = realFetch
global.Response = realFetch.Response
global.Headers = realFetch.Headers
global.Request = realFetch.Request
}
if (!global.URL) {
global.URL = URL
}
if (!global.URLSearchParams) {
global.URLSearchParams = URLSearchParams
}