arnaucube
arnaucube/raspberryGPIOhtmlserverPublic Self-hosted repository
raspberryGPIOhtmlserver/node_modules/has-binary-data/index.js
node_modules/has-binary-data/index.jsRaw
 1/*
 2 * Module requirements.
 3 */
 4
 5var isArray = require('isarray');
 6
 7/**
 8 * Module exports.
 9 */
10
11module.exports = hasBinary;
12
13/**
14 * Checks for binary data.
15 *
16 * Right now only Buffer and ArrayBuffer are supported..
17 *
18 * @param {Object} anything
19 * @api public
20 */
21
22function hasBinary(data) {
23
24  function _hasBinary(obj) {
25    if (!obj) return false;
26
27    if ( (global.Buffer && Buffer.isBuffer(obj)) ||
28         (global.ArrayBuffer && obj instanceof ArrayBuffer) ||
29         (global.Blob && obj instanceof Blob) ||
30         (global.File && obj instanceof File)
31        ) {
32      return true;
33    }
34
35    if (isArray(obj)) {
36      for (var i = 0; i < obj.length; i++) {
37          if (_hasBinary(obj[i])) {
38              return true;
39          }
40      }
41    } else if (obj && 'object' == typeof obj) {
42      if (obj.toJSON) {
43        obj = obj.toJSON();
44      }
45
46      for (var key in obj) {
47        if (obj.hasOwnProperty(key) && _hasBinary(obj[key])) {
48          return true;
49        }
50      }
51    }
52
53    return false;
54  }
55
56  return _hasBinary(data);
57}