forked from sindresorhus/ky-universal
/
index.js
38 lines (29 loc) · 762 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
const fetch = require('node-fetch');
const AbortController = require('abort-controller');
// Extracted from https://github.com/Richienb/try-import/blob/master/index.js
function tryImport(name) {
try {
return require(name);
} catch (_) { }
}
const streams = tryImport('web-streams-polyfill/ponyfill/es2018');
if (!global.fetch) {
global.fetch = fetch;
}
if (!global.Headers) {
global.Headers = fetch.Headers;
}
if (!global.Request) {
global.Request = fetch.Request;
}
if (!global.Response) {
global.Response = fetch.Response;
}
if (!global.AbortController) {
global.AbortController = AbortController;
}
if (!global.ReadableStream && streams) {
global.ReadableStream = streams.ReadableStream;
}
module.exports = require('ky/umd');