Files
common/packages/util/src/is/buffer.ts
T
Jaco a4256de444 Small u8aToU8a optimizations (#1498)
* Small u8aToU8a optimizations

* Slight order adjustments

* Adjust
2022-05-24 16:42:58 +03:00

25 lines
746 B
TypeScript

// 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
* <BR>
*
* ```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);
}