The lodash method _.isBuffer exported as a module for checking if a value is a Node.js Buffer object.
npx @tessl/cli install tessl/npm-lodash-isbuffer@4.3.0lodash.isbuffer is a standalone JavaScript utility module that provides the lodash _.isBuffer method for checking if a value is a Node.js Buffer object. This lightweight package offers cross-environment compatibility, working in both Node.js (with Buffer support) and browser environments (without Buffer support).
npm install lodash.isbuffervar isBuffer = require('lodash.isbuffer');For environments with ES module support:
import isBuffer from 'lodash.isbuffer';var isBuffer = require('lodash.isbuffer');
// Check if a value is a Buffer (Node.js environment)
isBuffer(Buffer.from('hello'));
// => true
isBuffer(Buffer.alloc(10));
// => true
// Check non-Buffer values
isBuffer(new Uint8Array(2));
// => false
isBuffer('hello');
// => false
isBuffer([1, 2, 3]);
// => false
isBuffer(null);
// => false
isBuffer(undefined);
// => falseChecks if a value is a Node.js Buffer object.
/**
* Checks if `value` is a buffer.
*
* @static
* @memberOf _
* @since 4.3.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
* @example
*
* _.isBuffer(Buffer.from('hello'));
* // => true
*
* _.isBuffer(new Uint8Array(2));
* // => false
*/
function isBuffer(value);Parameters:
value (*): The value to checkReturns:
boolean: Returns true if value is a buffer, else falseEnvironment Behavior:
Buffer.isBuffer() method when availablefalse (uses stubFalse fallback function)Implementation Details:
var isBuffer = nativeIsBuffer || stubFalsestubFalse function always returns false and serves as a safe fallback in environments without Buffer supportUsage Examples:
var isBuffer = require('lodash.isbuffer');
// Node.js Buffer objects
isBuffer(Buffer.from('hello'));
// => true
isBuffer(Buffer.alloc(10));
// => true
// Similar-looking objects that are not Buffers
isBuffer(new Uint8Array([1, 2, 3]));
// => false
isBuffer(new ArrayBuffer(8));
// => false
// Other data types
isBuffer('not a buffer');
// => false
isBuffer(42);
// => false
isBuffer({ length: 5 });
// => false
isBuffer([1, 2, 3, 4, 5]);
// => falseThe module is designed to work across different JavaScript environments:
Buffer.isBuffer() methodfalse since Buffers don't exist in browser environmentsThe implementation includes robust environment detection to ensure it works correctly regardless of the runtime environment, making it safe to use in universal JavaScript applications that run both on the server and in the browser.