arnaucube
arnaucube/comunicationLeapPublic Self-hosted repository
comunicationLeap/node_modules/has-binary/index.js
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(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      if (obj.toJSON) {
44        obj = obj.toJSON();
45      }
46
47      for (var key in obj) {
48        if (obj.hasOwnProperty(key) && _hasBinary(obj[key])) {
49          return true;
50        }
51      }
52    }
53
54    return false;
55  }
56
57  return _hasBinary(data);
58}