Skip to content

Commit 91aa21e

Browse files
amitportdarrachequesne
authored andcommitted
fix: avoid use of global (#4)
Related: socketio/socket.io-client#1166
1 parent 02266c0 commit 91aa21e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
var isArray = require('isarray');
88

99
var toString = Object.prototype.toString;
10-
var withNativeBlob = typeof global.Blob === 'function' || toString.call(global.Blob) === '[object BlobConstructor]';
11-
var withNativeFile = typeof global.File === 'function' || toString.call(global.File) === '[object FileConstructor]';
10+
var withNativeBlob = typeof Blob === 'function' ||
11+
typeof Blob !== 'undefined' && toString.call(Blob) === '[object BlobConstructor]';
12+
var withNativeFile = typeof File === 'function' ||
13+
typeof File !== 'undefined' && toString.call(File) === '[object FileConstructor]';
1214

1315
/**
1416
* Module exports.
@@ -39,11 +41,11 @@ function hasBinary (obj) {
3941
return false;
4042
}
4143

42-
if ((typeof global.Buffer === 'function' && global.Buffer.isBuffer && global.Buffer.isBuffer(obj)) ||
43-
(typeof global.ArrayBuffer === 'function' && obj instanceof ArrayBuffer) ||
44-
(withNativeBlob && obj instanceof Blob) ||
45-
(withNativeFile && obj instanceof File)
46-
) {
44+
if ((typeof Buffer === 'function' && Buffer.isBuffer && Buffer.isBuffer(obj)) ||
45+
(typeof ArrayBuffer === 'function' && obj instanceof ArrayBuffer) ||
46+
(withNativeBlob && obj instanceof Blob) ||
47+
(withNativeFile && obj instanceof File)
48+
) {
4749
return true;
4850
}
4951

0 commit comments

Comments
 (0)