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
|
||||
```
|
||||
Reference in New Issue
Block a user