isBuffer
lang
Checks if value is a Buffer. Note: This method returns false in browser environments.
Installation
Import
import { isBuffer } from '@tulx/utils';Source Code
Implementation
/**
* Checks if value is a Buffer.
* Note: This method returns false in browser environments.
*
* @param value - The value to check.
* @returns Returns true if value is a Buffer, else false.
*
* @example
* ```ts
* isBuffer(Buffer.alloc(2)); // true (Node.js)
* isBuffer(new Uint8Array(2)); // false
* ```
*/
export function isBuffer(value: unknown): boolean {
// In browser environments, Buffer is not available
if (typeof Buffer === 'undefined') {
return false;
}
return Buffer.isBuffer(value);
}
Example
import { isBuffer } from '@tulx/utils';
isBuffer(Buffer.alloc(2)); // true (Node.js)
isBuffer(new Uint8Array(2)); // falseRelated Functions
castArray
Casts value as an array if it's not one.
clone
Creates a shallow clone of value.
cloneDeep
This method is like clone except that it recursively clones value.
cloneDeepWith
This method is like cloneDeep except that it accepts customizer which is invoked to produce the cloned value.
cloneWith
This method is like clone except that it accepts customizer which is invoked to produce the cloned value.
conformsTo
Checks if object conforms to source by invoking the predicate properties of source with the corresponding property values of object.