Add isPlainObject
This commit is contained in:
14
snippets/isPlainObject.md
Normal file
14
snippets/isPlainObject.md
Normal file
@ -0,0 +1,14 @@
|
||||
### isPlainObject
|
||||
|
||||
Checks if the provided value is an bbject created by the Object constructor.
|
||||
|
||||
Check if the provided value is truthy, use `typeof` to check if it is an object and `Object.constructor` to make sure the constructor is equal to `Object`.
|
||||
|
||||
```js
|
||||
const isPlainObject = val => !!val && typeof val === 'object' && val.constructor === Object;
|
||||
```
|
||||
|
||||
```js
|
||||
isPlainObject({ 'a': 1 }); // true
|
||||
isPlainObject(new Map()); // false
|
||||
```
|
||||
@ -98,6 +98,7 @@ isNil:type
|
||||
isNull:type
|
||||
isNumber:type,math
|
||||
isObject:type,object
|
||||
isPlainObject:type,object
|
||||
isPrime:math
|
||||
isPrimitive:type,function,array,string
|
||||
isPromiseLike:type,function,promise
|
||||
|
||||
Reference in New Issue
Block a user