source: trip-planner-front/node_modules/socket.io-parser/dist/is-binary.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[6a3a178]1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.hasBinary = exports.isBinary = void 0;
4const withNativeArrayBuffer = typeof ArrayBuffer === "function";
5const isView = (obj) => {
6 return typeof ArrayBuffer.isView === "function"
7 ? ArrayBuffer.isView(obj)
8 : obj.buffer instanceof ArrayBuffer;
9};
10const toString = Object.prototype.toString;
11const withNativeBlob = typeof Blob === "function" ||
12 (typeof Blob !== "undefined" &&
13 toString.call(Blob) === "[object BlobConstructor]");
14const withNativeFile = typeof File === "function" ||
15 (typeof File !== "undefined" &&
16 toString.call(File) === "[object FileConstructor]");
17/**
18 * Returns true if obj is a Buffer, an ArrayBuffer, a Blob or a File.
19 *
20 * @private
21 */
22function isBinary(obj) {
23 return ((withNativeArrayBuffer && (obj instanceof ArrayBuffer || isView(obj))) ||
24 (withNativeBlob && obj instanceof Blob) ||
25 (withNativeFile && obj instanceof File));
26}
27exports.isBinary = isBinary;
28function hasBinary(obj, toJSON) {
29 if (!obj || typeof obj !== "object") {
30 return false;
31 }
32 if (Array.isArray(obj)) {
33 for (let i = 0, l = obj.length; i < l; i++) {
34 if (hasBinary(obj[i])) {
35 return true;
36 }
37 }
38 return false;
39 }
40 if (isBinary(obj)) {
41 return true;
42 }
43 if (obj.toJSON &&
44 typeof obj.toJSON === "function" &&
45 arguments.length === 1) {
46 return hasBinary(obj.toJSON(), true);
47 }
48 for (const key in obj) {
49 if (Object.prototype.hasOwnProperty.call(obj, key) && hasBinary(obj[key])) {
50 return true;
51 }
52 }
53 return false;
54}
55exports.hasBinary = hasBinary;
Note: See TracBrowser for help on using the repository browser.