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