root / HServer / 00.Server / 00.Program / node_modules / has-binary2 / index.js
이력 | 보기 | 이력해설 | 다운로드 (1.42 KB)
1 |
/* global Blob File */
|
---|---|
2 |
|
3 |
/*
|
4 |
* Module requirements.
|
5 |
*/
|
6 |
|
7 |
var isArray = require('isarray'); |
8 |
|
9 |
var toString = Object.prototype.toString;
|
10 |
var withNativeBlob = typeof global.Blob === 'function' || toString.call(global.Blob) === '[object BlobConstructor]'; |
11 |
var withNativeFile = typeof global.File === 'function' || toString.call(global.File) === '[object FileConstructor]'; |
12 |
|
13 |
/**
|
14 |
* Module exports.
|
15 |
*/
|
16 |
|
17 |
module.exports = hasBinary; |
18 |
|
19 |
/**
|
20 |
* Checks for binary data.
|
21 |
*
|
22 |
* Supports Buffer, ArrayBuffer, Blob and File.
|
23 |
*
|
24 |
* @param {Object} anything
|
25 |
* @api public
|
26 |
*/
|
27 |
|
28 |
function hasBinary (obj) { |
29 |
if (!obj || typeof obj !== 'object') { |
30 |
return false; |
31 |
} |
32 |
|
33 |
if (isArray(obj)) {
|
34 |
for (var i = 0, l = obj.length; i < l; i++) { |
35 |
if (hasBinary(obj[i])) {
|
36 |
return true; |
37 |
} |
38 |
} |
39 |
return false; |
40 |
} |
41 |
|
42 |
if ((typeof global.Buffer === 'function' && global.Buffer.isBuffer && global.Buffer.isBuffer(obj)) || |
43 |
(typeof global.ArrayBuffer === 'function' && obj instanceof ArrayBuffer) || |
44 |
(withNativeBlob && obj instanceof Blob) ||
|
45 |
(withNativeFile && obj instanceof File)
|
46 |
) { |
47 |
return true; |
48 |
} |
49 |
|
50 |
// see: https://github.com/Automattic/has-binary/pull/4
|
51 |
if (obj.toJSON && typeof obj.toJSON === 'function' && arguments.length === 1) { |
52 |
return hasBinary(obj.toJSON(), true); |
53 |
} |
54 |
|
55 |
for (var key in obj) { |
56 |
if (Object.prototype.hasOwnProperty.call(obj, key) && hasBinary(obj[key])) {
|
57 |
return true; |
58 |
} |
59 |
} |
60 |
|
61 |
return false; |
62 |
} |