From adaed178a758584e3a704d76b827a28ed9432ba9 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Fri, 19 Jan 2018 13:59:12 +0200 Subject: [PATCH] Add isPlainObject --- snippets/isPlainObject.md | 14 ++++++++++++++ tag_database | 1 + 2 files changed, 15 insertions(+) create mode 100644 snippets/isPlainObject.md 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