diff --git a/README.md b/README.md index 5135a2ee6..fc64e5408 100644 --- a/README.md +++ b/README.md @@ -324,17 +324,24 @@ average(1, 2, 3); * [`getType`](#gettype) * [`isArray`](#isarray) +* [`isArrayBuffer`](#isarraybuffer) * [`isArrayLike`](#isarraylike) * [`isBoolean`](#isboolean) * [`isFunction`](#isfunction) +* [`isMap`](#ismap) * [`isNull`](#isnull) * [`isNumber`](#isnumber) * [`isObject`](#isobject) * [`isPrimitive`](#isprimitive) * [`isPromiseLike`](#ispromiselike) +* [`isRegExp`](#isregexp) +* [`isSet`](#isset) * [`isString`](#isstring) * [`isSymbol`](#issymbol) +* [`isTypedArray`](#istypedarray) * [`isValidJSON`](#isvalidjson) +* [`isWeakMap`](#isweakmap) +* [`isWeakSet`](#isweakset) @@ -5150,6 +5157,28 @@ isArray([1]); // true
[⬆ Back to top](#table-of-contents) +### isArrayBuffer + +Checks if value is classified as a ArrayBuffer object. + +Use the `instanceof`operator to check if the provided value is a `ArrayBuffer` object. + +```js +const isArrayBuffer = val => val instanceof ArrayBuffer; +``` + +
+Examples + +```js +isArrayBuffer(new ArrayBuffer()); // true +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + ### isArrayLike Checks if the provided argument is array-like (i.e. is iterable). @@ -5226,6 +5255,28 @@ isFunction(x => x); // true
[⬆ Back to top](#table-of-contents) +### isMap + +Checks if value is classified as a Map object. + +Use the `instanceof`operator to check if the provided value is a `Map` object. + +```js +const isMap = val => val instanceof Map; +``` + +
+Examples + +```js +isMap(new Map()); // true +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + ### isNull Returns `true` if the specified value is `null`, `false` otherwise. @@ -5359,6 +5410,50 @@ isPromiseLike({}); // false
[⬆ Back to top](#table-of-contents) +### isRegExp + +Checks if value is classified as a RegExp object. + +Use the `instanceof`operator to check if the provided value is a `RegExp` object. + +```js +const isRegExp = val => val instanceof RegExp; +``` + +
+Examples + +```js +isRegExp(/./g); // true +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + +### isSet + +Checks if value is classified as a Set object. + +Use the `instanceof`operator to check if the provided value is a `Set` object. + +```js +const isSet = val => val instanceof Set; +``` + +
+Examples + +```js +isSet(new Set()); // true +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + ### isString Checks if the given argument is a string. @@ -5403,6 +5498,28 @@ isSymbol(Symbol('x')); // true
[⬆ Back to top](#table-of-contents) +### isTypedArray + +Checks if value is classified as a TypedArray object. + +Use the `instanceof`operator to check if the provided value is a `TypedArray` object. + +```js +const isTypedArray = val => val instanceof TypedArray; +``` + +
+Examples + +```js +isTypedArray(new TypedArray()); // true +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + ### isValidJSON Checks if the provided argument is a valid JSON. @@ -5433,6 +5550,50 @@ isValidJSON(null); // true
[⬆ Back to top](#table-of-contents) + +### isWeakMap + +Checks if value is classified as a WeakMap object. + +Use the `instanceof`operator to check if the provided value is a `WeakMap` object. + +```js +const isWeakMap = val => val instanceof WeakMap; +``` + +
+Examples + +```js +isWeakMap(new WeakMap()); // true +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + +### isWeakSet + +Checks if value is classified as a WeakSet object. + +Use the `instanceof`operator to check if the provided value is a `WeakSet` object. + +```js +const isWeakSet = val => val instanceof WeakSet; +``` + +
+Examples + +```js +isWeakSet(new WeakSet()); // true +``` + +
+ +
[⬆ Back to top](#table-of-contents) + --- ## 🔧 Utility diff --git a/docs/index.html b/docs/index.html index 205434aa1..70ea19b9d 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 ]
@@ -1166,6 +1166,8 @@ Foo.prototypeShow examples
getType(new Set([1, 2, 3])); // 'set'
 

isArray

Checks if the given argument is an array.

Use Array.isArray() to check if a value is classified as an array.

const isArray = val => Array.isArray(val);
 
isArray([1]); // true
+

isArrayBuffer

Checks if value is classified as a ArrayBuffer object.

Use the instanceofoperator to check if the provided value is a ArrayBuffer object.

const isArrayBuffer = val => val instanceof ArrayBuffer;
+
isArrayBuffer(new ArrayBuffer()); // true
 

isArrayLike

Checks if the provided argument is array-like (i.e. is iterable).

Use the spread operator (...) to check if the provided argument is iterable inside a try... catch block and the comma operator (,) to return the appropriate value.

const isArrayLike = val => {
   try {
     return [...val], true;
@@ -1182,6 +1184,8 @@ Foo.prototype📋 Copy to clipboard

isFunction

Checks if the given argument is a function.

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

const isFunction = val => typeof val === 'function';
 
isFunction('x'); // false
 isFunction(x => x); // true
+

isMap

Checks if value is classified as a Map object.

Use the instanceofoperator to check if the provided value is a Map object.

const isMap = val => val instanceof Map;
+
isMap(new Map()); // true
 

isNull

Returns true if the specified value is null, false otherwise.

Use the strict equality operator to check if the value and of val are equal to null.

const isNull = val => val === null;
 
isNull(null); // true
 

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';
@@ -1212,10 +1216,16 @@ Foo.prototype// true
 isPromiseLike(null); // false
 isPromiseLike({}); // false
+

isRegExp

Checks if value is classified as a RegExp object.

Use the instanceofoperator to check if the provided value is a RegExp object.

const isRegExp = val => val instanceof RegExp;
+
isRegExp(/./g); // true
+

isSet

Checks if value is classified as a Set object.

Use the instanceofoperator to check if the provided value is a Set object.

const isSet = val => val instanceof Set;
+
isSet(new Set()); // true
 

isString

Checks if the given argument is a string.

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

const isString = val => typeof val === 'string';
 
isString('10'); // true
 

isSymbol

Checks if the given argument is a symbol.

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

const isSymbol = val => typeof val === 'symbol';
 
isSymbol(Symbol('x')); // true
+

isTypedArray

Checks if value is classified as a TypedArray object.

Use the instanceofoperator to check if the provided value is a TypedArray object.

const isTypedArray = val => val instanceof TypedArray;
+
isTypedArray(new TypedArray()); // true
 

isValidJSON

Checks if the provided argument is a valid JSON.

Use JSON.parse() and a try... catch block to check if the provided argument is a valid JSON.

const isValidJSON = obj => {
   try {
     JSON.parse(obj);
@@ -1227,6 +1237,10 @@ Foo.prototypeShow examples
isValidJSON('{"name":"Adam","age":20}'); // true
 isValidJSON('{"name":"Adam",age:"20"}'); // false
 isValidJSON(null); // true
+

isWeakMap

Checks if value is classified as a WeakMap object.

Use the instanceofoperator to check if the provided value is a WeakMap object.

const isWeakMap = val => val instanceof WeakMap;
+
isWeakMap(new WeakMap()); // true
+

isWeakSet

Checks if value is classified as a WeakSet object.

Use the instanceofoperator to check if the provided value is a WeakSet object.

const isWeakSet = val => val instanceof WeakSet;
+
isWeakSet(new WeakSet()); // true
 

Utility

cloneRegExp

Clones a regular expression.

Use new RegExp(), RegExp.source and RegExp.flags to clone the given regular expression.

const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags);
 
const regExp = /lorem ipsum/gi;
 const regExp2 = cloneRegExp(regExp); // /lorem ipsum/gi