UNPKG

711 BJavaScriptView Raw
1// Copyright 2017-2022 @polkadot/util authors & contributors
2// SPDX-License-Identifier: Apache-2.0
3import { hasBuffer } from "../has.js";
4import { isFunction } from "./function.js";
5/**
6 * @name isBuffer
7 * @summary Tests for a `Buffer` object instance.
8 * @description
9 * Checks to see if the input object is an instance of `Buffer`.
10 * @example
11 * <BR>
12 *
13 * ```javascript
14 * import { isBuffer } from '@polkadot/util';
15 *
16 * console.log('isBuffer', isBuffer(Buffer.from([]))); // => true
17 * ```
18 */
19
20export function isBuffer(value) {
21 // we do check a function first, since it is slightly faster than isBuffer itself
22 return hasBuffer && isFunction(value && value.readDoubleLE) && Buffer.isBuffer(value);
23}
\No newline at end of file