0
# lodash.isobject
1
2
A standalone implementation of lodash's `_.isObject` utility function that checks if a value is the ECMAScript language type of Object. This modular build provides a lightweight, zero-dependency alternative to importing the entire lodash library when only the isObject functionality is needed.
3
4
## Package Information
5
6
- **Package Name**: lodash.isobject
7
- **Package Type**: npm
8
- **Language**: JavaScript
9
- **Installation**: `npm install lodash.isobject`
10
11
## Core Imports
12
13
```javascript
14
const isObject = require('lodash.isobject');
15
```
16
17
## Basic Usage
18
19
```javascript
20
const isObject = require('lodash.isobject');
21
22
// Objects return true
23
console.log(isObject({})); // => true
24
console.log(isObject({ a: 1 })); // => true
25
26
// Arrays are objects
27
console.log(isObject([1, 2, 3])); // => true
28
console.log(isObject([])); // => true
29
30
// Functions are objects
31
console.log(isObject(function() {})); // => true
32
console.log(isObject(() => {})); // => true
33
34
// Regular expressions are objects
35
console.log(isObject(/abc/)); // => true
36
37
// Boxed primitives are objects
38
console.log(isObject(new Number(5))); // => true
39
console.log(isObject(new String(''))); // => true
40
41
// Primitives and null return false
42
console.log(isObject(null)); // => false
43
console.log(isObject(undefined)); // => false
44
console.log(isObject('string')); // => false
45
console.log(isObject(42)); // => false
46
console.log(isObject(true)); // => false
47
```
48
49
## Capabilities
50
51
### Object Type Checking
52
53
Checks if a value is the ECMAScript language type of Object, including arrays, functions, objects, regexes, and boxed primitives.
54
55
```javascript { .api }
56
/**
57
* Checks if `value` is the ECMAScript language type of `Object`.
58
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
59
*
60
* @param {*} value The value to check.
61
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
62
*/
63
function isObject(value);
64
```
65
66
**Parameters:**
67
- `value` (*): The value to check
68
69
**Returns:**
70
- `boolean`: Returns `true` if `value` is an object, else `false`
71
72
**Behavior:**
73
- Returns `true` for ECMAScript language type of Object, which includes:
74
- Plain objects (`{}`)
75
- Arrays (`[]`)
76
- Functions (`function() {}`)
77
- Regular expressions (`/pattern/`)
78
- Dates (`new Date()`)
79
- Boxed primitives (`new Number()`, `new String()`, `new Boolean()`)
80
- Other object instances
81
- Returns `false` for:
82
- `null` (special case: `typeof null === 'object'` but `null` is falsy)
83
- `undefined`
84
- Primitive strings, numbers, booleans, symbols, and bigints
85
- Implementation: `!!value && (typeof value == 'object' || typeof value == 'function')`
86
87
**Usage Examples:**
88
89
```javascript
90
const isObject = require('lodash.isobject');
91
92
// Different object types
93
isObject({}); // => true
94
isObject({ name: 'John' }); // => true
95
isObject([1, 2, 3]); // => true
96
isObject(function hello() {}); // => true
97
isObject(/pattern/); // => true
98
isObject(new Date()); // => true
99
isObject(new Number(42)); // => true
100
101
// Non-object types
102
isObject(null); // => false
103
isObject(undefined); // => false
104
isObject('hello'); // => false
105
isObject(123); // => false
106
isObject(true); // => false
107
isObject(Symbol('sym')); // => false
108
```