socketioMEANseed/server/node_modules/has-binary/index.js
server/node_modules/has-binary/index.jsRaw
1
2/*
3 * Module requirements.
4 */
5
6var isArray = require('isarray');
7
8/**
9 * Module exports.
10 */
11
12module.exports = hasBinary;
13
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 */
22
23function hasBinary(data) {
24
25 function _hasBinary(obj) {
26 if (!obj) return false;
27
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;
34 }
35
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 }
54
55 return false;
56 }
57
58 return _hasBinary(data);
59}