// Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 import { hasBuffer } from '../has'; import { isFunction } from './function'; /** * @name isBuffer * @summary Tests for a `Buffer` object instance. * @description * Checks to see if the input object is an instance of `Buffer`. * @example *
* * ```javascript * import { isBuffer } from '@polkadot/util'; * * console.log('isBuffer', isBuffer(Buffer.from([]))); // => true * ``` */ export function isBuffer (value: unknown): value is Buffer { // we do check a function first, since it is slightly faster than isBuffer itself return hasBuffer && isFunction(value && (value as Buffer).readDoubleLE) && Buffer.isBuffer(value); }