From 649998596189dde5a8755ed579ab8a676bc2c5ba Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Wed, 17 Jan 2018 21:23:46 +0200 Subject: [PATCH 1/2] Combined is snippets into a generic one --- snippets/is.md | 19 +++++++++++++++++++ snippets/isArray.md | 13 ------------- snippets/isArrayBuffer.md | 13 ------------- snippets/isMap.md | 13 ------------- snippets/isRegExp.md | 13 ------------- snippets/isSet.md | 13 ------------- snippets/isTypedArray.md | 13 ------------- snippets/isWeakMap.md | 13 ------------- snippets/isWeakSet.md | 13 ------------- tag_database | 9 +-------- 10 files changed, 20 insertions(+), 112 deletions(-) create mode 100644 snippets/is.md delete mode 100644 snippets/isArray.md delete mode 100644 snippets/isArrayBuffer.md delete mode 100644 snippets/isMap.md delete mode 100644 snippets/isRegExp.md delete mode 100644 snippets/isSet.md delete mode 100644 snippets/isTypedArray.md delete mode 100644 snippets/isWeakMap.md delete mode 100644 snippets/isWeakSet.md diff --git a/snippets/is.md b/snippets/is.md new file mode 100644 index 000000000..a43e7744c --- /dev/null +++ b/snippets/is.md @@ -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 +``` diff --git a/snippets/isArray.md b/snippets/isArray.md deleted file mode 100644 index def452a89..000000000 --- a/snippets/isArray.md +++ /dev/null @@ -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 -``` diff --git a/snippets/isArrayBuffer.md b/snippets/isArrayBuffer.md deleted file mode 100644 index 7c28d4398..000000000 --- a/snippets/isArrayBuffer.md +++ /dev/null @@ -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 -``` diff --git a/snippets/isMap.md b/snippets/isMap.md deleted file mode 100644 index b3a202c5d..000000000 --- a/snippets/isMap.md +++ /dev/null @@ -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 -``` diff --git a/snippets/isRegExp.md b/snippets/isRegExp.md deleted file mode 100644 index db57bf587..000000000 --- a/snippets/isRegExp.md +++ /dev/null @@ -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 -``` diff --git a/snippets/isSet.md b/snippets/isSet.md deleted file mode 100644 index bddf3fcbb..000000000 --- a/snippets/isSet.md +++ /dev/null @@ -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 -``` diff --git a/snippets/isTypedArray.md b/snippets/isTypedArray.md deleted file mode 100644 index 7b7416bf9..000000000 --- a/snippets/isTypedArray.md +++ /dev/null @@ -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 -``` diff --git a/snippets/isWeakMap.md b/snippets/isWeakMap.md deleted file mode 100644 index 432f17f7e..000000000 --- a/snippets/isWeakMap.md +++ /dev/null @@ -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 -``` diff --git a/snippets/isWeakSet.md b/snippets/isWeakSet.md deleted file mode 100644 index a72a1f0ac..000000000 --- a/snippets/isWeakSet.md +++ /dev/null @@ -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 -``` diff --git a/tag_database b/tag_database index c0b80e5cb..4944f0cd4 100644 --- a/tag_database +++ b/tag_database @@ -79,16 +79,14 @@ initializeArrayWithValues:array,math inRange:math intersection:array,math invertKeyValues:object +is:type,array,regexp isAbsoluteURL:string,utility,browser,url -isArray:type,array -isArrayBuffer:type isArrayLike:type,array isBoolean:type isDivisible:math isEven:math isFunction:type,function isLowerCase:string,utility -isMap:type isNil:type isNull:type isNumber:type,math @@ -96,18 +94,13 @@ isObject:type,object isPrime:math isPrimitive:type,function,array,string isPromiseLike:type,function,promise -isRegExp:type,regexp -isSet:type isSorted:array isString:type,string isSymbol:type isTravisCI:node -isTypedArray:type isUndefined:type isUpperCase:string,utility isValidJSON:type,json -isWeakMap:type -isWeakSet:type join:array JSONToFile:node,json last:array From db0a5186d5f84c6446d425fd359be46aaa1f5753 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Wed, 17 Jan 2018 21:30:31 +0200 Subject: [PATCH 2/2] Update is.md --- snippets/is.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/snippets/is.md b/snippets/is.md index a43e7744c..de07e6070 100644 --- a/snippets/is.md +++ b/snippets/is.md @@ -1,6 +1,6 @@ ### is -Checks if the provided value is of the specified type. +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`. @@ -16,4 +16,10 @@ 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 ```