Merge pull request #556 from Chalarangelo/isUpdate

[PATCH] Combined is snippets into a generic one
This commit is contained in:
Angelos Chalaris
2018-01-17 21:38:35 +02:00
committed by GitHub
10 changed files with 26 additions and 112 deletions

25
snippets/is.md Normal file
View 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
```

View File

@ -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
```

View File

@ -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
```

View File

@ -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
```

View File

@ -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
```

View File

@ -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
```

View File

@ -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
```

View File

@ -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
```

View File

@ -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
```

View File

@ -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