Merge pull request #556 from Chalarangelo/isUpdate
[PATCH] Combined is snippets into a generic one
This commit is contained in:
25
snippets/is.md
Normal file
25
snippets/is.md
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
### is
|
||||||
|
|
||||||
|
Checks if the provided value is of the specified type (doesn't work with literals).
|
||||||
|
|
||||||
|
Use the `instanceof` operator to check if the provided value is of the specified `type`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const is = (type, val) => val instanceof type;
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
is(Array,[1]); // true
|
||||||
|
is(ArrayBuffer, new ArrayBuffer()); // true
|
||||||
|
is(Map, new Map()); // true
|
||||||
|
is(RegExp, /./g); // true
|
||||||
|
is(Set, new Set()); // true
|
||||||
|
is(WeakMap, new WeakMap()); // true
|
||||||
|
is(WeakSet, new WeakSet()); // true
|
||||||
|
is(String, ''); // false
|
||||||
|
is(String, new String('')); // true
|
||||||
|
is(Number, 1); // false
|
||||||
|
is(Number, new Number(1)); // true
|
||||||
|
is(Boolean, true); // false
|
||||||
|
is(Boolean, new Boolean(true)); // true
|
||||||
|
```
|
||||||
@ -1,13 +0,0 @@
|
|||||||
### isArray
|
|
||||||
|
|
||||||
Checks if the given argument is an array.
|
|
||||||
|
|
||||||
Use `Array.isArray()` to check if a value is classified as an array.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const isArray = val => Array.isArray(val);
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
|
||||||
isArray([1]); // true
|
|
||||||
```
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
### 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;
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
|
||||||
isArrayBuffer(new ArrayBuffer()); // true
|
|
||||||
```
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
### 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;
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
|
||||||
isMap(new Map()); // true
|
|
||||||
```
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
### 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;
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
|
||||||
isRegExp(/./g); // true
|
|
||||||
```
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
### 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;
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
|
||||||
isSet(new Set()); // true
|
|
||||||
```
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
### 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;
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
|
||||||
isTypedArray(new TypedArray()); // true
|
|
||||||
```
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
### 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;
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
|
||||||
isWeakMap(new WeakMap()); // true
|
|
||||||
```
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
### 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;
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
|
||||||
isWeakSet(new WeakSet()); // true
|
|
||||||
```
|
|
||||||
@ -81,16 +81,14 @@ initializeArrayWithValues:array,math
|
|||||||
inRange:math
|
inRange:math
|
||||||
intersection:array,math
|
intersection:array,math
|
||||||
invertKeyValues:object
|
invertKeyValues:object
|
||||||
|
is:type,array,regexp
|
||||||
isAbsoluteURL:string,utility,browser,url
|
isAbsoluteURL:string,utility,browser,url
|
||||||
isArray:type,array
|
|
||||||
isArrayBuffer:type
|
|
||||||
isArrayLike:type,array
|
isArrayLike:type,array
|
||||||
isBoolean:type
|
isBoolean:type
|
||||||
isDivisible:math
|
isDivisible:math
|
||||||
isEven:math
|
isEven:math
|
||||||
isFunction:type,function
|
isFunction:type,function
|
||||||
isLowerCase:string,utility
|
isLowerCase:string,utility
|
||||||
isMap:type
|
|
||||||
isNil:type
|
isNil:type
|
||||||
isNull:type
|
isNull:type
|
||||||
isNumber:type,math
|
isNumber:type,math
|
||||||
@ -98,18 +96,13 @@ isObject:type,object
|
|||||||
isPrime:math
|
isPrime:math
|
||||||
isPrimitive:type,function,array,string
|
isPrimitive:type,function,array,string
|
||||||
isPromiseLike:type,function,promise
|
isPromiseLike:type,function,promise
|
||||||
isRegExp:type,regexp
|
|
||||||
isSet:type
|
|
||||||
isSorted:array
|
isSorted:array
|
||||||
isString:type,string
|
isString:type,string
|
||||||
isSymbol:type
|
isSymbol:type
|
||||||
isTravisCI:node
|
isTravisCI:node
|
||||||
isTypedArray:type
|
|
||||||
isUndefined:type
|
isUndefined:type
|
||||||
isUpperCase:string,utility
|
isUpperCase:string,utility
|
||||||
isValidJSON:type,json
|
isValidJSON:type,json
|
||||||
isWeakMap:type
|
|
||||||
isWeakSet:type
|
|
||||||
join:array
|
join:array
|
||||||
JSONToFile:node,json
|
JSONToFile:node,json
|
||||||
last:array
|
last:array
|
||||||
|
|||||||
Reference in New Issue
Block a user