[apps/tidep0084.git] / example / iot-gateway / node_modules / engine.io-parser / node_modules / has-binary / index.js
2 /*
3 * Module requirements.
4 */
6 var isArray = require('isarray');
8 /**
9 * Module exports.
10 */
12 module.exports = hasBinary;
14 /**
15 * Checks for binary data.
16 *
17 * Right now only Buffer and ArrayBuffer are supported..
18 *
19 * @param {Object} anything
20 * @api public
21 */
23 function hasBinary(data) {
25 function _hasBinary(obj) {
26 if (!obj) return false;
28 if ( (global.Buffer && 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;
34 }
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 if (obj.toJSON) {
44 obj = obj.toJSON();
45 }
47 for (var key in obj) {
48 if (Object.prototype.hasOwnProperty.call(obj, key) && _hasBinary(obj[key])) {
49 return true;
50 }
51 }
52 }
54 return false;
55 }
57 return _hasBinary(data);
58 }