UNPKG

844 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.isBuffer = void 0;
4const x_global_1 = require("@polkadot/x-global");
5const has_js_1 = require("../has.js");
6const function_js_1 = require("./function.js");
7/**
8 * @name isBuffer
9 * @summary Tests for a `Buffer` object instance.
10 * @description
11 * Checks to see if the input object is an instance of `Buffer`.
12 * @example
13 * <BR>
14 *
15 * ```javascript
16 * import { isBuffer } from '@polkadot/util';
17 *
18 * console.log('isBuffer', isBuffer(Buffer.from([]))); // => true
19 * ```
20 */
21function isBuffer(value) {
22 // we do check a function first, since it is slightly faster than isBuffer itself
23 return has_js_1.hasBuffer && !!value && (0, function_js_1.isFunction)(value.readDoubleLE) && x_global_1.xglobal.Buffer.isBuffer(value);
24}
25exports.isBuffer = isBuffer;