diff --git a/README.md b/README.md index 08ea3212b..af92350ed 100644 --- a/README.md +++ b/README.md @@ -346,6 +346,7 @@ average(1, 2, 3); * [`isNull`](#isnull) * [`isNumber`](#isnumber) * [`isObject`](#isobject) +* [`isObjectLike`](#isobjectlike) * [`isPlainObject`](#isplainobject) * [`isPrimitive`](#isprimitive) * [`isPromiseLike`](#ispromiselike) @@ -5780,6 +5781,31 @@ isObject(true); // false
[⬆ Back to top](#table-of-contents) +### isObjectLike + +Checks if a value is object-like. + +Check if the provided value is not `null` and its `typeof` is equal to `'object'`. + +```js +const isObjectLike = val => val !== null && typeof val === 'object'; +``` + +
+Examples + +```js +isObjectLike({}); // true +isObjectLike([1, 2, 3]); // true +isObjectLike(x => x); // false +isObjectLike(null); // false +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + ### isPlainObject Checks if the provided value is an bbject created by the Object constructor. diff --git a/docs/index.html b/docs/index.html index aaa8b4fb8..147944c6e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -50,7 +50,7 @@ scrollToTop(); } }, false); - }

logo 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
+      }

logo 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
 
Promise.resolve([1, 2, 3])
   .then(call('map', x => 2 * x))
   .then(console.log); //[ 2, 4, 6 ]
@@ -1329,6 +1329,11 @@ Foo.prototypeisObject({ a: 1 }); // true
 isObject({}); // true
 isObject(true); // false
+

isObjectLike

Checks if a value is object-like.

Check if the provided value is not null and its typeof is equal to 'object'.

const isObjectLike = val => val !== null && typeof val === 'object';
+
isObjectLike({}); // true
+isObjectLike([1, 2, 3]); // true
+isObjectLike(x => x); // false
+isObjectLike(null); // false
 

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.

const isPlainObject = val => !!val && typeof val === 'object' && val.constructor === Object;
 
isPlainObject({ a: 1 }); // true
 isPlainObject(new Map()); // false