UNPKG

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