@@ -14,46 +14,45 @@ module.exports = hasBinary;
14
14
/**
15
15
* Checks for binary data.
16
16
*
17
- * Right now only Buffer and ArrayBuffer are supported. .
17
+ * Supports Buffer, ArrayBuffer, Blob and File .
18
18
*
19
19
* @param {Object } anything
20
20
* @api public
21
21
*/
22
22
23
- function hasBinary ( data ) {
23
+ function hasBinary ( obj ) {
24
24
25
- function _hasBinary ( obj ) {
26
- if ( ! obj ) return false ;
25
+ if ( ! obj || typeof obj !== 'object' ) {
26
+ return false ;
27
+ }
27
28
28
- if ( ( global . Buffer && global . Buffer . isBuffer && global . Buffer . isBuffer ( obj ) ) ||
29
- ( global . ArrayBuffer && obj instanceof ArrayBuffer ) ||
30
- ( global . Blob && obj instanceof Blob ) ||
31
- ( global . File && obj instanceof File )
32
- ) {
33
- return true ;
29
+ if ( isArray ( obj ) ) {
30
+ for ( var i = 0 , l = obj . length ; i < l ; i ++ ) {
31
+ if ( hasBinary ( obj [ i ] ) ) {
32
+ return true ;
33
+ }
34
34
}
35
+ return false ;
36
+ }
35
37
36
- if ( isArray ( obj ) ) {
37
- for ( var i = 0 ; i < obj . length ; i ++ ) {
38
- if ( _hasBinary ( obj [ i ] ) ) {
39
- return true ;
40
- }
41
- }
42
- } else if ( obj && 'object' == typeof obj ) {
43
- // see: https://github.com/Automattic/has-binary/pull/4
44
- if ( obj . toJSON && 'function' == typeof obj . toJSON ) {
45
- obj = obj . toJSON ( ) ;
46
- }
47
-
48
- for ( var key in obj ) {
49
- if ( Object . prototype . hasOwnProperty . call ( obj , key ) && _hasBinary ( obj [ key ] ) ) {
50
- return true ;
51
- }
52
- }
53
- }
38
+ if ( ( global . Buffer && global . Buffer . isBuffer && global . Buffer . isBuffer ( obj ) ) ||
39
+ ( global . ArrayBuffer && obj instanceof ArrayBuffer ) ||
40
+ ( global . Blob && obj instanceof Blob ) ||
41
+ ( global . File && obj instanceof File )
42
+ ) {
43
+ return true ;
44
+ }
54
45
55
- return false ;
46
+ // see: https://github.com/Automattic/has-binary/pull/4
47
+ if ( obj . toJSON && 'function' == typeof obj . toJSON ) {
48
+ obj = obj . toJSON ( ) ;
49
+ }
50
+
51
+ for ( var key in obj ) {
52
+ if ( Object . prototype . hasOwnProperty . call ( obj , key ) && hasBinary ( obj [ key ] ) ) {
53
+ return true ;
54
+ }
56
55
}
57
56
58
- return _hasBinary ( data ) ;
57
+ return false ;
59
58
}
0 commit comments