7 var isArray = require('isarray');
9 var toString = Object.prototype.toString;
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]';
19 module.exports = hasBinary;
22 * Checks for binary data.
24 * Supports Buffer, ArrayBuffer, Blob and File.
26 * @param {Object} anything
30 function hasBinary (obj) {
31 if (!obj || typeof obj !== 'object') {
36 for (var i = 0, l = obj.length; i < l; i++) {
37 if (hasBinary(obj[i])) {
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)
52 // see: https://github.com/Automattic/has-binary/pull/4
53 if (obj.toJSON && typeof obj.toJSON === 'function' && arguments.length === 1) {
54 return hasBinary(obj.toJSON(), true);
57 for (var key in obj) {
58 if (Object.prototype.hasOwnProperty.call(obj, key) && hasBinary(obj[key])) {