Combined is snippets into a generic one

This commit is contained in:
Angelos Chalaris
2018-01-17 21:23:46 +02:00
parent 6921a9387b
commit 4feb68e848
10 changed files with 20 additions and 112 deletions

19
snippets/is.md Normal file
View File

@ -0,0 +1,19 @@
### is
Checks if the provided value is of the specified type.
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
```

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