From 13ba436b415e2981e8bcefa9a0726c4ddc3cae39 Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Thu, 11 Jan 2018 10:40:53 +0000 Subject: [PATCH] Travis build: 1183 --- README.md | 30 ++++++++++++++++++++++++++++++ docs/index.html | 10 +++++++++- snippets/httpPost.md | 1 + snippets/isObject.md | 2 +- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 87098f99b..c609e7a4e 100644 --- a/README.md +++ b/README.md @@ -314,6 +314,7 @@ average(1, 2, 3); * [`isFunction`](#isfunction) * [`isNull`](#isnull) * [`isNumber`](#isnumber) +* [`isObject`](#isobject) * [`isPrimitive`](#isprimitive) * [`isPromiseLike`](#ispromiselike) * [`isString`](#isstring) @@ -4893,6 +4894,34 @@ isNumber(1); // true
[⬆ Back to top](#table-of-contents) +### isObject + +Returns a boolean determining if the passed value is an object or not. + +Uses the `Object` constructor to create an object wrapper for the given value. +If the value is `null` or `undefined`, create and return an empty object. Οtherwise, return an object of a type that corresponds to the given value. + +```js +const isObject = obj => obj === Object(obj); +``` + +
+Examples + +```js +isObject([1, 2, 3, 4]); // true +isObject([]); // true +isObject(['Hello!']); // true +isObject({ a: 1 }); // true +isObject({}); // true +isObject(true); // false +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + ### isPrimitive Returns a boolean determining if the passed value is primitive or not. @@ -5272,6 +5301,7 @@ const httpPost = (url, callback, data = null, err = console.error) => { + const newPost = { "userId": 1, "id": 1337, diff --git a/docs/index.html b/docs/index.html index 6f80a9058..f8edae984 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 ]
@@ -1059,6 +1059,13 @@ console.log<
 

isNumber

Checks if the given argument is a number.

Use typeof to check if a value is classified as a number primitive.

const isNumber = val => typeof val === 'number';
 
isNumber('1'); // false
 isNumber(1); // true
+

isObject

Returns a boolean determining if the passed value is an object or not.

Uses the Object constructor to create an object wrapper for the given value. If the value is null or undefined, create and return an empty object. Οtherwise, return an object of a type that corresponds to the given value.

const isObject = obj => obj === Object(obj);
+
isObject([1, 2, 3, 4]); // true
+isObject([]); // true
+isObject(['Hello!']); // true
+isObject({ a: 1 }); // true
+isObject({}); // true
+isObject(true); // false
 

isPrimitive

Returns a boolean determining if the passed value is primitive or not.

Use Array.includes() on an array of type strings which are not primitive, supplying the type using typeof. Since typeof null evaluates to 'object', it needs to be directly compared.

const isPrimitive = val => !['object', 'function'].includes(typeof val) || val === null;
 
isPrimitive(null); // true
 isPrimitive(50); // true
@@ -1171,6 +1178,7 @@ Logs: {
 
 
 
+
 const newPost = {
   "userId": 1,
   "id": 1337,
diff --git a/snippets/httpPost.md b/snippets/httpPost.md
index 55d29a095..e9e6d1e70 100644
--- a/snippets/httpPost.md
+++ b/snippets/httpPost.md
@@ -30,6 +30,7 @@ const httpPost = (url, callback, data = null, err = console.error) => {
 
 
 
+
 const newPost = {
   "userId": 1,
   "id": 1337,
diff --git a/snippets/isObject.md b/snippets/isObject.md
index c4cc5ffa8..eb8aee625 100644
--- a/snippets/isObject.md
+++ b/snippets/isObject.md
@@ -13,7 +13,7 @@ const isObject = obj => obj === Object(obj);
 isObject([1, 2, 3, 4]); // true
 isObject([]); // true
 isObject(['Hello!']); // true
-isObject({ a:1 }); // true
+isObject({ a: 1 }); // true
 isObject({}); // true
 isObject(true); // false
 ```