or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

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

0

# lodash.isbuffer

1

2

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

3

4

## Package Information

5

6

- **Package Name**: lodash.isbuffer

7

- **Package Type**: npm

8

- **Language**: JavaScript

9

- **Installation**: `npm install lodash.isbuffer`

10

11

## Core Imports

12

13

```javascript

14

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

15

```

16

17

For environments with ES module support:

18

19

```javascript

20

import isBuffer from 'lodash.isbuffer';

21

```

22

23

## Basic Usage

24

25

```javascript

26

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

27

28

// Check if a value is a Buffer (Node.js environment)

29

isBuffer(Buffer.from('hello'));

30

// => true

31

32

isBuffer(Buffer.alloc(10));

33

// => true

34

35

// Check non-Buffer values

36

isBuffer(new Uint8Array(2));

37

// => false

38

39

isBuffer('hello');

40

// => false

41

42

isBuffer([1, 2, 3]);

43

// => false

44

45

isBuffer(null);

46

// => false

47

48

isBuffer(undefined);

49

// => false

50

```

51

52

## Capabilities

53

54

### Buffer Detection

55

56

Checks if a value is a Node.js Buffer object.

57

58

```javascript { .api }

59

/**

60

* Checks if `value` is a buffer.

61

*

62

* @static

63

* @memberOf _

64

* @since 4.3.0

65

* @category Lang

66

* @param {*} value The value to check.

67

* @returns {boolean} Returns `true` if `value` is a buffer, else `false`.

68

* @example

69

*

70

* _.isBuffer(Buffer.from('hello'));

71

* // => true

72

*

73

* _.isBuffer(new Uint8Array(2));

74

* // => false

75

*/

76

function isBuffer(value);

77

```

78

79

**Parameters:**

80

- `value` (*): The value to check

81

82

**Returns:**

83

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

84

85

**Environment Behavior:**

86

- **Node.js**: Uses native `Buffer.isBuffer()` method when available

87

- **Browser/Non-Buffer environments**: Always returns `false` (uses `stubFalse` fallback function)

88

89

**Implementation Details:**

90

- Uses conditional logic: `var isBuffer = nativeIsBuffer || stubFalse`

91

- The `stubFalse` function always returns `false` and serves as a safe fallback in environments without Buffer support

92

93

**Usage Examples:**

94

95

```javascript

96

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

97

98

// Node.js Buffer objects

99

isBuffer(Buffer.from('hello'));

100

// => true

101

102

isBuffer(Buffer.alloc(10));

103

// => true

104

105

// Similar-looking objects that are not Buffers

106

isBuffer(new Uint8Array([1, 2, 3]));

107

// => false

108

109

isBuffer(new ArrayBuffer(8));

110

// => false

111

112

// Other data types

113

isBuffer('not a buffer');

114

// => false

115

116

isBuffer(42);

117

// => false

118

119

isBuffer({ length: 5 });

120

// => false

121

122

isBuffer([1, 2, 3, 4, 5]);

123

// => false

124

```

125

126

## Environment Compatibility

127

128

The module is designed to work across different JavaScript environments:

129

130

- **Node.js**: Full functionality using native `Buffer.isBuffer()` method

131

- **Browser**: Safe fallback that always returns `false` since Buffers don't exist in browser environments

132

- **Universal builds**: Automatically detects environment and uses appropriate implementation

133

134

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.