diff --git a/snippets/isPlainObject.md b/snippets/isPlainObject.md new file mode 100644 index 000000000..af27f16fe --- /dev/null +++ b/snippets/isPlainObject.md @@ -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 +``` diff --git a/tag_database b/tag_database index 984f905b7..d1cd81502 100644 --- a/tag_database +++ b/tag_database @@ -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