From cc78f490dd282d13cf59723fdba2c3b0bc9872ab Mon Sep 17 00:00:00 2001 From: Amit Portnoy <1131991+amitport@users.noreply.github.com> Date: Fri, 29 Jun 2018 13:48:33 +0300 Subject: [PATCH] avoid using global global is not standard in the browser (yet?), using it blocks using this lib with some build tools (e.g., angular-cli with socket.io imports) --- index.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 53eaf0b..9168826 100644 --- a/index.js +++ b/index.js @@ -2,10 +2,11 @@ * Create a blob builder even when vendor prefixes exist */ -var BlobBuilder = global.BlobBuilder - || global.WebKitBlobBuilder - || global.MSBlobBuilder - || global.MozBlobBuilder; +var BlobBuilder = typeof BlobBuilder !== 'undefined' ? BlobBuilder : + typeof WebKitBlobBuilder !== 'undefined' ? WebKitBlobBuilder : + typeof MSBlobBuilder !== 'undefined' ? MSBlobBuilder : + typeof MozBlobBuilder !== 'undefined' ? MozBlobBuilder : + false; /** * Check if Blob constructor is supported @@ -83,14 +84,14 @@ function BlobConstructor(ary, options) { return new Blob(mapArrayBufferViews(ary), options || {}); }; -if (global.Blob) { +if (typeof Blob !== 'undefined') { BlobBuilderConstructor.prototype = Blob.prototype; BlobConstructor.prototype = Blob.prototype; } module.exports = (function() { if (blobSupported) { - return blobSupportsArrayBufferView ? global.Blob : BlobConstructor; + return blobSupportsArrayBufferView ? Blob : BlobConstructor; } else if (blobBuilderSupported) { return BlobBuilderConstructor; } else {