diff --git a/fetch.js b/fetch.js index 3c02d57e..f88488cd 100644 --- a/fetch.js +++ b/fetch.js @@ -1,9 +1,13 @@ +var global = (function(self) { + return self + // eslint-disable-next-line no-invalid-this +})(typeof self !== 'undefined' ? self : this) var support = { - searchParams: 'URLSearchParams' in self, - iterable: 'Symbol' in self && 'iterator' in Symbol, + searchParams: 'URLSearchParams' in global, + iterable: 'Symbol' in global && 'iterator' in Symbol, blob: - 'FileReader' in self && - 'Blob' in self && + 'FileReader' in global && + 'Blob' in global && (function() { try { new Blob() @@ -12,8 +16,8 @@ var support = { return false } })(), - formData: 'FormData' in self, - arrayBuffer: 'ArrayBuffer' in self + formData: 'FormData' in global, + arrayBuffer: 'ArrayBuffer' in global } function isDataView(obj) { @@ -435,7 +439,7 @@ Response.redirect = function(url, status) { return new Response(null, {status: status, headers: {location: url}}) } -export var DOMException = self.DOMException +export var DOMException = global.DOMException try { new DOMException() } catch (err) { @@ -496,7 +500,7 @@ export function fetch(input, init) { function fixUrl(url) { try { - return url === '' && self.location.href ? self.location.href : url + return url === '' && global.location.href ? global.location.href : url } catch (e) { return url } @@ -543,9 +547,9 @@ export function fetch(input, init) { fetch.polyfill = true -if (!self.fetch) { - self.fetch = fetch - self.Headers = Headers - self.Request = Request - self.Response = Response +if (!global.fetch) { + global.fetch = fetch + global.Headers = Headers + global.Request = Request + global.Response = Response } diff --git a/rollup.config.js b/rollup.config.js index d4297335..3ed622ca 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -3,6 +3,7 @@ export default { output: { file: 'dist/fetch.umd.js', format: 'umd', - name: 'WHATWGFetch' + name: 'WHATWGFetch', + strict: false } }