or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-lodash-isbuffer

The lodash method _.isBuffer exported as a module for checking if a value is a Node.js Buffer object.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/lodash.isbuffer@4.3.x

To install, run

npx @tessl/cli install tessl/npm-lodash-isbuffer@4.3.0

index.mddocs/

lodash.isbuffer

lodash.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).

Package Information

  • Package Name: lodash.isbuffer
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install lodash.isbuffer

Core Imports

var isBuffer = require('lodash.isbuffer');

For environments with ES module support:

import isBuffer from 'lodash.isbuffer';

Basic Usage

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);
// => false

Capabilities

Buffer Detection

Checks 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 check

Returns:

  • boolean: Returns true if value is a buffer, else false

Environment Behavior:

  • Node.js: Uses native Buffer.isBuffer() method when available
  • Browser/Non-Buffer environments: Always returns false (uses stubFalse fallback function)

Implementation Details:

  • Uses conditional logic: var isBuffer = nativeIsBuffer || stubFalse
  • The stubFalse function always returns false and serves as a safe fallback in environments without Buffer support

Usage 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]);
// => false

Environment Compatibility

The module is designed to work across different JavaScript environments:

  • Node.js: Full functionality using native Buffer.isBuffer() method
  • Browser: Safe fallback that always returns false since Buffers don't exist in browser environments
  • Universal builds: Automatically detects environment and uses appropriate implementation

The 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.