From ac70cf84e8e105998e0eba2231d6aca34e8a7564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 14 Apr 2021 01:19:13 +0200 Subject: [PATCH 001/201] refactor(isString): add callback function, use isStringObject and isStringType functions. --- packages/type/src/is/lib/is-string.func.ts | 26 +++++++++------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/packages/type/src/is/lib/is-string.func.ts b/packages/type/src/is/lib/is-string.func.ts index 8e30cb00..549b9426 100644 --- a/packages/type/src/is/lib/is-string.func.ts +++ b/packages/type/src/is/lib/is-string.func.ts @@ -1,25 +1,19 @@ -import { IsString } from '../type/is-string.type'; +import { errorCallback } from '../../lib/error-callback.func'; +import { isStringObject } from './is-string-object.func'; +import { isStringType } from './is-string-type.func'; import { typeOf } from '../../lib/type-of.func'; +// Type. +import { IsString } from '../type/is-string.type'; +import { ResultCallback } from '../../type/result-callback.type'; + /** * Checks if any `value` is a `'string'` type, not instance of `Object` and `String` * or `'object'` type and instance of `String` and `Object`. * Use the`guardString()` function to type-guard `string` also. * @param value Any value to check if it's a `'string'` type, not an instance of `Object` and `String` * or `'object'` type and instance of `String` and `Object`. + * @param callback ResultCallback function to handle result before return. * @returns boolean. */ -export const isString: IsString = (value: any): value is string => - typeOf(value) === 'string' && - ( - ( - typeof value === 'object' && - value instanceof Object === true && - value instanceof String === true - ) - || - ( - value instanceof Object === false && - value instanceof String === false && - typeof value === 'string' - ) - ); +export const isString: IsString = (value: any, callback: ResultCallback = errorCallback): value is string => + callback(typeOf(value) === 'string' && (isStringObject(value) || isStringType(value))); From 21bae23185020a523f2d8b9ece257f242c23b824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 14 Apr 2021 01:23:25 +0200 Subject: [PATCH 002/201] feat(resultCallback): Function to handle callback. --- packages/type/src/lib/error-callback.func.ts | 2 ++ packages/type/src/type/result-callback.type.ts | 1 + 2 files changed, 3 insertions(+) create mode 100644 packages/type/src/lib/error-callback.func.ts create mode 100644 packages/type/src/type/result-callback.type.ts diff --git a/packages/type/src/lib/error-callback.func.ts b/packages/type/src/lib/error-callback.func.ts new file mode 100644 index 00000000..1ae95e1a --- /dev/null +++ b/packages/type/src/lib/error-callback.func.ts @@ -0,0 +1,2 @@ +import { ResultCallback } from '../type/result-callback.type'; +export const errorCallback: ResultCallback = (result: boolean): boolean => result; diff --git a/packages/type/src/type/result-callback.type.ts b/packages/type/src/type/result-callback.type.ts new file mode 100644 index 00000000..daacc602 --- /dev/null +++ b/packages/type/src/type/result-callback.type.ts @@ -0,0 +1 @@ +export type ResultCallback = (result: boolean) => boolean; From 915c01b9fbfe9daac60fcc3284a4fa9ec5c208ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 14 Apr 2021 01:23:55 +0200 Subject: [PATCH 003/201] refactor(IsString): add callback. --- packages/type/src/is/type/is-string.type.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/type/src/is/type/is-string.type.ts b/packages/type/src/is/type/is-string.type.ts index 996c5927..03876e5b 100644 --- a/packages/type/src/is/type/is-string.type.ts +++ b/packages/type/src/is/type/is-string.type.ts @@ -1 +1,2 @@ -export type IsString = (value: any) => value is string; +import { ResultCallback } from '../../type/result-callback.type'; +export type IsString = (value: any, callback?: ResultCallback) => value is string; From 5f783a3913f1e3b700ef24186e40ef7a36024e0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 14 Apr 2021 01:28:03 +0200 Subject: [PATCH 004/201] refactor(isObject): Generic `Obj` equal to `object`, update description. --- packages/type/src/is/lib/is-object.func.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/type/src/is/lib/is-object.func.ts b/packages/type/src/is/lib/is-object.func.ts index e01b60e8..3cedd1a4 100644 --- a/packages/type/src/is/lib/is-object.func.ts +++ b/packages/type/src/is/lib/is-object.func.ts @@ -5,13 +5,11 @@ import { typeOf } from '../../lib/type-of.func'; * Checks if any `value` is a generic `Obj` `'object'` type and `Object` instance with the possibility of containing `key`. * Use the `guardObject()` function to type-guard generic object type also. * @param value Any `value` to check if it's a generic `'object'` type and `Object` instance. - * @param [key] Property name to find in argument `value`. + * @param key Name to find in argument `value`. * @returns boolean */ -export const isObject: IsObject = (value: any, key?: string): value is Obj => - typeOf(value) === 'object' && - typeof value === 'object' && - value instanceof Object === true +export const isObject: IsObject = (value: any, key?: string): value is Obj => + (typeOf(value) === 'object' && typeof value === 'object' && value instanceof Object === true) ? isString(key) ? key in value : true From 52c48373b34dd25cf2cce7629b33d52dc496ce56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 14 Apr 2021 02:28:16 +0200 Subject: [PATCH 005/201] feat(KeyName): Type for property name. --- packages/type/src/type/key-name.type.ts | 1 + 1 file changed, 1 insertion(+) create mode 100644 packages/type/src/type/key-name.type.ts diff --git a/packages/type/src/type/key-name.type.ts b/packages/type/src/type/key-name.type.ts new file mode 100644 index 00000000..65186809 --- /dev/null +++ b/packages/type/src/type/key-name.type.ts @@ -0,0 +1 @@ +export type KeyName = string | number | symbol; From d0aec2b9d3966ad30e47a8db5f7dd012c5faaaf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 19 Apr 2021 12:49:20 +0200 Subject: [PATCH 006/201] refactor(KeyName): simplify type name to `Key`. --- packages/type/src/type/key-name.type.ts | 1 - packages/type/src/type/key.type.ts | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 packages/type/src/type/key-name.type.ts create mode 100644 packages/type/src/type/key.type.ts diff --git a/packages/type/src/type/key-name.type.ts b/packages/type/src/type/key-name.type.ts deleted file mode 100644 index 65186809..00000000 --- a/packages/type/src/type/key-name.type.ts +++ /dev/null @@ -1 +0,0 @@ -export type KeyName = string | number | symbol; diff --git a/packages/type/src/type/key.type.ts b/packages/type/src/type/key.type.ts new file mode 100644 index 00000000..76ae3142 --- /dev/null +++ b/packages/type/src/type/key.type.ts @@ -0,0 +1 @@ +export type Key = number | string | symbol; From e3a2f100bc25df0303f6f6302a2a76d80a21c825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 19 Apr 2021 12:51:01 +0200 Subject: [PATCH 007/201] feat(isKey): function to determine whether or not name is string or number or symbol. --- packages/type/src/is/lib/is-key.func.ts | 9 +++++++++ packages/type/src/is/type/is-key.type.ts | 2 ++ 2 files changed, 11 insertions(+) create mode 100644 packages/type/src/is/lib/is-key.func.ts create mode 100644 packages/type/src/is/type/is-key.type.ts diff --git a/packages/type/src/is/lib/is-key.func.ts b/packages/type/src/is/lib/is-key.func.ts new file mode 100644 index 00000000..27721eca --- /dev/null +++ b/packages/type/src/is/lib/is-key.func.ts @@ -0,0 +1,9 @@ +// Function. +import { isString } from './is-string.func'; +import { isNumber } from './is-number.func'; +import { isSymbol } from './is-symbol.func'; +// Type. +import { IsKey } from '../type/is-key.type'; +import { Key } from '../../type/key.type'; + +export const isKey: IsKey = (name: Key): boolean => isString(name) || isNumber(name) || isSymbol(name); diff --git a/packages/type/src/is/type/is-key.type.ts b/packages/type/src/is/type/is-key.type.ts new file mode 100644 index 00000000..c1e7f554 --- /dev/null +++ b/packages/type/src/is/type/is-key.type.ts @@ -0,0 +1,2 @@ +import { Key } from '../../type/key.type'; +export type IsKey = (name: Key) => boolean; From f0d4d7c4bd8c38e013bf03792cb447020b277401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 19 Apr 2021 13:12:10 +0200 Subject: [PATCH 008/201] refactor(isKey): parameter change to value any type and add description. --- packages/type/src/is/lib/is-key.func.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/type/src/is/lib/is-key.func.ts b/packages/type/src/is/lib/is-key.func.ts index 27721eca..9c3f5a94 100644 --- a/packages/type/src/is/lib/is-key.func.ts +++ b/packages/type/src/is/lib/is-key.func.ts @@ -4,6 +4,10 @@ import { isNumber } from './is-number.func'; import { isSymbol } from './is-symbol.func'; // Type. import { IsKey } from '../type/is-key.type'; -import { Key } from '../../type/key.type'; -export const isKey: IsKey = (name: Key): boolean => isString(name) || isNumber(name) || isSymbol(name); +/** + * Determines if any `value` is one of the string, number, or symbol type. + * @param value Any value to check. + * @returns A boolean indicating whether or not the value is one of the string, number or symbol type. + */ +export const isKey: IsKey = (value: any): boolean => isString(value) || isNumber(value) || isSymbol(value); From 6e66c4c7f176f07d89f0af0e19aa89f964e707c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 19 Apr 2021 13:12:44 +0200 Subject: [PATCH 009/201] refactor(IsObject): Obj type is by default equal to object --- packages/type/src/is/type/is-object.type.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/is/type/is-object.type.ts b/packages/type/src/is/type/is-object.type.ts index 6542dbc2..d5f88798 100644 --- a/packages/type/src/is/type/is-object.type.ts +++ b/packages/type/src/is/type/is-object.type.ts @@ -1 +1 @@ -export type IsObject = (value: any, key?: string) => value is Obj; +export type IsObject = (value: any, key?: string) => value is Obj; From 7675668edb163f1c35459a31b3204236d64c11fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 19 Apr 2021 13:57:04 +0200 Subject: [PATCH 010/201] feat(guardKey): feature to guard key for objects. --- packages/type/src/guard/lib/guard-key.func.ts | 14 ++++++++++++++ packages/type/src/guard/type/guard-key.type.ts | 2 ++ 2 files changed, 16 insertions(+) create mode 100644 packages/type/src/guard/lib/guard-key.func.ts create mode 100644 packages/type/src/guard/type/guard-key.type.ts diff --git a/packages/type/src/guard/lib/guard-key.func.ts b/packages/type/src/guard/lib/guard-key.func.ts new file mode 100644 index 00000000..9894c7a8 --- /dev/null +++ b/packages/type/src/guard/lib/guard-key.func.ts @@ -0,0 +1,14 @@ +// Function. +import { isNumber } from '../../is/lib/is-number.func'; +import { isString } from '../../is/lib/is-string.func'; +import { isSymbol } from '../../is/lib/is-symbol.func'; +// Type. +import { GuardKey } from '../type/guard-key.type'; +import { Key } from '../../type/key.type'; + +/** + * Guard the value to be one of the string, number, or symbol type. + * @param value Generic `Key` type value to guard. + * @returns A boolean indicating whether or not the value is one of the string, number or symbol type. + */ +export const guardKey: GuardKey = (value: Key): boolean => isString(value) || isNumber(value) || isSymbol(value); diff --git a/packages/type/src/guard/type/guard-key.type.ts b/packages/type/src/guard/type/guard-key.type.ts new file mode 100644 index 00000000..3bb94bfe --- /dev/null +++ b/packages/type/src/guard/type/guard-key.type.ts @@ -0,0 +1,2 @@ +import { Key } from '../../type/key.type'; +export type GuardKey = (value: Key) => boolean; From 7a63d545d197e7d5b9a045f57ba80c57a67a2a13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 19 Apr 2021 13:58:41 +0200 Subject: [PATCH 011/201] fix(guardArray): fix file name. --- packages/type/src/guard/index.ts | 2 +- .../guard/lib/{guard-array.func.type.ts => guard-array.func.ts} | 0 packages/type/src/guard/test/guard-array.spec.ts | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename packages/type/src/guard/lib/{guard-array.func.type.ts => guard-array.func.ts} (100%) diff --git a/packages/type/src/guard/index.ts b/packages/type/src/guard/index.ts index c58eb95b..9b2b827d 100644 --- a/packages/type/src/guard/index.ts +++ b/packages/type/src/guard/index.ts @@ -1,6 +1,6 @@ export { guard } from './lib/guard.object'; -export { guardArray } from './lib/guard-array.func.type'; +export { guardArray } from './lib/guard-array.func'; export { guardFunction } from './lib/guard-function.func'; export { guardNumber } from './lib/guard-number.func'; export { guardObjectKey } from './lib/guard-object-key.func'; diff --git a/packages/type/src/guard/lib/guard-array.func.type.ts b/packages/type/src/guard/lib/guard-array.func.ts similarity index 100% rename from packages/type/src/guard/lib/guard-array.func.type.ts rename to packages/type/src/guard/lib/guard-array.func.ts diff --git a/packages/type/src/guard/test/guard-array.spec.ts b/packages/type/src/guard/test/guard-array.spec.ts index 2d8d1ddb..1c73f5c2 100644 --- a/packages/type/src/guard/test/guard-array.spec.ts +++ b/packages/type/src/guard/test/guard-array.spec.ts @@ -1,5 +1,5 @@ // Function. -import { guardArray } from '../lib/guard-array.func.type'; +import { guardArray } from '../lib/guard-array.func'; // Variables. import { Class } from '../../is/test/variables/class.const'; From 170cabb1ca8da7e5c1e92357abbafb0160c35cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 19 Apr 2021 13:59:01 +0200 Subject: [PATCH 012/201] fix(guardArray): fix file name. --- packages/type/src/guard/lib/guard-is.object.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/guard/lib/guard-is.object.ts b/packages/type/src/guard/lib/guard-is.object.ts index 858eaf7c..8b383e72 100644 --- a/packages/type/src/guard/lib/guard-is.object.ts +++ b/packages/type/src/guard/lib/guard-is.object.ts @@ -1,5 +1,5 @@ import { GuardIs } from '../interface/guard-is.interface'; -import { guardArray } from './guard-array.func.type'; +import { guardArray } from './guard-array.func'; import { guardFunction } from './guard-function.func'; import { guardNumber } from './guard-number.func'; import { guardObject } from './guard-object.func'; From 7c26fea080029f8e909e3ca063fcc6473de25fdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 19 Apr 2021 14:17:53 +0200 Subject: [PATCH 013/201] refactor(guardIs): add guardKey to guardIs object. --- packages/type/src/guard/interface/guard-is.interface.ts | 2 ++ packages/type/src/guard/lib/guard-is.object.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/packages/type/src/guard/interface/guard-is.interface.ts b/packages/type/src/guard/interface/guard-is.interface.ts index f7a70b54..96ee125f 100644 --- a/packages/type/src/guard/interface/guard-is.interface.ts +++ b/packages/type/src/guard/interface/guard-is.interface.ts @@ -7,10 +7,12 @@ import { GuardPrimitive } from '../type/guard-primitive.type'; import { GuardString } from '../type/guard-string.type'; import { GuardType } from '../type/guard-type.type'; import { GuardObject } from '../type/guard-object.type'; +import { GuardKey } from '../type/guard-key.type'; export interface GuardIs { array: GuardArray; function: GuardFunction; + key: GuardKey; // TODO: Guard not // not: GuardNotIs; number: GuardNumber; diff --git a/packages/type/src/guard/lib/guard-is.object.ts b/packages/type/src/guard/lib/guard-is.object.ts index 8b383e72..2d10715f 100644 --- a/packages/type/src/guard/lib/guard-is.object.ts +++ b/packages/type/src/guard/lib/guard-is.object.ts @@ -7,11 +7,13 @@ import { guardObjectKey } from './guard-object-key.func'; import { guardPrimitive } from './guard-primitive.func'; import { guardString } from './guard-string.func'; import { guardType } from './guard-type.func'; +import { guardKey } from './guard-key.func'; export const guardIs: GuardIs = { // TODO: add other guards etc. boolean, null, undefined array: guardArray, function: guardFunction, + key: guardKey, number: guardNumber, objectKey: guardObjectKey, object: guardObject, From aa44c817e28386a4d0944e666111c71f4c0f4386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 19 Apr 2021 14:23:52 +0200 Subject: [PATCH 014/201] docs(guardKey): update description. --- packages/type/src/guard/lib/guard-key.func.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/type/src/guard/lib/guard-key.func.ts b/packages/type/src/guard/lib/guard-key.func.ts index 9894c7a8..8fb43b53 100644 --- a/packages/type/src/guard/lib/guard-key.func.ts +++ b/packages/type/src/guard/lib/guard-key.func.ts @@ -7,8 +7,8 @@ import { GuardKey } from '../type/guard-key.type'; import { Key } from '../../type/key.type'; /** - * Guard the value to be one of the string, number, or symbol type. - * @param value Generic `Key` type value to guard. - * @returns A boolean indicating whether or not the value is one of the string, number or symbol type. + * Guard the `value` of `Key type to be one of the `string`, `number`, or `symbol` type. + * @param value A generic `Key` type `value` to guard. + * @returns A `boolean` indicating whether or not the `value` is one of the `string`, `number` or `symbol` type. */ export const guardKey: GuardKey = (value: Key): boolean => isString(value) || isNumber(value) || isSymbol(value); From 1c92cc11d2c65ab4969f01d9c9a5a077dc4b3ead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 19 Apr 2021 17:02:46 +0200 Subject: [PATCH 015/201] chore(isSymbol): reorder imports, add comments to imports, update description. --- packages/type/src/is/lib/is-symbol.func.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/type/src/is/lib/is-symbol.func.ts b/packages/type/src/is/lib/is-symbol.func.ts index 2c62e472..9806b106 100644 --- a/packages/type/src/is/lib/is-symbol.func.ts +++ b/packages/type/src/is/lib/is-symbol.func.ts @@ -1,10 +1,11 @@ -import { IsSymbol } from '../type/is-symbol.type'; +// Function. import { typeOf } from '../../lib/type-of.func'; +// Type. +import { IsSymbol } from '../type/is-symbol.type'; /** * Checks if any `value` is a `'symbol'` type. - * Use the`guardSymbol()` function to type-guard `symbol` also. - * @param value Any `value` to check if it's a `'symbol'` type. - * @returns boolean. + * @param value Any `value` to check. + * @returns A `boolean` indicating whether or not the `value` is a `symbol`. */ export const isSymbol: IsSymbol = (value: any): value is symbol => typeOf(value) === 'symbol' && From 2fea29358541cdc82b03bd2521ec9f7bf5d8cf99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 20 Apr 2021 12:32:06 +0200 Subject: [PATCH 016/201] chore(isArray): upgrade jsdoc, reorder import. --- packages/type/src/is/lib/is-array.func.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/type/src/is/lib/is-array.func.ts b/packages/type/src/is/lib/is-array.func.ts index a474a6de..0220e037 100644 --- a/packages/type/src/is/lib/is-array.func.ts +++ b/packages/type/src/is/lib/is-array.func.ts @@ -1,10 +1,11 @@ -import { IsArray } from '../type/is-array.type'; +// Function. import { typeOf } from '../../lib/type-of.func'; +// Type. +import { IsArray } from '../type/is-array.type'; /** - * Checks if any `value` is an `Array` of `'object'` generic `Type` type and `Array` instance. - * Use the `guardArray()` function to type-guard `array` also. - * @param value Any `value` to check if it's an `Array` of `'object'` generic `Type` type and `Array` instance. - * @returns boolean. + * Checks if any `value` is an `Array`, `Array` instance and `object` type. + * @param value Any `value` to check. + * @returns A `boolean` indicating whether or not the `value` is an `Array`. */ export const isArray: IsArray = (value: any): value is Array => typeOf(value) === 'array' && From a9f54c70983f3428fa6970a3e184666357e83e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 20 Apr 2021 12:35:14 +0200 Subject: [PATCH 017/201] chore(isBigInt): update jsdoc, reorder imports. --- packages/type/src/is/lib/is-big-int.func.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/type/src/is/lib/is-big-int.func.ts b/packages/type/src/is/lib/is-big-int.func.ts index 2d47e8f2..1d2e5b6a 100644 --- a/packages/type/src/is/lib/is-big-int.func.ts +++ b/packages/type/src/is/lib/is-big-int.func.ts @@ -1,9 +1,11 @@ -import { IsBigInt } from '../type/is-big-int.type'; +// Function. import { typeOf } from '../../lib/type-of.func'; +// Type. +import { IsBigInt } from '../type/is-big-int.type'; /** - * Checks if any `value` is a `'bigint'` type. - * @param value Any `value` to check if it's a `'bigint'` type. - * @returns boolean + * Checks if any `value` is a `bigint` type. + * @param value Any `value` to check. + * @returns A `boolean` indicating whether or not the `value` is a `bigint`. */ export const isBigInt: IsBigInt = (value: any): value is bigint => typeOf(value) === 'bigint' && From c4f78fc65457b6fb70397002ad725e46d9f72e89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 20 Apr 2021 13:26:20 +0200 Subject: [PATCH 018/201] feat(isBooleanObject): function to check if any value is a boolean object. --- packages/type/src/is/lib/is-boolean-object.func.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 packages/type/src/is/lib/is-boolean-object.func.ts diff --git a/packages/type/src/is/lib/is-boolean-object.func.ts b/packages/type/src/is/lib/is-boolean-object.func.ts new file mode 100644 index 00000000..32f0ab9e --- /dev/null +++ b/packages/type/src/is/lib/is-boolean-object.func.ts @@ -0,0 +1,4 @@ +export const isBooleanObject = (value: any) => + typeof value === 'object' && + value instanceof Boolean === true && + value instanceof Object === true; From 196e302a7b1d762dda5c63010d6895038d70ea1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 20 Apr 2021 13:26:41 +0200 Subject: [PATCH 019/201] feat(isBooleanType): function to check if any value is a boolean type. --- packages/type/src/is/lib/is-boolean-type.func.ts | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 packages/type/src/is/lib/is-boolean-type.func.ts diff --git a/packages/type/src/is/lib/is-boolean-type.func.ts b/packages/type/src/is/lib/is-boolean-type.func.ts new file mode 100644 index 00000000..a638eab9 --- /dev/null +++ b/packages/type/src/is/lib/is-boolean-type.func.ts @@ -0,0 +1,5 @@ +export const isBooleanType = (value: any) => + value instanceof Boolean === false && + value instanceof Object === false && + typeof value === 'boolean' && + (value === true || value === false); From eb547ceb32f6b4ab405eef5ee00836f69fbf6180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 20 Apr 2021 13:29:04 +0200 Subject: [PATCH 020/201] refactor(isBoolean): use separated functions `isBooleanObject` and `isBooleanType`, update jsdoc, reorder imports. --- packages/type/src/is/lib/is-boolean.func.ts | 28 +++++++-------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/packages/type/src/is/lib/is-boolean.func.ts b/packages/type/src/is/lib/is-boolean.func.ts index f6ad846d..0ac122ec 100644 --- a/packages/type/src/is/lib/is-boolean.func.ts +++ b/packages/type/src/is/lib/is-boolean.func.ts @@ -1,24 +1,14 @@ -import { IsBoolean } from '../type/is-boolean.type'; +// Function. import { typeOf } from '../../lib/type-of.func'; +// Type. +import { IsBoolean } from '../type/is-boolean.type'; +import { isBooleanObject } from './is-boolean-object.func'; +import { isBooleanType } from './is-boolean-type.func'; /** - * Checks if any `value` is a `'boolean'` type not instance of `Boolean` and `Object` or `'object'` type instance of `Boolean` and `Object`. - * @param value Any `value` to check if it's a `'boolean'` type not instance of `Boolean` and `Object` - * or `'object'` type instance of `Boolean` and `Object`. - * @returns boolean. + * Checks if any `value` is a `boolean` type not instance of `Boolean` and `Object` or `object` type instance of `Boolean` and `Object`. + * @param value Any `value` to check. + * @returns A `boolean` indicating whether or not the `value` is a `boolean`. */ export const isBoolean: IsBoolean = (value: any): value is boolean => typeOf(value) === 'boolean' && - ( - ( - typeof value === 'object' && - value instanceof Boolean === true && - value instanceof Object === true - ) - || - ( - value instanceof Boolean === false && - value instanceof Object === false && - typeof value === 'boolean' && - (value === true || value === false) - ) - ); + (isBooleanObject(value) || isBooleanType(value)); From 5f746c35d57080901650a359dd0ecb65360133d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 20 Apr 2021 14:26:01 +0200 Subject: [PATCH 021/201] chore(isDefined): reorder imports, update jsdoc. --- packages/type/src/is/lib/is-defined.func.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/type/src/is/lib/is-defined.func.ts b/packages/type/src/is/lib/is-defined.func.ts index fb89c321..75126b56 100644 --- a/packages/type/src/is/lib/is-defined.func.ts +++ b/packages/type/src/is/lib/is-defined.func.ts @@ -1,9 +1,11 @@ -import { IsDefined } from '../type/is-defined.type'; +// Function. import { typeOf } from '../../lib/type-of.func'; +// Type. +import { IsDefined } from '../type/is-defined.type'; /** - * Checks if an unknown `value` is NOT an `'undefined'` type and is not equal to `undefined`. - * @param value An unknown `value` to check if it's NOT an `'undefined'` type and is not equal to `undefined`. - * @returns boolean. + * Checks if an unknown `value` is NOT an `undefined` type and is NOT equal to `undefined`. + * @param value An unknown `value` to check. + * @returns A `boolean` indicating whether or not the `value` is defined. */ export const isDefined: IsDefined = (value: unknown): boolean => typeOf(value) !== 'undefined' && From 18cf332d90aa40b2d6d5247e16b063a6dd8d4736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 20 Apr 2021 14:32:08 +0200 Subject: [PATCH 022/201] docs(README.md): update. --- README.md | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 78219b2f..b9f72d6e 100644 --- a/README.md +++ b/README.md @@ -241,7 +241,7 @@ const areString = (...args: any): boolean => check('string', ...args); ### isArray -Use `isArray()` or `is.array()` to check if **any** `value` is an `Array` of `'object'` generic `Type` type and `Array` instance. The return value is a `boolean` value. +Use `isArray()` or `is.array()` to check if **any** `value` is an `Array`, `Array` instance and `object` type. The return value is a `boolean` value indicating whether or not the `value` is an `Array`. ```typescript const isArray: IsArray = (value: any): value is Array => @@ -253,13 +253,13 @@ const isArray: IsArray = (value: any): value is Array => | Parameter | Type | Description | |-----------| :---: |-------------| -| value | `any` | Any `value` to check if it's an `Array` of `'object'` generic `Type` type and `Array` instance. | +| value | `any` | Any `value` to check. | [Example usage][is-array] ### isBigInt -Use `isBigInt()` or `is.bigInt()` to check if **any** `value` is a `'bigint'` type. The return value is a `boolean` value. +Use `isBigInt()` or `is.bigInt()` to check if **any** `value` is a `bigint` type. The return value is a `boolean` value indicating whether or not the `value` is a `bigint`. ```typescript const isBigInt: IsBigInt = (value: any): value is bigint => @@ -269,42 +269,29 @@ const isBigInt: IsBigInt = (value: any): value is bigint => | Parameter | Type | Description | |-----------| :---: |-------------| -| value | `any` | Any `value` to check if it's a `'bigint'` type. | +| value | `any` | Any `value` to check. | [Example usage][is-bigint] | [How to detect 'bigint' type][detect-bigint] ### isBoolean -Use `isBoolean()` or `is.boolean()` to check if **any** `value` is a `'boolean'` type not instance of `Boolean` and `Object` or `'object'` type instance of `Boolean` and `Object`. The return value is a `boolean` value. +Use `isBoolean()` or `is.boolean()` to check if **any** `value` is a `boolean` type not instance of `Boolean` and `Object` or `object` type instance of `Boolean` and `Object`. The return value is a `boolean` indicating whether or not the `value` is a `boolean`. ```typescript const isBoolean: IsBoolean = (value: any): value is boolean => typeOf(value) === 'boolean' && - ( - ( - typeof value === 'object' && - value instanceof Boolean === true && - value instanceof Object === true - ) - || - ( - value instanceof Boolean === false && - value instanceof Object === false && - typeof value === 'boolean' && - (value === true || value === false) - ) - ); + (isBooleanObject(value) || isBooleanType(value)); ``` | Parameter | Type | Description | |-----------| :---: |-------------| -| value | `any` | Any `value` to check if it's a `'boolean'` type not instance of `Boolean` and `Object` or `'object'` type instance of `Boolean` and `Object`. | +| value | `any` | Any `value` to check. | [Example usage][is-boolean] | [How to detect 'boolean' type][detect-boolean] ### isDefined -Use `isDefined()` or `is.defined()` to check if an **unknown** `value` is NOT an `'undefined'` type and is not equal to `undefined`. The return value is a `boolean` value. +Use `isDefined()` or `is.defined()` to check if an **unknown** `value` is NOT an `'undefined'` type and is NOT equal to `undefined`. The return value is a `boolean` indicating whether or not the `value` is defined. ```typescript const isDefined: IsDefined = (value: unknown): boolean => @@ -315,11 +302,13 @@ const isDefined: IsDefined = (value: unknown): boolean => | Parameter | Type | Description | |-----------| :-------: |-------------| -| value | `unknown` | An unknown `value` to check if it's NOT an `'undefined'` type and is not equal to `undefined`. | +| value | `unknown` | An unknown `value` to check. | ### isFunction -Use `isFunction()` or `is.function()` to check if **any** `value` is a `'function'` type, instance of `Function`, and `Object`. The return value is a `boolean` value. +Use `isFunction()` or `is.function()` to check if **any** `value` is a `'function'` type, instance of `Function`, and `Object`. + +#### Syntax ```typescript const isFunction: IsFunction = (value: any): value is Func => @@ -329,9 +318,17 @@ const isFunction: IsFunction = (value: any): value is Func => value instanceof Object === true; ``` +#### Parameters + | Parameter | Type | Description | |-----------| :---: |-------------| -| value | `any` | Any `value` to check it's a `'function'` type, instance of `Function` and `Object`. | +| value | `any` | Any `value` to check. | + +#### Return value + +The return value is a `boolean` indicating whether or not the `value` is a `function`. + +#### Examples [Example usage][is-function] | [How to detect 'function' type][detect-function] From 21bcdd4867bad04b7ac541e4a0a671e6d22050aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 20 Apr 2021 14:34:49 +0200 Subject: [PATCH 023/201] docs(README.md): update. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b9f72d6e..723b2a60 100644 --- a/README.md +++ b/README.md @@ -304,6 +304,8 @@ const isDefined: IsDefined = (value: unknown): boolean => |-----------| :-------: |-------------| | value | `unknown` | An unknown `value` to check. | +---- + ### isFunction Use `isFunction()` or `is.function()` to check if **any** `value` is a `'function'` type, instance of `Function`, and `Object`. From 1dfdd2379085bac803783a1456624b40a8289103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 20 Apr 2021 16:45:40 +0200 Subject: [PATCH 024/201] docs(README.md): update. --- README.md | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 723b2a60..6dcaffd4 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Useful packages based on the [angular.io](https://angular.io/). | prism | `Prism` highlighter module. | *In Progress* | [Readme][prism-readme-github] | | property | Features to handle properties. | *In Progress* | [Readme][property-readme-github] | | ui | User interface based on **[Spectre.css](https://github.com/picturepan2/spectre)**. | *In Progress* | [Github][ui-readme-github] | -| type | Common types, type guards and checkers. | [![npm version][type-npm-svg]][type-npm-badge] | [Github][type-readme-github] \| [npm][type-readme-npm] | +| type | Common types, type guards and type checkers. | [![npm version][type-npm-svg]][type-npm-badge] | [Github][type-readme-github] \| [npm][type-readme-npm] | ## angular-package/type @@ -223,6 +223,8 @@ const isNot: IsNot = { }; ``` +---- + ## Checks ### areString @@ -239,9 +241,11 @@ const areString = (...args: any): boolean => check('string', ...args); [Example usage][are-string] +---- + ### isArray -Use `isArray()` or `is.array()` to check if **any** `value` is an `Array`, `Array` instance and `object` type. The return value is a `boolean` value indicating whether or not the `value` is an `Array`. +Use `isArray()` or `is.array()` to check if **any** `value` is an `Array`, `Array` instance and `object` type. ```typescript const isArray: IsArray = (value: any): value is Array => @@ -255,11 +259,15 @@ const isArray: IsArray = (value: any): value is Array => |-----------| :---: |-------------| | value | `any` | Any `value` to check. | +The **return value** is a `boolean` value indicating whether or not the `value` is an `Array`. + [Example usage][is-array] +---- + ### isBigInt -Use `isBigInt()` or `is.bigInt()` to check if **any** `value` is a `bigint` type. The return value is a `boolean` value indicating whether or not the `value` is a `bigint`. +Use `isBigInt()` or `is.bigInt()` to check if **any** `value` is a `bigint` type. ```typescript const isBigInt: IsBigInt = (value: any): value is bigint => @@ -271,6 +279,8 @@ const isBigInt: IsBigInt = (value: any): value is bigint => |-----------| :---: |-------------| | value | `any` | Any `value` to check. | +The **return value** is a `boolean` value indicating whether or not the `value` is a `bigint`. + [Example usage][is-bigint] | [How to detect 'bigint' type][detect-bigint] ### isBoolean @@ -308,7 +318,7 @@ const isDefined: IsDefined = (value: unknown): boolean => ### isFunction -Use `isFunction()` or `is.function()` to check if **any** `value` is a `'function'` type, instance of `Function`, and `Object`. +Use `isFunction()` or `is.function()` to check if **any** `value` is a `'function'` type, instance of `Function`, and `Object`. #### Syntax @@ -320,20 +330,16 @@ const isFunction: IsFunction = (value: any): value is Func => value instanceof Object === true; ``` -#### Parameters - | Parameter | Type | Description | |-----------| :---: |-------------| | value | `any` | Any `value` to check. | -#### Return value - -The return value is a `boolean` indicating whether or not the `value` is a `function`. - -#### Examples +The **return value** is a `boolean` indicating whether or not the `value` is a `function`. [Example usage][is-function] | [How to detect 'function' type][detect-function] +---- + ### isInstance Use `isInstance()` or `is.instance()` to check if **any** value is a generic `Obj` type `constructor` instance and is an `Object`. @@ -350,8 +356,12 @@ const isInstance: IsInstance = (value: any, instance: Constructor): va | value | `any` | Any generic `Obj` type `value` instance to compare with `type` instance. | | type | `Constructor` | Creates generic `Obj` type instance to compare with argument `value`. | +The **return value** is a `boolean` indicating whether or not the `value` is a `function`. + [Example usage][is-instance] | [How to detect `constructor` instance][detect-instance] +---- + ### isNull Use `isNull()` or `is.null()` to check if **any** `value` is an `'object'` type and equal to `null`. From 3199806d095e32aad33bcec7055c17e8412f1f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 20 Apr 2021 16:52:04 +0200 Subject: [PATCH 025/201] chore(isFunction): reorder imports, update jsdoc. --- packages/type/src/is/lib/is-function.func.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/type/src/is/lib/is-function.func.ts b/packages/type/src/is/lib/is-function.func.ts index 0d055f0d..6d215f86 100644 --- a/packages/type/src/is/lib/is-function.func.ts +++ b/packages/type/src/is/lib/is-function.func.ts @@ -1,10 +1,12 @@ +// Function. import { IsFunction } from '../type/is-function.type'; -import { Func } from '../../type/func.type'; import { typeOf } from '../../lib/type-of.func'; +// Type. +import { Func } from '../../type/func.type'; /** - * Checks if any `value` is a `'function'` type, instance of `Function` and `Object`. - * @param value Any `value` to check if it's a `'function'` type, instance of `Function` and `Object`. - * @returns boolean. + * Checks if any `value` is a `function` type, instance of `Function` and `Object`. + * @param value Any `value` to check. + * @returns A `boolean` indicating whether or not the `value` is a `function`. */ export const isFunction: IsFunction = (value: any): value is Func => typeOf(value) === 'function' && From b9b75b8b92457e45edaf09ab08f80a6381500a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 20 Apr 2021 17:06:25 +0200 Subject: [PATCH 026/201] docs(README.md): update. --- README.md | 72 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6dcaffd4..893be079 100644 --- a/README.md +++ b/README.md @@ -223,8 +223,6 @@ const isNot: IsNot = { }; ``` ----- - ## Checks ### areString @@ -261,7 +259,16 @@ const isArray: IsArray = (value: any): value is Array => The **return value** is a `boolean` value indicating whether or not the `value` is an `Array`. -[Example usage][is-array] +```typescript +// Example usage +const ARRAY_NUMBER = [1, 2, 3]; +const ARRAY_STRING = ['a', 'b', 'c']; + +isArray(ARRAY_NUMBER); // true +isArray(ARRAY_STRING); // true +``` + +[Example usage playground][is-array] ---- @@ -281,7 +288,9 @@ const isBigInt: IsBigInt = (value: any): value is bigint => The **return value** is a `boolean` value indicating whether or not the `value` is a `bigint`. -[Example usage][is-bigint] | [How to detect 'bigint' type][detect-bigint] +[Example usage][is-bigint] | [How to detect `bigint` type][detect-bigint] + +---- ### isBoolean @@ -299,9 +308,11 @@ const isBoolean: IsBoolean = (value: any): value is boolean => [Example usage][is-boolean] | [How to detect 'boolean' type][detect-boolean] +---- + ### isDefined -Use `isDefined()` or `is.defined()` to check if an **unknown** `value` is NOT an `'undefined'` type and is NOT equal to `undefined`. The return value is a `boolean` indicating whether or not the `value` is defined. +Use `isDefined()` or `is.defined()` to check if an **unknown** `value` is NOT an `'undefined'` type and is NOT equal to `undefined`. ```typescript const isDefined: IsDefined = (value: unknown): boolean => @@ -314,13 +325,13 @@ const isDefined: IsDefined = (value: unknown): boolean => |-----------| :-------: |-------------| | value | `unknown` | An unknown `value` to check. | +The **return value** is a `boolean` indicating whether or not the `value` is defined. + ---- ### isFunction -Use `isFunction()` or `is.function()` to check if **any** `value` is a `'function'` type, instance of `Function`, and `Object`. - -#### Syntax +Use `isFunction()` or `is.function()` to check if **any** `value` is a `function` type, instance of `Function`, and `Object`. ```typescript const isFunction: IsFunction = (value: any): value is Func => @@ -336,7 +347,7 @@ const isFunction: IsFunction = (value: any): value is Func => The **return value** is a `boolean` indicating whether or not the `value` is a `function`. -[Example usage][is-function] | [How to detect 'function' type][detect-function] +[Example usage][is-function] | [How to detect `function` type][detect-function] ---- @@ -379,6 +390,8 @@ const isNull: IsNull = (value: any): value is null => [Example usage][is-null] | [How to detect `null` type][detect-null] +---- + ### isNumber Use `isNumber()` or `is.number()` to check if **any** `value` is a '`number`' type not instance of `Number` and `Object` or `'object'` type instance of `Number` and `Object`. The return value is a `boolean` value. @@ -408,6 +421,8 @@ const isNumber: IsNumber = (value: any): value is number => [Example usage][is-number] | [How to detect `'number'` type][detect-number] +---- + ### isObject Use `isObject()` or `is.object()` to check if **any** `value` is a generic `Obj` `'object'` type and `Object` instance with the possibility of containing `key`. The return value is a `boolean` value. @@ -430,6 +445,8 @@ const isObject: IsObject = (value: any, key?: string): value is Obj => [Example usage][is-object] | [How to detect `'object'` type][detect-object] +---- + ### isPrimitive Use `isPrimitive()` or `is.primitive()` to check if **any** `value` is a generic `Type` type one of the primitive `'boolean'`, `'bigint'`, `'number'`, `'string'`, `'symbol'`, `'undefined'` type. The return value is a `boolean` value. @@ -456,6 +473,8 @@ const isPrimitive: IsPrimitive = (value: any, type: Primitives): value is [Example usage][is-primitive] +---- + ### isString Use `isString()` or `is.string()` to check if **any** `value` is a `'string'` type, not instance of `Object` and `String` or `'object'` type and instance of `String` and `Object`. The return value is a `boolean` value. @@ -482,6 +501,8 @@ const isString: IsString = (value: any): value is string => [Example usage][is-string] | [How to detect `'string'` type][detect-string] +---- + ### isSymbol Use `isSymbol()` or `is.symbol()` to check if **any** `value` is a `'symbol'` type. The return value is a `boolean` value. @@ -498,6 +519,8 @@ const isSymbol: IsSymbol = (value: any): value is symbol => [Example usage][is-symbol] | [How to detect `'symbol'` type][detect-symbol] +---- + ### isType Use `isType()` or `is.type()` Check if **any** `value` is a generic `Type` type constructor, `'function'`, `'object'` or primitive type. The return value is a `boolean` value. @@ -527,6 +550,8 @@ const isType: IsType = (value: any, type: Types): value is Type => { [Example usage][is-type] +---- + ### isUndefined Use `isUndefined()` or `is.undefined()` to check if **any** `value` is an `'undefined'` type and equal to `undefined`. The return value is a `boolean` value. @@ -544,6 +569,8 @@ const isUndefined: IsUndefined = (value: any): value is undefined => [Example usage][is-undefined] | [How to detect `'undefined'` type][detect-undefined] +---- + ### isNotBoolean Use `isNotBoolean()` or `is.not.boolean()` to check if an **unknown** `value` is NOT a `'boolean'` type, NOT equal to `true` or `false` and NOT an instance of a `Boolean`. The return value is a `boolean` value. @@ -561,6 +588,8 @@ const isNotBoolean: IsNotBoolean = (value: unknown): boolean => |-----------| :-------: |-------------| | value | `unknown` | An unknown `value` to check if it's NOT a `'boolean'` type, NOT equal to `true` or `false` and NOT an instance of `Boolean`. | +---- + ### isNotDefined Use `isNotDefined()` or `is.not.defined()` to check if an **unknown** `value` is an `'undefined'` type and is equal to `undefined`. The return value is a `boolean` value. @@ -576,6 +605,9 @@ const isNotDefined: IsNotDefined = (value: unknown): boolean => |-----------| :-------: |-------------| | value | `unknown` | An unknown `value` to check if it's an `'undefined'` type and is equal to `undefined`. | + +---- + ### isNotFunction Use `isNotFunction()` or `is.not.function()` to check if an **unknown** `value` is NOT a `'function'` type and NOT an instance of `Function`. The return value is a `boolean` value. @@ -591,6 +623,8 @@ const isNotFunction: IsNotFunction = (value: unknown): boolean => |-----------| :-------: |-------------| | value | `unknown` | An unknown `value` to check if it's NOT a `'function'` type and NOT an instance of `Function`. | +---- + ### isNotNull Use `isNotNull()` or `is.not.null()` to check if an **unknown** `value` is NOT a `'null'` type and NOT equal to `null`. The return value is a `boolean` value. @@ -605,6 +639,8 @@ const isNotNull: IsNotNull = (value: unknown): boolean => |-----------| :-------: |-------------| | value | `unknown` | An unknown `value` to check if it's NOT a `'null'` type and NOT equal to `null`. | +---- + ### isNotNumber Use `isNotNumber()` or `is.not.number()` to check if an **unknown** `value` is NOT a `'number'` type and NOT an instance of `Number`. The return value is a `boolean` value. @@ -621,6 +657,8 @@ const isNotNumber: IsNotNumber = (value: any): boolean => |-----------| :-------: |-------------| | value | `unknown` | An unknown value to check if it's NOT a `'number'` type and NOT an instance of `Number`. | +---- + ### isNotString Use `isNotString()` or `is.not.string()` to check if an **unknown** `value` is NOT a `'string'` type and NOT an instance of `String`. The return value is a `boolean` value. @@ -636,6 +674,8 @@ const isNotString: IsNotString = (value: unknown): boolean => |-----------| :-------: |-------------| | value | `unknown` | An unknown `value` to check if it's NOT a `'string'` type or NOT an `'object'` type and NOT an instance of `String`. | +---- + ### isNotUndefined Use `isNotUndefined()` or `is.not.undefined()` to check if an **unknown** `value` is NOT an `'undefined'` type and NOT equal to `undefined`. The return value is a `boolean` value. @@ -667,6 +707,8 @@ const guardArray: GuardArray = (value: Array): value is Array [Example usage][guard-array] +---- + ### guardFunction Use `guardFunction()` or `guard.is.function()` to guard the `func` value to be a `Func` type. The return value is a `boolean` value. @@ -681,6 +723,8 @@ const guardFunction: GuardFunction = (func: Func): func is Func => isFunction(fu [Example usage][guard-function] +---- + ### guardNumber Use `guardNumber()` or `guard.is.number()` to guard the `value` to be a `number` type. The return value is a `boolean` value. @@ -695,6 +739,8 @@ const guardNumber: GuardNumber = (value: number): value is number => isNumber(va [Example usage][guard-number] +---- + ### guardObject Use `guardObject()` or `guard.is.object()` to guard the `object` value to be a generic `Obj` type. The return value is a `boolean` value. @@ -709,6 +755,8 @@ const guardObject: GuardObject = (object: Obj): object is Obj => isObject(object: Obj, [Example usage][guard-object-key] +---- + ### guardPrimitive Use `guardPrimitive()` or `guard.is.primitive()` to guard the `value` to be a generic `Type` from one of the `Primitives`. The return value is a `boolean` value. @@ -740,6 +790,8 @@ const guardPrimitive: GuardPrimitive = (value: Type, type: Primitives): va [Example usage][guard-primitive] +---- + ### guardString Use `guardString()` or `guard.is.string()` to guard the `value` to be a `string` type. The return value is a `boolean` value. @@ -754,6 +806,8 @@ const guardString: GuardString = (value: string): value is string => isString(va [Example usage][guard-string] +---- + ### guardType Use `guardType()` or `guard.is.type()` to guard the `value` to be a generic `Type` type from one of the `Types` type. The return value is a `boolean` value. From c7daf4a382c9d2d3db70c7cbfc4740fba388a9a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 20 Apr 2021 22:58:23 +0200 Subject: [PATCH 027/201] docs(isFunction): update. --- packages/type/src/is/lib/is-function.func.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/is/lib/is-function.func.ts b/packages/type/src/is/lib/is-function.func.ts index 6d215f86..b79c0638 100644 --- a/packages/type/src/is/lib/is-function.func.ts +++ b/packages/type/src/is/lib/is-function.func.ts @@ -4,7 +4,7 @@ import { typeOf } from '../../lib/type-of.func'; // Type. import { Func } from '../../type/func.type'; /** - * Checks if any `value` is a `function` type, instance of `Function` and `Object`. + * Checks if any `value` is a `function` type, an instance `Function` and `Object`. * @param value Any `value` to check. * @returns A `boolean` indicating whether or not the `value` is a `function`. */ From dd5d522706f0b69931b4338c0f3891ade8bda5a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 20 Apr 2021 22:59:27 +0200 Subject: [PATCH 028/201] chore(isFunction): move import to type. --- packages/type/src/is/lib/is-function.func.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/is/lib/is-function.func.ts b/packages/type/src/is/lib/is-function.func.ts index b79c0638..45e7ad65 100644 --- a/packages/type/src/is/lib/is-function.func.ts +++ b/packages/type/src/is/lib/is-function.func.ts @@ -1,8 +1,8 @@ // Function. -import { IsFunction } from '../type/is-function.type'; import { typeOf } from '../../lib/type-of.func'; // Type. import { Func } from '../../type/func.type'; +import { IsFunction } from '../type/is-function.type'; /** * Checks if any `value` is a `function` type, an instance `Function` and `Object`. * @param value Any `value` to check. From 989e49b4d7d9afb24633d4a98a8ddad9e5f9f8ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 20 Apr 2021 23:08:11 +0200 Subject: [PATCH 029/201] refactor(isInstance): update. - reorder imports. - use `isFunction` to check `instance`. - update jsdoc. --- packages/type/src/is/lib/is-instance.func.ts | 22 +++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/type/src/is/lib/is-instance.func.ts b/packages/type/src/is/lib/is-instance.func.ts index deef0e07..4a74c796 100644 --- a/packages/type/src/is/lib/is-instance.func.ts +++ b/packages/type/src/is/lib/is-instance.func.ts @@ -1,13 +1,19 @@ +// Function. +import { isObject } from './is-object.func'; +import { isString } from './is-string.func'; +// Type. import { Constructor } from '../../type/constructor.type'; import { IsInstance } from '../type/is-instance.type'; -import { isString } from './is-string.func'; -import { isObject } from './is-object.func'; +import { isFunction } from './is-function.func'; /** - * Checks if any `value` is a generic `Obj` type `constructor` instance and is an `Object`. - * @param value Any generic `Obj` type `value` instance to compare with `type` instance. - * @param instance Creates generic `Obj` type instance to compare with argument `value`. + * Checks if any `value` is an `object` of a generic `Obj` type equal to an `instance` of `Constructor` type. + * @param value Any `value` to compare with the `instance`. + * @param instance The name of the generic `Obj` type to create an `instance` to compare with the `value`. + * @returns A `boolean` indicating whether or not the `value` is an `instance`. */ export const isInstance: IsInstance = (value: any, instance: Constructor): value is Obj => - isObject(value) && - value instanceof instance === true && - isString(instance.prototype.constructor.name); + isObject(value) ? + isFunction(instance) ? + value instanceof instance === true && isString(instance.prototype.constructor.name) + : false + : false; From 8720171be4d501b797a1678f947ba4288d4f32b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 20 Apr 2021 23:16:05 +0200 Subject: [PATCH 030/201] refactor(IsKey): change parameter name, and result boolean. --- packages/type/src/is/type/is-key.type.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/is/type/is-key.type.ts b/packages/type/src/is/type/is-key.type.ts index c1e7f554..68d8a627 100644 --- a/packages/type/src/is/type/is-key.type.ts +++ b/packages/type/src/is/type/is-key.type.ts @@ -1,2 +1,2 @@ import { Key } from '../../type/key.type'; -export type IsKey = (name: Key) => boolean; +export type IsKey = (value: any) => value is Key; From 1a59555be8b8081ba84701296d3324760ecc1aa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 20 Apr 2021 23:17:50 +0200 Subject: [PATCH 031/201] refactor(isKey): update. - reorder imports. - import `Key` type. - boolean result is `Key`. - update jsdoc. --- packages/type/src/is/lib/is-key.func.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/type/src/is/lib/is-key.func.ts b/packages/type/src/is/lib/is-key.func.ts index 9c3f5a94..e3cf5f97 100644 --- a/packages/type/src/is/lib/is-key.func.ts +++ b/packages/type/src/is/lib/is-key.func.ts @@ -1,13 +1,13 @@ // Function. -import { isString } from './is-string.func'; import { isNumber } from './is-number.func'; +import { isString } from './is-string.func'; import { isSymbol } from './is-symbol.func'; // Type. import { IsKey } from '../type/is-key.type'; - +import { Key } from '../../type/key.type'; /** - * Determines if any `value` is one of the string, number, or symbol type. - * @param value Any value to check. - * @returns A boolean indicating whether or not the value is one of the string, number or symbol type. + * Determines if any `value` is one of the `string`, `number`, or `symbol`. + * @param value Any `value` to check. + * @returns A `boolean` indicating whether or not the `value` is a `Key` type. */ -export const isKey: IsKey = (value: any): boolean => isString(value) || isNumber(value) || isSymbol(value); +export const isKey: IsKey = (value: any): value is Key => isString(value) || isNumber(value) || isSymbol(value); From 9fbc21909a330e64829c8b681c3e4784ea8fc564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 20 Apr 2021 23:44:22 +0200 Subject: [PATCH 032/201] chore(isNull): reorders imports, update jsdoc. --- packages/type/src/is/lib/is-null.func.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/type/src/is/lib/is-null.func.ts b/packages/type/src/is/lib/is-null.func.ts index bd32b7af..528dfd06 100644 --- a/packages/type/src/is/lib/is-null.func.ts +++ b/packages/type/src/is/lib/is-null.func.ts @@ -1,9 +1,11 @@ -import { IsNull } from '../type/is-null.type'; +// Function. import { typeOf } from '../../lib/type-of.func'; +// Type. +import { IsNull } from '../type/is-null.type'; /** - * Checks if any `value` is an `'object'` type and equal to `null`. - * @param value Any `value` to check if it's a `null` value and an `'object'` type. - * @returns boolean + * Checks if any `value` is an `object` type and equal to `null`. + * @param value Any `value` to check. + * @returns A `boolean` indicating whether or not the `value` is `null`. */ export const isNull: IsNull = (value: any): value is null => typeOf(value) === 'null' && From 7204cf331cfa7c6bef122723a2e7525b5f678078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 20 Apr 2021 23:46:12 +0200 Subject: [PATCH 033/201] refactor(isKey): check number as first. --- packages/type/src/is/lib/is-key.func.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/is/lib/is-key.func.ts b/packages/type/src/is/lib/is-key.func.ts index e3cf5f97..bb92a4bf 100644 --- a/packages/type/src/is/lib/is-key.func.ts +++ b/packages/type/src/is/lib/is-key.func.ts @@ -10,4 +10,4 @@ import { Key } from '../../type/key.type'; * @param value Any `value` to check. * @returns A `boolean` indicating whether or not the `value` is a `Key` type. */ -export const isKey: IsKey = (value: any): value is Key => isString(value) || isNumber(value) || isSymbol(value); +export const isKey: IsKey = (value: any): value is Key => isNumber(value) || isString(value) || isSymbol(value); From c943239f325fef63e0565dbcae3ce4aae6300ac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 20 Apr 2021 23:57:14 +0200 Subject: [PATCH 034/201] docs(README.md): update. --- README.md | 151 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 111 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 893be079..cd476953 100644 --- a/README.md +++ b/README.md @@ -237,7 +237,7 @@ const areString = (...args: any): boolean => check('string', ...args); |-----------| :---: |-------------| | ...args | `any` | Any arguments to check they're all a `'string'` type. | -[Example usage][are-string] +[Example usage on playground][are-string] ---- @@ -257,7 +257,7 @@ const isArray: IsArray = (value: any): value is Array => |-----------| :---: |-------------| | value | `any` | Any `value` to check. | -The **return value** is a `boolean` value indicating whether or not the `value` is an `Array`. +The **return value** is a `boolean` indicating whether or not the `value` is an `Array`. ```typescript // Example usage @@ -268,7 +268,7 @@ isArray(ARRAY_NUMBER); // true isArray(ARRAY_STRING); // true ``` -[Example usage playground][is-array] +[Example usage on playground][is-array] ---- @@ -286,15 +286,24 @@ const isBigInt: IsBigInt = (value: any): value is bigint => |-----------| :---: |-------------| | value | `any` | Any `value` to check. | -The **return value** is a `boolean` value indicating whether or not the `value` is a `bigint`. +The **return value** is a `boolean` indicating whether or not the `value` is a `bigint`. -[Example usage][is-bigint] | [How to detect `bigint` type][detect-bigint] +```typescript +// Example usage +const BIGINT = 9007199254740991n; +const NUMBER = 27; + +isBigInt(NUMBER); // false +isBigInt(BIGINT); // true +``` + +[Example usage on playground][is-bigint] | [How to detect `bigint` type][detect-bigint] ---- ### isBoolean -Use `isBoolean()` or `is.boolean()` to check if **any** `value` is a `boolean` type not instance of `Boolean` and `Object` or `object` type instance of `Boolean` and `Object`. The return value is a `boolean` indicating whether or not the `value` is a `boolean`. +Use `isBoolean()` or `is.boolean()` to check if **any** `value` is a `boolean` type not instance of `Boolean` and `Object` or `object` type instance of `Boolean` and `Object`. ```typescript const isBoolean: IsBoolean = (value: any): value is boolean => @@ -306,7 +315,18 @@ const isBoolean: IsBoolean = (value: any): value is boolean => |-----------| :---: |-------------| | value | `any` | Any `value` to check. | -[Example usage][is-boolean] | [How to detect 'boolean' type][detect-boolean] +The **return value** is a `boolean` indicating whether or not the `value` is a `boolean`. + +```typescript +// Example usage +const BIGINT = 9007199254740991n; +const NUMBER = 27; + +isBigInt(NUMBER); // false +isBigInt(BIGINT); // true +``` + +[Example usage on playground][is-boolean] | [How to detect `boolean` type][detect-boolean] ---- @@ -327,11 +347,20 @@ const isDefined: IsDefined = (value: unknown): boolean => The **return value** is a `boolean` indicating whether or not the `value` is defined. +```typescript +// Example usage +const UNDEFINED = undefined; +let defined; + +isDefined(UNDEFINED); // false +isDefined(defined); // false +``` + ---- ### isFunction -Use `isFunction()` or `is.function()` to check if **any** `value` is a `function` type, instance of `Function`, and `Object`. +Use `isFunction()` or `is.function()` to check if **any** `value` is a `function` type, an instance `Function` and `Object`. ```typescript const isFunction: IsFunction = (value: any): value is Func => @@ -347,35 +376,76 @@ const isFunction: IsFunction = (value: any): value is Func => The **return value** is a `boolean` indicating whether or not the `value` is a `function`. -[Example usage][is-function] | [How to detect `function` type][detect-function] +```typescript +// Example usage +class Class { x = 5; } +const FUNC: Func = (x: number): any => { return x + 5; } + +isFunction(Class); // true +isFunction(FUNC); // true +isFunction(() => 5); // true +``` + +[Example usage on playground][is-function] | [How to detect `function` type][detect-function] ---- ### isInstance -Use `isInstance()` or `is.instance()` to check if **any** value is a generic `Obj` type `constructor` instance and is an `Object`. +Use `isInstance()` or `is.instance()` to check if **any** value is an `object` of a generic `Obj` type equal to an `instance` of `Constructor` type. ```typescript const isInstance: IsInstance = (value: any, instance: Constructor): value is Obj => - isObject(value) && - value instanceof instance === true && - isString(instance.prototype.constructor.name) === true; + isObject(value) ? + isFunction(instance) ? + value instanceof instance === true && isString(instance.prototype.constructor.name) + : false + : false; ``` | Parameter | Type | Description | |-----------| :----------------: |-------------| -| value | `any` | Any generic `Obj` type `value` instance to compare with `type` instance. | -| type | `Constructor` | Creates generic `Obj` type instance to compare with argument `value`. | +| value | `any` | Any `value` to compare with the `instance`. | +| instance | `Constructor` | The name of the generic `Obj` type to create an `instance` to compare with the `value`. | -The **return value** is a `boolean` indicating whether or not the `value` is a `function`. +The **return value** is a `boolean` indicating whether or not the `value` is an `instance`. + +```typescript +// Example usage +class Some { x = 127; } +class Two { y = 'Lorem ipsum'; } -[Example usage][is-instance] | [How to detect `constructor` instance][detect-instance] +const SOME = new Some(); +const TWO = new Two(); + +isInstance(TWO, SOME); // false +isInstance(SOME, SOME); // true +isInstance(TWO, TWO); // true and type error +``` + +[Example usage on playground][is-instance] | [How to detect `constructor` instance][detect-instance] + +---- + +### isKey + +Use `isKey()` or `is.key()` to determine if **any** `value` is one of the `string`, `number`, or `symbol`. + +```typescript +const isKey: IsKey = (value: any): value is Key => isString(value) || isNumber(value) || isSymbol(value); +``` + +| Parameter | Type | Description | +|-----------| :---: |-------------| +| value | `any` | Any `value` to check. | + +The **return value** is a `boolean` indicating whether or not the `value` is a `Key` type. ---- ### isNull -Use `isNull()` or `is.null()` to check if **any** `value` is an `'object'` type and equal to `null`. +Use `isNull()` or `is.null()` to check if **any** `value` is an `object` type and equal to `null`. ```typescript const isNull: IsNull = (value: any): value is null => @@ -386,40 +456,41 @@ const isNull: IsNull = (value: any): value is null => | Parameter | Type | Description | |-----------| :---: |-------------| -| value | `any` | Any `value` to check if it's a `null` value and an `'object'` type. | +| value | `any` | Any `value` to check. | + +The **return value** is a `boolean` indicating whether or not the `value` is `null`. + +```typescript +// Example usage +const NULL = null; +const NUMBER = 27; + +isNull(NULL); // true +isNull(NUMBER); // false +``` -[Example usage][is-null] | [How to detect `null` type][detect-null] +[Example usage on playground][is-null] | [How to detect `null` type][detect-null] ---- ### isNumber -Use `isNumber()` or `is.number()` to check if **any** `value` is a '`number`' type not instance of `Number` and `Object` or `'object'` type instance of `Number` and `Object`. The return value is a `boolean` value. +Use `isNumber()` or `is.number()` to check if **any** `value` is a '`number`' type not an instance of `Number` and `Object` or `'object'` type instance of `Number` and `Object`. ```typescript const isNumber: IsNumber = (value: any): value is number => typeOf(value) === 'number' && - ( - isFinite(value) === true && - ( - value instanceof Number === false && - value instanceof Object === false && - typeof value === 'number' - ) - || - ( - typeof value === 'object' && - value instanceof Number === true && - value instanceof Object === true - ) - ); + isFinite(value) === true && + (isNumberObject(value) || isNumberType(value)); ``` | Parameter | Type | Description | |-----------| :---: |-------------| -| value | `any` | Any ``value`` to check if it's a `'number'` type not instance of `Number` and `Object` or `'object'` type instance of `Number` and `Object`. | +| value | `any` | Any ``value`` to check. | + +The return value is a `boolean` indicating whether or not the `value` is a `number`. -[Example usage][is-number] | [How to detect `'number'` type][detect-number] +[Example usage on playground][is-number] | [How to detect `number` type][detect-number] ---- @@ -922,9 +993,9 @@ MIT © angular-package ([license](https://github.com/angular-package/type/blob/m [is-array]: https://www.typescriptlang.org/play?jsx=0#code/MYewdgzgLgBFCeAHApgeQGYwLwwBQDcBDAGwFdkAuGQseASiugCcBLMAc2wD4ZUAjAFbJgUAHSImIKFKTJR0gMpRWHUcBLECJcnVERiLYMlwAOADQwAtAEZd0gDIgA7siYBhQhGN0A3ACgEFBgABVYAWxYoFnxkbBg+EBBiZBoYAB94lnY2WAywUmJidJh8sL5XYuY2TgyIeDKk4tIwABNkdDZkFv9A2IBJCABBJiZCeDitMkpqWjpuGCIpmBYIGGHR+AAeGnguf1BIWBX1saoBk-GcTYAVWS5J8iodhgXtWJW1kbGbu+4-GDgsgwD2Qcyw4JgAHJCF94JCYAAyBH-T4bUTHWEgsEQ5TkRHIgGLPFsaA0IwgTAXbA4ph4pEo3oU15LcE4SEgQTCKCQ-bgaAwBTXABKfQAcgBxOKQxxMZBhZaICCkMIAfh5fgO-NFAFUALIAIQAokK4gAmADsvMOMH1qFQ9kNg1FcXQJC8Vv52tFABFDQAxMWG71xZptDpgLoe2CDIVCwYATUFIolVAumyqHB4OAA2tDIRZIXx81DgJCALpRtaxhM6g3G1OwzalcpMLMwbPWCymiwAZgrGr50er8eCIt1fWufQAaoaGxtNqEWBEojE29moRn2MWLRZcbF+5rYAApBSoUUAfSng3s2sNcQA3uhElRrKaewBfD1JOTEEDsXAAAZJmK4oARYGIbLgwESnQvgwAA9PBMCusQXgDpA36iL+-4AbWRpCmByxDJieHGrBPgIUhKFeDA6EQJh2GAba9qOqKhEQWMuDMQ6TrkZRyFusgdEMX+gFer6AaikG7HEZB4n+oG3p8YhAmoUJmoiThMZxomwogTJFy4NpCbQeKylIXuwnJFhokAcZ8akQR4GyZx9mOeZcC0upfKaYB9mjn046TjOBmYv5Y4TtOhoeZZGnWYxAEnmel7XreoWQUlF5Xje0VwSp1FCUAA [is-bigint]: https://www.typescriptlang.org/play?target=7&jsx=0#code/MYewdgzgLgBFCeAHApgeQGYwLwwBQDcBDAGwFdkAuGQseASiugCcBLMAc2wD4ZUAjAFbJgUAHSImIKFKTJR0gMpRWHUcBLECJcnVERiLYMlwAOADQwAtAEZd0gDIgA7siYBhQhGN0A3ACgEFBgASQgAIRZ2YLBYHC0ySmpaOm4YIgSYFggYPki2KH9QSFgsiKiYqlCy6Ni8dPIqGnoqeuRM7Nz2fO4-GDhZDHidbCwcAHJO-LGYADIZ3v6UEExWkfHJmLHC8GgYBQAVACVggDkAcWwYMccmZABbTMQIUjuAfi2-It2TgFUAWTCAFFDpcAEwAdm2xRgYVQqHsgIAgidLugSF4obswsEzqd9pcAJwABiJ4OsBIJoIArAAWcE0okU6xgTEgYhyYggdi4AAGB2O5x5FlKkRquH5pzOdF8MAA9LKYGjiF5Pjs2RyubzfgDgUL2tUYrhtUDDtKfHKFUqVV91aJOdyebD4UiTnqReUoLgnQjkWaLYr0chVZBbfbedjcSd9m7wqLDRG8X75XAmOQ-EA [is-boolean]: https://www.typescriptlang.org/play?target=7&jsx=0#code/MYewdgzgLgBFCeAHApgeQGYwLwwBQDcBDAGwFdkAuGQseASiugCcBLMAc2wD4ZUAjAFbJgUAHSImIKFKTJR0gMpRWHUcBLECJcnVERiLYMlwAOADQwAtAEZd0gDIgA7siYBhQhGN0A3ACgEFBgASQgAIRAQYmQabDwiMkpqWjpuGATyGBYIGD5I6Jp-UEhYbIiomLAqUPKCsDitRKoaeioM5CycvIrYrC4-GDhZDEadbCwcAHJuusmYADJ5gbxlwdxVwaGUEEx28amQQWEoOcWNwb22aBojHZhayv24Jkyzzc3LkpvkO-4hESeynIGzoGwAPmCNut3hdtB0rlBvncHr0JjB0CQvAsljD0nCsl8wLdMH9jk8McQsW8YYEfrt8RMpjNKqccTDRh1Gc9MhC8YlyZjkKD3sKYL4-MVoDAFAAVABKwQAcgBxOKTRxMZAAWyyiAgpC1AH5JkVwFLFQBVACyYQAonK4gAmADsppK91QqHstoAgoq4hSvG6pWFPd6-QB9eUW21xIHIYOwUNe32KiNK2V+tyxnBgZBOe75Sq4QNC4MVUTEEDsXAAA1lCpVtYsZSLNFwDaVyrovhgAHo++jBRKzRWqzXa5abfbm50UWBcFO7XKez5+4PSyPIGPq3Xk+HFbPWz0F-vU6v19zkFuIDuJ2fI9HbUfwm3T2HU1G5TGLwOrze7z3D9IwzGUs2fFtXxPXAHzTUDwN-Qd4z8IA -[is-function]: https://www.typescriptlang.org/play?target=7&jsx=0#code/MYewdgzgLgBFCeAHApgeQGYwLwwBQDcBDAGwFdkAuGQseASiugCcBLMAc2wD4ZUAjAFbJgUAHSImIKFKTJR0gMpRWHUcBLECJcnVERiLYMlwAOADQwAtAEZd0gDIgA7siYBhQhGN0A3ACgEFBgAMVIwYGw8UWjEQiZCAFsqGnpualp-QOQYAEkIUPCoFnBIrTJKdNSsHiJymBYIELDgf2BiT0a3dohGgG8YAA9IgFYfGABfP1BIWAaCkWKwKjz5opKcMvJk2gYYWvJ6xvnuPxg4WQxN5DpsLBwAcnRmtbB7mAAyd9PzlBBMfeydweT0Kizen2+APqMxoRj+TVB6zucCYBwhZyhbGgsOQ8P4QhEtxwynIrXA0BgACFUKh7ABRACCADlIiTkGSZlScgBxHJMgAqkQAnAAGEUAdmsQqFACZhgAWcXykXS6xgDkUpkAVQAspS6QAlSLWGXijWwBT8g187mRe46+AwMCkBJ8VyHe7mkJapluKjHDYDKjO12uXYpNL9JjIKCkJhgQYwADUMFGEym5NgfMtzLcdMiYGQThgXQ6uF8GcgIGIcmIIHYuAABqWeo2LHNnotcC2IHRfDAAPQDlHkSsQau1+u4e6Unl8-n3dv5TvgXCz3kCvtjIcwdAkLxjieiOsNmc0+nMxeHVZd6m0xlMreD4d74gH6bjmvHqf3bV6w1Xh2iJgLgf76gaT47q+77kkeJ7Tpa1pMtygHLsBuCITakEvvuyCHl+8GNsEPpuG214riBxG+thI54R+cE-tm-K5nSqE3quTEsTR0HIEAA -[is-instance]: https://www.typescriptlang.org/play?target=7&jsx=0#code/C4TwDgpgBAwg9gOwM7AE4FcDGw6oDwAq4EAfFALxQIQDuUAFAHTMCGqA5kgFxQsIgBtALoBKCmSKQA3AChQkKAEkki5MD6ZolPAHkARgCsS9AG4sANugg8+IADRQAlmo3XYiFBmy5dhkmPIyM0toRyQofQNZeWhlAGU0Z3YKBmCrG34AoIsrJ3DPJOjiJSRIiGwU3yNTHLdbBwBrCBAAfh4ChHYsqDTQ8MjZTA9gKBidADMUmpCMkBF2xM7xCMNy4EYwVDgcGMYcBNQkxkwLc2mrEUYkc0dNegAOBwBaAEZLnAAZOBoIVBgWJAQegiQbDPIHJI8eKLZKUc51TI8Xp5KAdWFkegxOCTZHkPFQADkcFW2AJUAAZOSerUnC4EJpsSsDGsKVTkc4UK5GRDOmIAD580bERm4-EEtEE0FqPJlbBQ0okkbaSLGXqzRrNNqomHzakhFGRcQyKBCyATeEBMXE5mk1nG00QEU0vGUImKsmU+3sukMyaypX4tBWe0mlrgmH0JpzCiBjAQEMmqBhqO0vW5F2jOOs1I0gFMy4ACwBOhoCAACltIKhQJHmpbKEH44moDxG-aeOMLICpSg8qpOfS3Mp++pB5UVfD1bSB5oePA1F4cPgVbr2f1DEaTWF-VVVbUxJ6Td6Z47JhzR5oYw2s4fw4dOvRz64NlsdsRjsNF7hGAgWABbCB60zKxZBkTBzABcI4jgACYAgpBwgAbygAAPFIXgAJgAdikKAAF8wPg8ICBoOA4MgqBkJAFICS+VAID-JwwCQdA-0lfCZBkAB6LioAANTYRwWD0cwICQMCwTiAgACVFAAOQAcQAfT4gBBD4AFUAFEaLohimJYv8WklCTpTkjSAFkACEtOklT1O0lJsJ7EYrJ0HQPi01S5PszSdMoTtzG7Uzew0uSABEtIAMXkrTwt87SlIIAB1HQUnQBAABMIHGZwIEy2RRJGMLIpiuS4oSrSXKgOIdAsrSYA+VS4jiFJqDoaDYKI4FqpSnRGua1rKHaqASLI7qQU4oZkDgUTGHMOB2EfFQfQgPBOogciEOMPqBpahwNq2pARBBKAeKgQLARC2aIHmxblpHVx1pgzaiOMWr6r2uIDpeo6Ttw8622mpAbrupawkewdnq6yCdtSr6HDGv7TsBuMZCAA -[is-null]: https://www.typescriptlang.org/play?target=7&jsx=0#code/C4TwDgpgBAkgzgOQK4BsVQLxQBQDcCGKSEAXFPgHYgCUmAfFAUdAJZxQWooDcAUAMYB7CnGBRQkAPIAzTDibEylGmVEAnFhQDm9KJIBGAKwj9gAOjBrBwa+AhmbAZWAbtZ-oRR5CxambgoLPwQ2AAcADRQALQAjH42ADKCAO4QagDC+HAh1HxCImJsyGhk8MXoWN7MSlTUZAqs7Jxo9LxQ4nYyVb6YGFgA5M0o-VAAZKNtHZCCsg29A4JGJsAj45NzfVhDecKiUI4AKgBKMAgA4nL9SWoQALZQLGBwSLcA-P07BVAIAKoJCXJtgJdmJfgBZABCAFEjnIAEwAdk+ewhkkkCShAEEEHJpIRssixKj0ViEAB9Y4-KFyFzEQlQYkY7Fk06HbHpalbCDJBmCQQoCCUbB4lDZXLAkT8+woQRabAAA0OJ3O8siRS42CVpzO1FyUAA9PqoCLshK4FKzDK5fLfv9VQ9EBrbQlddwDUbaRAzRarQrwdCjvb1WhsP6Ya73cb8V78uaBZbZQrGaSg46Q8nsRHDVHRTHdj7E-KM+TKVDU+VsMWKUcqVmjSa85L476i2imeTWQd2WW1WmvFXO926znTUA +[is-function]: https://www.typescriptlang.org/play?target=7&jsx=0#code/MYewdgzgLgBFCeAHApgeQGYwLwwBQDcBDAGwFdkAuGQseASiugCcBLMAc2wD4ZUAjAFbJgUAHSImIKFKTJR0gMpRWHUcBLECJcnVERiLYMlwAOADQwAtAEZd0gDIgA7siYBhQhGN0A3ACgEFBgAMVIwYGw8UWjEQiZCAFsqGnpualp-QOQYAEkIUPCoFnBIrTJKdNSsHiJymBYIELDgf2BiT0a3dohGgG8YAA9IgFYfGABfP1BIWAaCkWKwKjz5opKcMvJk2gYYWvJ6xvm0rIxN5DpsLBwAcnRmtbAbmAAyF7hZEEx97Ovb+8Ki2ebz22mybGgNCMXyagPW1zgTAOIJ+9RmUOQMP4QhEVxwynIrXA0BgACFUKh7ABRACCADlIgTkESZmScgBxHJ0gAqkQAnAAGAUAdmsfL5ACZhgAWYXSgXi6xgFkkukAVQAsqSqQAlSLWCXClWwBTcnVc9mRG4a+AwMCkBJ8VyHG7GkJquluKjHDYDKj2x2uXYpNL9JjIKCkJhgQYwADUMFGEymxNgXNN9LcVMiYGQThgXQ6uF8KcgIGIcmIIHYuAABoWerWLHMHotcA2IHRfDAAPQ9xHkUsQcuV6u4G6kjlc7k3Zv5VvgXCTzk8rtjPswdAkLxDkeiKs1icU6n02eHVZt8mU2l0te9-tb4g76bDiv7sc3dVa3VnltwsC4F+2o6neG6Ps+xJ7ge46muadLsr+87-rgsEWqBD7bsgu5vtBtbBB6bhNueC4AfhnroQOWEvlBH7ptymZUohF6LnRDEUeBVGQThY61sWaTDERf4LIufHVImFFMkAA +[is-instance]: https://www.typescriptlang.org/play?target=7&jsx=0&module=6#code/PTAEBUE8AcFMDoBQAXGtQGED2A7AzsgE4CuAxsloQDxRwB8oAvKDrAO6gAU8PAhoQHM8ALlC8ckANoBdAJRMGtWAG4UaUAEk8AMWI5yAS1xMuAN14AbYrFHjI8xg3NX0BvFx7xo-XgFtbEg4MdqqocJp4GvjI4qTozFQA8gBGAFZ0nM7WAZAANKAG0bE2mLgEJOSUSWl0QaBZru4pqaHqWgDKRIUCJpmW2WKBCvX9jaDl3a3hWs2w5CbV6X0uOfkA1rCQAPyiEzgCdQ0FTWmqIKC6+shGOEikZcigYbCJAGa9DTmyu137w7PkLyELAUZ7wCidQjdeCkSwWZbWWTwPAWAxxTgADnyAFoAIxIigAGSwbFghAwvDwsE4slU92ix0uhlwoi0TOuxmYCJKdm+Ixcxw8PG8hD8X2GdmGzze3IcjGYAHJXnpmTgFaAAGQap5oLDvI7yxXKq43dVa-nWApFfSwPUXFUcnBMeVPEjoc1HQoEYp2gGPQ2u6x0h7HSHdVl4MN-LmfQb2USe9x7HqOLjPO0Gl0KrBpObIM3az3WuK+3PzD2jK3em12qMHUAAHwbOrgGcrAYVyYVwYZbj9Eb9C2aJhzqTzGVjdnWmx241+BwTlbcoGHjkQoDTaBlDTlitHeYLLdt+vbWf35EPRerJfeg4DRER643oC2ofnnA29ifz5foE-VotWBv1AUQHyAjdRFeSwqR7Ahjiia8Si0BCYhtIcam5VYq1QuJRGwaIKgoahmlqRcBWXVc6CfPsy2QRYJ1GeQtmAtx2RuTgvRw2AmOAjcry4u1OOKZ1mDAzVtTcOsOOLBBoGBUE0BhB5CMoeAcD8bjgMg6DwJA0AoIsGDEEQUgLEpdx2iwXxYAwMy8HcABvUAAA8TFxAAmAB2ZRQAAX1AUzzIgNgsFsoKnMgEwFWJQhYF8ApoDwYhfG7PzjPOAA1fgDF4ZILFgPATJDdpwAAJQ0AA5ABxAB9DKAEFCQAVQAUSimK4oSpLfC2VL6TgiqmoAWQAIRa0q6sa1qTC8nz+seEbEkSQkWvqirJuatrmAMmCApDJqKoAERa7RKpaw6NtamrwAAdUSEw9AAE1gV5ClgR7VHyx4DuO06KvOy6Wtgx52kSIaWowQl6vadoTFYDhLOssL7JpOaQ1uxJIeh2HmHh4LQrsvBUeM-qsHy+ALCwAQOMiGSqERmzCYyDGsZh-IGeRvBZFpUBzh2oDSfJynqbcFDinpqzGfMjJQfB1n2nZyXOe5nzzjAor8DJhBhZpsWbQlpGmc4FmobZ-HlZ5tW3UQIA +[is-null]: https://www.typescriptlang.org/play?target=7&jsx=0&ssl=11&ssc=21&pln=11&pc=33#code/C4TwDgpgBAkgzgOQK4BsVQLxQBQDcCGKSEAXFPgHYgCUmAfFAUdAJZxQWooDcAUAMYB7CnGBRQkAPIAzTDibEylGmVEAnFhQDm9KJIBGAKwj9gAOjBrBwa+AhmbAZWAbtZ-oRR5CxambgoLPwQ2AAcADRQALQAjH42ADKCAO4QagDC+HAh1HxCImJsyGhk8MXoWN7MSlTUZAqs7JxouhIQMlW+mBhYAOTNKL1QAGTD4naCsg3dfYJGJsBDo4w+0D1YA3nColCOACoASjAIAOJyvUlqEAC2UCxgcEjXAPy9WwVQCACqCQlymwJtmJvgBZABCAFEDnIAEwAdneOzBkkkCQhAEEEHJpIRsoixMjURiEAB9Q5fCFyFzEfFQQlozEk477THpSkbCDJOmCQQoCCUbA4lDZXKAkS8+woQRabAAA32R1OssiRS42AVxxO1FyUAA9LqoELsmK4BKzFKZbLvr9lXdEGrrQltdw9QbqRATWaLXLQZCDrbVWhsL6oc7XYbcR78qa+ebpXL6cSA-ag4nMWH9RHhVHtl747K06TyRDk+VsIWyQcKRmDUac+LY96CyiGaTmXtWSWVSmvBX252a1njUA [is-number]: https://www.typescriptlang.org/play?target=7&jsx=0#code/C4TwDgpgBAkgzgOQK4FsBGEBOUC8UAUAbgIYA2SEAXFMQHYgCUuAfFCedAJZxS2oaYA3ACgAxgHtacYFFCQA8gDNcBdhWp1G1aZk60A5iyjy0AKwijgAOjCZxwe+AhWHAZWC6DV0WVJEyFAxWcKScohD4ABwANFAAtACMQQ4AMuIA7lgAwsRwEQwiElIy3MjoWNTwZQIq-hwa9AzUalw8fOXYOMzCULJOSnWBuDh4AOTtAqNQAGTTPQTzvdwAYnqcwBEtTCN4HhQzc729+ItHLVB60nTh4srVWMN4imR5B6e955fA1xC3xmYWGQ7KDPUivWbvPqQP7nYHjfhYUanBinAA+qNOJyORzkv2UsJGUFG4gBlimEOxHwCXGKPz+906hL20AplM+tNoN2UJnMlkeskwFGR8wKYkk0igACEYABxGAIAAqKgAnAAGVUAdgSyuVACYAKwAFg1htVOoStEK4pkkvk8hSAFEAIIIFSgvJW4pQBAAVQAspKHQAlFS6jWeiW+gPBgD68tcCpdWQdKloEHS3oRmHw+tFRQlCaD8plKlGaUwEBQFzAcFQAH5RhHxKRnKRxPp8AADaVyxWd2KlLP4HvyhUMApQAD0k5BLwgYqkzdb7a7tvtzoQ-YuiCHa8dLvHginM-d8-zS6sbY7najgaDW8HHXwt+Dh+PAqF55bl5XN-9d7jBAEyTB0Hx3J8XyDQDgIQZM32nD8z3FC8ry7QtizAhl8HQhAZXgk852EYQgA [is-object]: https://www.typescriptlang.org/play?noUncheckedIndexedAccess=true&target=7&jsx=0#code/JYOwLgpgTgZghgYwgAgPICMBWEFgJLjTxLIDeyAHgFzIgCuAtutANzIC+AUKJLIiqjAALaBmy4yyAOY16TVh05gAngAcUAMTogEyALzIAFADpTquFDgMacEMoCU+gHzJbylkrUo8AZzE4wfWQAHjEnQwA3OAAbOggbOwAaZABrCGUAfhofMChQKUc9FyjYlGAfNCwPFXVkXwA5AHswerpo6KDImLiabRSQRoB3EEKXdEbG6IhbDwRGkBzkcqaWtuiaBubW9s6SnuQ+geH7GnHJ6ZBnTmRkGohUGC7SxwBCPQMAcnp2j+QAMj+12QexQbwM32is3mizuD123XirjsJ2QOTyICkzkq4jAxlUUGazS8xjAjQAyrl8sYEDFok84vZjD5osAkIYABzJAC0AEZGaSADJDaAAYTgPgghnsUIWgXKFPRmIM9MRbhRIKWFTR+Sxd0aMGBCP072QH21GI+MsW5X8uA2fiwASCoSw4RBCWUyTSmWylIx6qN5WxVxusMeIMKJo+jUduF+AKBeoNGvenxjOPjgJuGtAOVsSH12KdqduUDiQJuGU1Cvyhm9kYMuXLNxbyCr3qWlxTJqbKABRg14uxjKE4tQwwACgT1FAVHX0g3S82WzRe0CaPBohKPEDOAhouKKiLoU3cI0oCKDz4KuQKEEAKxsLhzWXIEWoepkgAqACUAKoil+qA-gA+iKAoAIJkmSQQgBAgxvieZZnheV4+FKVqBAAUmSH4gagABCWEAKKATQtr4IQfAkAYt40AAzIoL6LBof71CKNBaDonTULQjDMFAKJuFiFCYcgBGoKgArERB9RBL2O7MecxjRI0UiGAABsesrIaSqGHhpyQ2rGYDBNpaJ0Chl6HuE76fr+AFAaB4FQWS9jSsgAD0nlLhAe7QspqnqRpOF4YRJGAYZmoUaEwiiCZ4ShfU+FEaRX7uWw3m+f5CyBWpmmsexUXGTiwRcQg4SFSKGVeT5m4SjlPh5cFdnfv+gHAWBkHQQA2hQAC6xUOqV5mnnp1nXrZH5tY5nUudByQfBQHw1Vla5KVMKn5SFuHJeFaU9cog1GcNASxSIUAUYlu0pRFX6LcoK0eVl9V+RtEBbcFVV9cd0UmWV2gVYYVWLctq11TEDXvZ9mkSVJMn1ENMVuOEcPSbJ4PIK9nBAA [is-primitive]: https://www.typescriptlang.org/play?target=7&jsx=0#code/C4TwDgpgBACgTgSwLYOAgbhAzlAvFAcgCMEBzBAO2AKgB9CiB7RgGwgEMKb6CKBXJEQhxuhLCEGtRBLMEQVS0vhQAmEAGaUIKggG4AUPtCQoASSwAhZm054oACnTsWfCAC4onEAEo8APignF2gEHCZWDgoDY2hzADkBITg7R2dXDy9fXACg1yhQqH5BYWjwWKx4ZFQMaHwAHgAVMr9U4IyKEAAaKBiPSpQ0TCwsnLSQnCbIUpNzAGU5SlIU3PdPDpHAsfycWXlSafLZiSYWZbH2n39N4O2ocUkWA7MsAFVVDS0VM7a1y+zrvIFZRqTQUbQGfQAY0YFFk2wsZFMVG+6V+3g8K1uJHIyP+MUY6gBtVw+GIZEo1AM0NhwHh1kiHnMVgitnwrVRmQxWwK4RsFCu7JCNM4kIgBKgzL5UAAZNKiflhRRReKAPJEABWEEhwF8tHo9kFeBJPTgeT18pJ+HUziwEF8sp6ZXFmMtDHpnAI3ipMLhoQSxTgjKw-qSKNWnPlBSKobxTsJLuNvESwhoAH5tgAxSioCCC3xcm6UWQisWEkPCGVyzFF4Al1UarXAb007bzPZBtuLMMXdGRnYLBQC-HxraugiMBvamgO6uK5WEtWa7WVyNz0tQTsKXX0YcWxO7RZ6KE+2mhI4PDvHVjdtEFwE7K+nWOQZ2j-ePo-U32vd6g7RBt4QU+G8I2rHBgQ+MEvn+BN8Agv8vgdXdYMIeDPiPY8W1CfpqkwIMcMGWooEaZpBQubpelgRABhqYY73GKBJlqAIAG99CgfJCXsM8B1IewYm8Xw2I4jisAAd1QSEAAsHAEqBhJEjjIXYW0GHJKgCA8OAIGAPg4H5UIEVIJFgDzAxFKUlToGId0uC0nS9IMyxbLM9iLOU1SkwDTSoG03T9O2cs4FciyoA86yDwUHy-Mc1teJC9yrLED97P8pzzxOBLFPC1Df3Q1LYtCQDIO0LKoAAXzcyqOJigLrRYW0DHKiEv1pCwVRVAAZABRABBOI7HqxrMLhCxTAAcVMOIGjsABOAAGeaAHYAEZZtmgAmABWAAWJadvm9aVqiEbaTiF4AFkLG6gAlOwVo2pbmzhWYGhuqbxrsAgLpAQpk2SUJPxPKAXjiAARbqMym7qwbsNCoOe2lZgATSurq7Ay1h7AIeHtE9Z6IgAOhYRg+IAAzGybprJ7psOo3CIDqbEKRaSmpoaboyRxahBN0KAAHp+ZNVwRqJknyfarq+riGntgImo6ki0hWY6nr+s53lIk9L0BaFuQRa-MXSfsMnzqu27ZbpqpCLqaNhBaM3rpuzm7ZEXndeFiBRbYYnjbJ173ricbLYqembaVloA4+zmle1vnBc972IF98mUbRzqQ-lzBFcfSPUfazqY4-d2E-1r3DZ98WTdBiGobiGHM7DhXcZUFoa8h6Gwc5lu449svDAr5Oq9Ny6ncb62FeZqgHdH26NfUnmdYToby59I3ycdi3adDifs4j+xN+dsReN75ebVX2F15NqOg-Hmjs81zhI7e6O3RZLgS6Flek5T6+X9v7eWdGau2foHcaLt-qny-uffQQA From 64530aba9d9f95b0e23a212b91a992c56ea38f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 21 Apr 2021 00:10:05 +0200 Subject: [PATCH 035/201] docs(README.md): update. --- README.md | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index cd476953..463c91d3 100644 --- a/README.md +++ b/README.md @@ -254,7 +254,7 @@ const isArray: IsArray = (value: any): value is Array => ``` | Parameter | Type | Description | -|-----------| :---: |-------------| +| :-------- | :---: | :---------- | | value | `any` | Any `value` to check. | The **return value** is a `boolean` indicating whether or not the `value` is an `Array`. @@ -283,7 +283,7 @@ const isBigInt: IsBigInt = (value: any): value is bigint => ``` | Parameter | Type | Description | -|-----------| :---: |-------------| +| :-------- | :---: | :---------- | | value | `any` | Any `value` to check. | The **return value** is a `boolean` indicating whether or not the `value` is a `bigint`. @@ -312,18 +312,18 @@ const isBoolean: IsBoolean = (value: any): value is boolean => ``` | Parameter | Type | Description | -|-----------| :---: |-------------| +| :---------| :---: | :---------- | | value | `any` | Any `value` to check. | The **return value** is a `boolean` indicating whether or not the `value` is a `boolean`. ```typescript // Example usage -const BIGINT = 9007199254740991n; -const NUMBER = 27; +const BOOLEAN = false; +const BOOLEAN_INSTANCE = new Boolean(false); -isBigInt(NUMBER); // false -isBigInt(BIGINT); // true +isBoolean(BOOLEAN); // true +isBoolean(BOOLEAN_INSTANCE); // true ``` [Example usage on playground][is-boolean] | [How to detect `boolean` type][detect-boolean] @@ -332,7 +332,7 @@ isBigInt(BIGINT); // true ### isDefined -Use `isDefined()` or `is.defined()` to check if an **unknown** `value` is NOT an `'undefined'` type and is NOT equal to `undefined`. +Use `isDefined()` or `is.defined()` to check if an **unknown** `value` is NOT an `undefined` type and is NOT equal to `undefined`. ```typescript const isDefined: IsDefined = (value: unknown): boolean => @@ -342,7 +342,7 @@ const isDefined: IsDefined = (value: unknown): boolean => ``` | Parameter | Type | Description | -|-----------| :-------: |-------------| +| :-------- | :-------: | :---------- | | value | `unknown` | An unknown `value` to check. | The **return value** is a `boolean` indicating whether or not the `value` is defined. @@ -371,7 +371,7 @@ const isFunction: IsFunction = (value: any): value is Func => ``` | Parameter | Type | Description | -|-----------| :---: |-------------| +| :-------- | :---: | :---------- | | value | `any` | Any `value` to check. | The **return value** is a `boolean` indicating whether or not the `value` is a `function`. @@ -404,7 +404,7 @@ const isInstance: IsInstance = (value: any, instance: Constructor): va ``` | Parameter | Type | Description | -|-----------| :----------------: |-------------| +| :-------- | :----------------: | :---------- | | value | `any` | Any `value` to compare with the `instance`. | | instance | `Constructor` | The name of the generic `Obj` type to create an `instance` to compare with the `value`. | @@ -436,7 +436,7 @@ const isKey: IsKey = (value: any): value is Key => isString(value) || isNumber(v ``` | Parameter | Type | Description | -|-----------| :---: |-------------| +| :-------- | :---: |:----------- | | value | `any` | Any `value` to check. | The **return value** is a `boolean` indicating whether or not the `value` is a `Key` type. @@ -455,7 +455,7 @@ const isNull: IsNull = (value: any): value is null => ``` | Parameter | Type | Description | -|-----------| :---: |-------------| +| :-------- | :---: |------------ | | value | `any` | Any `value` to check. | The **return value** is a `boolean` indicating whether or not the `value` is `null`. @@ -485,7 +485,7 @@ const isNumber: IsNumber = (value: any): value is number => ``` | Parameter | Type | Description | -|-----------| :---: |-------------| +| :-------- | :---: | :---------- | | value | `any` | Any ``value`` to check. | The return value is a `boolean` indicating whether or not the `value` is a `number`. @@ -510,7 +510,7 @@ const isObject: IsObject = (value: any, key?: string): value is Obj => ``` | Parameter | Type | Description | -|-----------| :------: |-------------| +| :-------- | :------: | :---------- | | value | `any` | Any `value` to check if it's a generic `'object'` type and `Object` instance. | | key? | `string` | Property name to find in argument `value`. | @@ -537,8 +537,8 @@ const isPrimitive: IsPrimitive = (value: any, type: Primitives): value is }; ``` -| Parameter | Type | Description | -|-----------| :----------: |--------------| +| Parameter | Type | Description | +| :-------- | :----------: | :---------- | | value | `any` | Any `value` to check if it's a generic `Type` type from on of the `type`. | | type | `Primitives` | One of the `Primitives` `'boolean'`, `'bigint'`, `'number'`, `'string'`, `'symbol'`, `'undefined'` type to check `value`. | @@ -567,7 +567,7 @@ const isString: IsString = (value: any): value is string => ``` | Parameter | Type | Description | -|-----------| :---: |-------------| +| :-------- | :---: | :---------- | | value | `any` | Any value to check if it's a `'string'` type, not an instance of `Object` and `String` or `'object'` type and instance of `String` and `Object`. | [Example usage][is-string] | [How to detect `'string'` type][detect-string] @@ -585,7 +585,7 @@ const isSymbol: IsSymbol = (value: any): value is symbol => ``` | Parameter | Type | Description | -|-----------| :---: |-------------| +| :-------- | :---: | :---------- | | value | `any` | Any `value` to check if it's a `'symbol'` type. | [Example usage][is-symbol] | [How to detect `'symbol'` type][detect-symbol] @@ -615,7 +615,7 @@ const isType: IsType = (value: any, type: Types): value is Type => { ``` | Parameter | Type | Description | -|-----------| :-----------: |-------------| +| :-------- | :-----------: | :---------- | | value | `any` | Any value to check it is a generic `Type` type from one of the `type`. | | type | `Types` | Generic constructor `Type`, `'function'`, `'object'` or one of the `Primitives` `'bigint'`, `'boolean'`, `'number'`, `'symbol'`, `'string'`, `'undefined'` to check `value` type. | @@ -635,7 +635,7 @@ const isUndefined: IsUndefined = (value: any): value is undefined => ``` | Parameter | Type | Description | -|-----------| :---: |-------------| +| :-------- | :---: | :---------- | | value | `any` | Any `value` to check if it's an `'undefined'` type, and equal to `undefined`. | [Example usage][is-undefined] | [How to detect `'undefined'` type][detect-undefined] @@ -656,7 +656,7 @@ const isNotBoolean: IsNotBoolean = (value: unknown): boolean => ``` | Parameter | Type | Description | -|-----------| :-------: |-------------| +| :-------- | :-------: | :---------- | | value | `unknown` | An unknown `value` to check if it's NOT a `'boolean'` type, NOT equal to `true` or `false` and NOT an instance of `Boolean`. | ---- @@ -676,7 +676,6 @@ const isNotDefined: IsNotDefined = (value: unknown): boolean => |-----------| :-------: |-------------| | value | `unknown` | An unknown `value` to check if it's an `'undefined'` type and is equal to `undefined`. | - ---- ### isNotFunction From 676820e973b50040f0d5f1774c7c90c0889e6948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 21 Apr 2021 00:20:16 +0200 Subject: [PATCH 036/201] chore(isNumber): update. - reoder imports. - use IsNumberObject to check. - use isNumberType to check. - update jsdoc. --- packages/type/src/is/lib/is-number.func.ts | 30 ++++++++-------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/packages/type/src/is/lib/is-number.func.ts b/packages/type/src/is/lib/is-number.func.ts index 89cacea3..0442ff93 100644 --- a/packages/type/src/is/lib/is-number.func.ts +++ b/packages/type/src/is/lib/is-number.func.ts @@ -1,25 +1,15 @@ -import { IsNumber } from '../type/is-number.type'; +// Function. +import { isNumberObject } from './is-number-object.func'; +import { isNumberType } from './is-number-type.func'; import { typeOf } from '../../lib/type-of.func'; +// Type. +import { IsNumber } from '../type/is-number.type'; /** - * Checks if any `value` is a `'number'` type not instance of `Number` and `Object` or `'object'` type instance of `Number` and `Object`. - * Use the `guardNumber()` function to type-guard `number` also. - * @param value Any value to check if it's a `'number'` type not instance of `Number` and `Object` - * or `'object'` type instance of `Number` and `Object`. - * @returns boolean + * Checks if any `value` is a `number` type not an instance of `Number` and `Object` or `object` type instance of `Number` and `Object`. + * @param value Any value to check. + * @returns A `boolean` indicating whether or not the `value` is a `number`. */ export const isNumber: IsNumber = (value: any): value is number => typeOf(value) === 'number' && - ( - isFinite(value) === true && - ( - value instanceof Number === false && - value instanceof Object === false && - typeof value === 'number' - ) - || - ( - typeof value === 'object' && - value instanceof Number === true && - value instanceof Object === true - ) - ); + isFinite(value) === true && + (isNumberObject(value) || isNumberType(value)); From 057cf453aa2326d64800c1fd00cc629ff9353f6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 21 Apr 2021 00:37:04 +0200 Subject: [PATCH 037/201] refactor(isObject): update. - reorder imports. - parameter type `key` from `string` to `Key`. - use `isKey` instead of `isString` to check. --- packages/type/src/is/lib/is-object.func.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/type/src/is/lib/is-object.func.ts b/packages/type/src/is/lib/is-object.func.ts index 3cedd1a4..00f7d441 100644 --- a/packages/type/src/is/lib/is-object.func.ts +++ b/packages/type/src/is/lib/is-object.func.ts @@ -1,16 +1,18 @@ -import { isString } from './is-string.func'; -import { IsObject } from '../type/is-object.type'; +// Function. +import { isKey } from './is-key.func'; import { typeOf } from '../../lib/type-of.func'; +// Type. +import { IsObject } from '../type/is-object.type'; +import { Key } from '../../type/key.type'; /** - * Checks if any `value` is a generic `Obj` `'object'` type and `Object` instance with the possibility of containing `key`. - * Use the `guardObject()` function to type-guard generic object type also. - * @param value Any `value` to check if it's a generic `'object'` type and `Object` instance. - * @param key Name to find in argument `value`. - * @returns boolean + * Checks if any `value` is a generic `Obj` `object` type and `Object` instance with the possibility of containing `key`. + * @param value Any `value` to check. + * @param key Property name to find in `value`. + * @returns A `boolean` indicating whether or not the `value` is an `object`. */ -export const isObject: IsObject = (value: any, key?: string): value is Obj => +export const isObject: IsObject = (value: any, key?: Key): value is Obj => (typeOf(value) === 'object' && typeof value === 'object' && value instanceof Object === true) - ? isString(key) + ? isKey(key) ? key in value : true : false; From d4d65c2f03170fab8da6f7299199abfbd47c4107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 21 Apr 2021 00:46:49 +0200 Subject: [PATCH 038/201] docs(isString): update. --- packages/type/src/is/lib/is-string.func.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/type/src/is/lib/is-string.func.ts b/packages/type/src/is/lib/is-string.func.ts index 549b9426..2a7689d7 100644 --- a/packages/type/src/is/lib/is-string.func.ts +++ b/packages/type/src/is/lib/is-string.func.ts @@ -5,15 +5,11 @@ import { typeOf } from '../../lib/type-of.func'; // Type. import { IsString } from '../type/is-string.type'; import { ResultCallback } from '../../type/result-callback.type'; - /** - * Checks if any `value` is a `'string'` type, not instance of `Object` and `String` - * or `'object'` type and instance of `String` and `Object`. - * Use the`guardString()` function to type-guard `string` also. - * @param value Any value to check if it's a `'string'` type, not an instance of `Object` and `String` - * or `'object'` type and instance of `String` and `Object`. - * @param callback ResultCallback function to handle result before return. - * @returns boolean. + * Checks if any `value` is a `string` type, not instance of `Object` and `String` or `object` type and instance of `String` and `Object`. + * @param value Any `value` to check. + * @param callback `ResultCallback` function to handle result before return. + * @returns A `boolean` indicating whether or not the `value` is a `string`. */ export const isString: IsString = (value: any, callback: ResultCallback = errorCallback): value is string => callback(typeOf(value) === 'string' && (isStringObject(value) || isStringType(value))); From 2a49333b0eae8511f8abff80357cf29d484f90d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 21 Apr 2021 00:54:28 +0200 Subject: [PATCH 039/201] docs(isSymbol): update. --- packages/type/src/is/lib/is-symbol.func.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/is/lib/is-symbol.func.ts b/packages/type/src/is/lib/is-symbol.func.ts index 9806b106..0503cc8c 100644 --- a/packages/type/src/is/lib/is-symbol.func.ts +++ b/packages/type/src/is/lib/is-symbol.func.ts @@ -3,7 +3,7 @@ import { typeOf } from '../../lib/type-of.func'; // Type. import { IsSymbol } from '../type/is-symbol.type'; /** - * Checks if any `value` is a `'symbol'` type. + * Checks if any `value` is a `symbol` type. * @param value Any `value` to check. * @returns A `boolean` indicating whether or not the `value` is a `symbol`. */ From 09afc7b20d3ee03dee1d65dc8cf998e6ec708aec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 21 Apr 2021 01:09:52 +0200 Subject: [PATCH 040/201] docs(README.md): update. --- README.md | 132 ++++++++++++++++++++++++++---------------------------- 1 file changed, 64 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index 463c91d3..c13cd151 100644 --- a/README.md +++ b/README.md @@ -244,6 +244,7 @@ const areString = (...args: any): boolean => check('string', ...args); ### isArray Use `isArray()` or `is.array()` to check if **any** `value` is an `Array`, `Array` instance and `object` type. +The **return value** is a `boolean` indicating whether or not the `value` is an `Array`. ```typescript const isArray: IsArray = (value: any): value is Array => @@ -257,8 +258,6 @@ const isArray: IsArray = (value: any): value is Array => | :-------- | :---: | :---------- | | value | `any` | Any `value` to check. | -The **return value** is a `boolean` indicating whether or not the `value` is an `Array`. - ```typescript // Example usage const ARRAY_NUMBER = [1, 2, 3]; @@ -275,6 +274,7 @@ isArray(ARRAY_STRING); // true ### isBigInt Use `isBigInt()` or `is.bigInt()` to check if **any** `value` is a `bigint` type. +The **return value** is a `boolean` indicating whether or not the `value` is a `bigint`. ```typescript const isBigInt: IsBigInt = (value: any): value is bigint => @@ -286,8 +286,6 @@ const isBigInt: IsBigInt = (value: any): value is bigint => | :-------- | :---: | :---------- | | value | `any` | Any `value` to check. | -The **return value** is a `boolean` indicating whether or not the `value` is a `bigint`. - ```typescript // Example usage const BIGINT = 9007199254740991n; @@ -304,6 +302,7 @@ isBigInt(BIGINT); // true ### isBoolean Use `isBoolean()` or `is.boolean()` to check if **any** `value` is a `boolean` type not instance of `Boolean` and `Object` or `object` type instance of `Boolean` and `Object`. +The **return value** is a `boolean` indicating whether or not the `value` is a `boolean`. ```typescript const isBoolean: IsBoolean = (value: any): value is boolean => @@ -315,8 +314,6 @@ const isBoolean: IsBoolean = (value: any): value is boolean => | :---------| :---: | :---------- | | value | `any` | Any `value` to check. | -The **return value** is a `boolean` indicating whether or not the `value` is a `boolean`. - ```typescript // Example usage const BOOLEAN = false; @@ -333,6 +330,7 @@ isBoolean(BOOLEAN_INSTANCE); // true ### isDefined Use `isDefined()` or `is.defined()` to check if an **unknown** `value` is NOT an `undefined` type and is NOT equal to `undefined`. +The **return value** is a `boolean` indicating whether or not the `value` is defined. ```typescript const isDefined: IsDefined = (value: unknown): boolean => @@ -345,8 +343,6 @@ const isDefined: IsDefined = (value: unknown): boolean => | :-------- | :-------: | :---------- | | value | `unknown` | An unknown `value` to check. | -The **return value** is a `boolean` indicating whether or not the `value` is defined. - ```typescript // Example usage const UNDEFINED = undefined; @@ -361,6 +357,7 @@ isDefined(defined); // false ### isFunction Use `isFunction()` or `is.function()` to check if **any** `value` is a `function` type, an instance `Function` and `Object`. +The **return value** is a `boolean` indicating whether or not the `value` is a `function`. ```typescript const isFunction: IsFunction = (value: any): value is Func => @@ -374,8 +371,6 @@ const isFunction: IsFunction = (value: any): value is Func => | :-------- | :---: | :---------- | | value | `any` | Any `value` to check. | -The **return value** is a `boolean` indicating whether or not the `value` is a `function`. - ```typescript // Example usage class Class { x = 5; } @@ -393,6 +388,7 @@ isFunction(() => 5); // true ### isInstance Use `isInstance()` or `is.instance()` to check if **any** value is an `object` of a generic `Obj` type equal to an `instance` of `Constructor` type. +The **return value** is a `boolean` indicating whether or not the `value` is an `instance`. ```typescript const isInstance: IsInstance = (value: any, instance: Constructor): value is Obj => @@ -408,8 +404,6 @@ const isInstance: IsInstance = (value: any, instance: Constructor): va | value | `any` | Any `value` to compare with the `instance`. | | instance | `Constructor` | The name of the generic `Obj` type to create an `instance` to compare with the `value`. | -The **return value** is a `boolean` indicating whether or not the `value` is an `instance`. - ```typescript // Example usage class Some { x = 127; } @@ -430,6 +424,7 @@ isInstance(TWO, TWO); // true and type error ### isKey Use `isKey()` or `is.key()` to determine if **any** `value` is one of the `string`, `number`, or `symbol`. +The **return value** is a `boolean` indicating whether or not the `value` is a `Key` type. ```typescript const isKey: IsKey = (value: any): value is Key => isString(value) || isNumber(value) || isSymbol(value); @@ -439,13 +434,12 @@ const isKey: IsKey = (value: any): value is Key => isString(value) || isNumber(v | :-------- | :---: |:----------- | | value | `any` | Any `value` to check. | -The **return value** is a `boolean` indicating whether or not the `value` is a `Key` type. - ---- ### isNull Use `isNull()` or `is.null()` to check if **any** `value` is an `object` type and equal to `null`. +The **return value** is a `boolean` indicating whether or not the `value` is `null`. ```typescript const isNull: IsNull = (value: any): value is null => @@ -458,8 +452,6 @@ const isNull: IsNull = (value: any): value is null => | :-------- | :---: |------------ | | value | `any` | Any `value` to check. | -The **return value** is a `boolean` indicating whether or not the `value` is `null`. - ```typescript // Example usage const NULL = null; @@ -476,6 +468,7 @@ isNull(NUMBER); // false ### isNumber Use `isNumber()` or `is.number()` to check if **any** `value` is a '`number`' type not an instance of `Number` and `Object` or `'object'` type instance of `Number` and `Object`. +The **return value** is a `boolean` indicating whether or not the `value` is a `number`. ```typescript const isNumber: IsNumber = (value: any): value is number => @@ -488,33 +481,30 @@ const isNumber: IsNumber = (value: any): value is number => | :-------- | :---: | :---------- | | value | `any` | Any ``value`` to check. | -The return value is a `boolean` indicating whether or not the `value` is a `number`. - [Example usage on playground][is-number] | [How to detect `number` type][detect-number] ---- ### isObject -Use `isObject()` or `is.object()` to check if **any** `value` is a generic `Obj` `'object'` type and `Object` instance with the possibility of containing `key`. The return value is a `boolean` value. +Use `isObject()` or `is.object()` to check if **any** `value` is a generic `Obj` `object` type and `Object` instance with the possibility of containing `key`. +The **return value** is a `boolean` indicating whether or not the `value` is an `object`. ```typescript -const isObject: IsObject = (value: any, key?: string): value is Obj => - typeOf(value) === 'object' && - typeof value === 'object' && - value instanceof Object === true - ? isString(key) === true - ? value.hasOwnProperty(key) === true +const isObject: IsObject = (value: any, key?: Key): value is Obj => + (typeOf(value) === 'object' && typeof value === 'object' && value instanceof Object === true) + ? isKey(key) + ? key in value : true : false; ``` | Parameter | Type | Description | | :-------- | :------: | :---------- | -| value | `any` | Any `value` to check if it's a generic `'object'` type and `Object` instance. | -| key? | `string` | Property name to find in argument `value`. | +| value | `any` | Any `value` to check. | +| key? | `Key` | Property name to find in `value`. | -[Example usage][is-object] | [How to detect `'object'` type][detect-object] +[Example usage on playground][is-object] | [How to detect `object` type][detect-object] ---- @@ -540,7 +530,7 @@ const isPrimitive: IsPrimitive = (value: any, type: Primitives): value is | Parameter | Type | Description | | :-------- | :----------: | :---------- | | value | `any` | Any `value` to check if it's a generic `Type` type from on of the `type`. | -| type | `Primitives` | One of the `Primitives` `'boolean'`, `'bigint'`, `'number'`, `'string'`, `'symbol'`, `'undefined'` type to check `value`. | +| type | `Primitives` | One of the `Primitives` `'boolean'`, `'bigint'`, `'number'`, `'string'`, `'symbol'`, `'undefined'` type to check `value`. | [Example usage][is-primitive] @@ -548,47 +538,39 @@ const isPrimitive: IsPrimitive = (value: any, type: Primitives): value is ### isString -Use `isString()` or `is.string()` to check if **any** `value` is a `'string'` type, not instance of `Object` and `String` or `'object'` type and instance of `String` and `Object`. The return value is a `boolean` value. +Use `isString()` or `is.string()` to check if **any** `value` is a `string` type, not instance of `Object` and `String` or `object` type and instance of `String` and `Object`. +The **return value** is a `boolean` indicating whether or not the `value` is a `string`. ```typescript -const isString: IsString = (value: any): value is string => - typeOf(value) === 'string' && - ( - typeof value === 'object' && - value instanceof Object === true && - value instanceof String === true - ) - || - ( - value instanceof Object === false && - value instanceof String === false && - typeof value === 'string' - ); +const isString: IsString = (value: any, callback: ResultCallback = errorCallback): value is string => + callback(typeOf(value) === 'string' && (isStringObject(value) || isStringType(value))); ``` -| Parameter | Type | Description | -| :-------- | :---: | :---------- | -| value | `any` | Any value to check if it's a `'string'` type, not an instance of `Object` and `String` or `'object'` type and instance of `String` and `Object`. | +| Parameter | Type | Description | +| :-------- | :--------------: | :---------- | +| value | `any` | Any value to check. | +| callback | `ResultCallback` | `ResultCallback` function to handle result before return eg. to throw an `Error`. | -[Example usage][is-string] | [How to detect `'string'` type][detect-string] +[Example usage on playground][is-string] | [How to detect `string` type][detect-string] ---- ### isSymbol -Use `isSymbol()` or `is.symbol()` to check if **any** `value` is a `'symbol'` type. The return value is a `boolean` value. +Use `isSymbol()` or `is.symbol()` to check if **any** `value` is a `symbol` type. +The **return value** is a `boolean` indicating whether or not the `value` is a `symbol`. ```typescript const isSymbol: IsSymbol = (value: any): value is symbol => typeOf(value) === 'symbol' && - typeof value === 'symbol'; + typeof value === 'symbol';s ``` | Parameter | Type | Description | | :-------- | :---: | :---------- | -| value | `any` | Any `value` to check if it's a `'symbol'` type. | +| value | `any` | Any `value` to check if it's a `symbol` type. | -[Example usage][is-symbol] | [How to detect `'symbol'` type][detect-symbol] +[Example usage on playground][is-symbol] | [How to detect `symbol` type][detect-symbol] ---- @@ -619,13 +601,14 @@ const isType: IsType = (value: any, type: Types): value is Type => { | value | `any` | Any value to check it is a generic `Type` type from one of the `type`. | | type | `Types` | Generic constructor `Type`, `'function'`, `'object'` or one of the `Primitives` `'bigint'`, `'boolean'`, `'number'`, `'symbol'`, `'string'`, `'undefined'` to check `value` type. | -[Example usage][is-type] +[Example usage on playground][is-type] ---- ### isUndefined -Use `isUndefined()` or `is.undefined()` to check if **any** `value` is an `'undefined'` type and equal to `undefined`. The return value is a `boolean` value. +Use `isUndefined()` or `is.undefined()` to check if **any** `value` is an `undefined` type and equal to `undefined`. +The **return value** is a `boolean` indicating whether or not the `value` is undefined. ```typescript const isUndefined: IsUndefined = (value: any): value is undefined => @@ -636,15 +619,16 @@ const isUndefined: IsUndefined = (value: any): value is undefined => | Parameter | Type | Description | | :-------- | :---: | :---------- | -| value | `any` | Any `value` to check if it's an `'undefined'` type, and equal to `undefined`. | +| value | `any` | Any `value` to check. | -[Example usage][is-undefined] | [How to detect `'undefined'` type][detect-undefined] +[Example usage on playground][is-undefined] | [How to detect `'undefined'` type][detect-undefined] ---- ### isNotBoolean -Use `isNotBoolean()` or `is.not.boolean()` to check if an **unknown** `value` is NOT a `'boolean'` type, NOT equal to `true` or `false` and NOT an instance of a `Boolean`. The return value is a `boolean` value. +Use `isNotBoolean()` or `is.not.boolean()` to check if an **unknown** `value` is NOT a `'boolean'` type, NOT equal to `true` or `false` and NOT an instance of a `Boolean`. +The return value is a `boolean` value. ```typescript const isNotBoolean: IsNotBoolean = (value: unknown): boolean => @@ -680,7 +664,7 @@ const isNotDefined: IsNotDefined = (value: unknown): boolean => ### isNotFunction -Use `isNotFunction()` or `is.not.function()` to check if an **unknown** `value` is NOT a `'function'` type and NOT an instance of `Function`. The return value is a `boolean` value. +Use `isNotFunction()` or `is.not.function()` to check if an **unknown** `value` is NOT a `function` type and NOT an instance of `Function`. The return value is a `boolean` value. ```typescript const isNotFunction: IsNotFunction = (value: unknown): boolean => @@ -691,13 +675,13 @@ const isNotFunction: IsNotFunction = (value: unknown): boolean => | Parameter | Type | Description | |-----------| :-------: |-------------| -| value | `unknown` | An unknown `value` to check if it's NOT a `'function'` type and NOT an instance of `Function`. | +| value | `unknown` | An unknown `value` to check. | ---- ### isNotNull -Use `isNotNull()` or `is.not.null()` to check if an **unknown** `value` is NOT a `'null'` type and NOT equal to `null`. The return value is a `boolean` value. +Use `isNotNull()` or `is.not.null()` to check if an **unknown** `value` is NOT a `null` type and NOT equal to `null`. The return value is a `boolean` value. ```typescript const isNotNull: IsNotNull = (value: unknown): boolean => @@ -707,13 +691,13 @@ const isNotNull: IsNotNull = (value: unknown): boolean => | Parameter | Type | Description | |-----------| :-------: |-------------| -| value | `unknown` | An unknown `value` to check if it's NOT a `'null'` type and NOT equal to `null`. | +| value | `unknown` | An unknown `value` to check. | ---- ### isNotNumber -Use `isNotNumber()` or `is.not.number()` to check if an **unknown** `value` is NOT a `'number'` type and NOT an instance of `Number`. The return value is a `boolean` value. +Use `isNotNumber()` or `is.not.number()` to check if an **unknown** `value` is NOT a `number` type and NOT an instance of `Number`. The return value is a `boolean` value. ```typescript const isNotNumber: IsNotNumber = (value: any): boolean => @@ -725,13 +709,13 @@ const isNotNumber: IsNotNumber = (value: any): boolean => | Parameter | Type | Description | |-----------| :-------: |-------------| -| value | `unknown` | An unknown value to check if it's NOT a `'number'` type and NOT an instance of `Number`. | +| value | `unknown` | An unknown `value` to check. | ---- ### isNotString -Use `isNotString()` or `is.not.string()` to check if an **unknown** `value` is NOT a `'string'` type and NOT an instance of `String`. The return value is a `boolean` value. +Use `isNotString()` or `is.not.string()` to check if an **unknown** `value` is NOT a `string` type and NOT an instance of `String`. The return value is a `boolean` value. ```typescript const isNotString: IsNotString = (value: unknown): boolean => @@ -742,13 +726,13 @@ const isNotString: IsNotString = (value: unknown): boolean => | Parameter | Type | Description | |-----------| :-------: |-------------| -| value | `unknown` | An unknown `value` to check if it's NOT a `'string'` type or NOT an `'object'` type and NOT an instance of `String`. | +| value | `unknown` | An unknown `value` to check. | ---- ### isNotUndefined -Use `isNotUndefined()` or `is.not.undefined()` to check if an **unknown** `value` is NOT an `'undefined'` type and NOT equal to `undefined`. The return value is a `boolean` value. +Use `isNotUndefined()` or `is.not.undefined()` to check if an **unknown** `value` is NOT an `undefined` type and NOT equal to `undefined`. The return value is a `boolean` value. ```typescript const isNotUndefined: IsNotUndefined = (value: unknown): boolean => @@ -759,7 +743,7 @@ const isNotUndefined: IsNotUndefined = (value: unknown): boolean => | Parameter | Type | Description | |-----------| :-------: |-------------| -| value | `unknown` | An Unknown `value` to check if it's NOT an `'undefined'` type and NOT equal to `undefined`. | +| value | `unknown` | An Unknown `value` to check. | ## Guards @@ -914,16 +898,28 @@ type CycleHook = 'ngAfterContentInit' | 'ngAfterContentChecked' | 'ngAfterViewIn type Func = (...param: any) => any; ``` +### Key + +```typescript +type Key = number | string | symbol; +``` + ### Primitive ```typescript -type Primitive = boolean | bigint | null | number | string | symbol | undefined; +type Primitive = bigint | boolean | null | number | string | symbol | undefined; ``` ### Primitives ```typescript -type Primitives = 'bigint' | 'boolean' | 'number' | 'symbol' | 'string' | 'undefined'; +type Primitives = 'bigint' | 'boolean' | 'number' | 'string' | 'symbol' | 'undefined'; +``` + +### ResultCallback + +```typescript +type ResultCallback = (result: boolean) => boolean; ``` ### Types From 77f250ac8eab700280d805176e533ceee76f0ad3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 21 Apr 2021 13:14:40 +0200 Subject: [PATCH 041/201] refactor(IsObject): parameter key change to `Key`. --- packages/type/src/is/type/is-object.type.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/type/src/is/type/is-object.type.ts b/packages/type/src/is/type/is-object.type.ts index d5f88798..7cc12901 100644 --- a/packages/type/src/is/type/is-object.type.ts +++ b/packages/type/src/is/type/is-object.type.ts @@ -1 +1,2 @@ -export type IsObject = (value: any, key?: string) => value is Obj; +import { Key } from '../../type/key.type'; +export type IsObject = (value: any, key?: Key) => value is Obj; From 90105d1b610c5e56383fe82d5136f60abd84690b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 21 Apr 2021 13:15:34 +0200 Subject: [PATCH 042/201] feat(isObjectKey): determines if any `object` has its own specified keys of the `Key` type. --- .../type/src/is/lib/is-object-key.func.ts | 21 +++++++++++++++++++ .../type/src/is/type/is-object-key.type.ts | 2 ++ 2 files changed, 23 insertions(+) create mode 100644 packages/type/src/is/lib/is-object-key.func.ts create mode 100644 packages/type/src/is/type/is-object-key.type.ts diff --git a/packages/type/src/is/lib/is-object-key.func.ts b/packages/type/src/is/lib/is-object-key.func.ts new file mode 100644 index 00000000..be9783ca --- /dev/null +++ b/packages/type/src/is/lib/is-object-key.func.ts @@ -0,0 +1,21 @@ +// Function. +import { isArray } from './is-array.func'; +import { isKey } from './is-key.func'; +import { isObject } from './is-object.func'; +// Type. +import { IsObjectKey } from '../type/is-object-key.type'; +import { Key } from '../../type/key.type'; +/** + * Determines if any `object` has its own specified keys of the `Key` type. + * @param object Any `object` to check if it contains a specified `key`. + * @param key `Key` type or an array of `Key` type to check. + * @returns A `boolean` indicating whether or not the `object` has its own specified keys of `Key` type. + */ +export const isObjectKey: IsObjectKey = (object: any, key: Key | Key[]): object is object => + isObject(object) ? + isArray(key) ? + key.every(k => isKey(k) ? ({}).hasOwnProperty.call(object, k) === true : false) + : isKey(key) ? + ({}).hasOwnProperty.call(object, key) + : false + : false; diff --git a/packages/type/src/is/type/is-object-key.type.ts b/packages/type/src/is/type/is-object-key.type.ts new file mode 100644 index 00000000..7b133268 --- /dev/null +++ b/packages/type/src/is/type/is-object-key.type.ts @@ -0,0 +1,2 @@ +import { Key } from '../../type/key.type'; +export type IsObjectKey = (object: any, key: Key | Key[]) => object is object; From b59783d8dbd0e95eb7cd7e5fbf747cedfaa40520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 21 Apr 2021 22:07:13 +0200 Subject: [PATCH 043/201] docs(README.md): update. --- README.md | 147 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 95 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index c13cd151..2caab274 100644 --- a/README.md +++ b/README.md @@ -227,7 +227,7 @@ const isNot: IsNot = { ### areString - Use `areString()` or `are.string()` to check if all of **any** arguments are a `'string'` type. The return value is a `boolean` value. + Use `areString()` or `are.string()` to check if all of **any** arguments are a `string` type. ```typescript const areString = (...args: any): boolean => check('string', ...args); @@ -235,7 +235,9 @@ const areString = (...args: any): boolean => check('string', ...args); | Parameter | Type | Description | |-----------| :---: |-------------| -| ...args | `any` | Any arguments to check they're all a `'string'` type. | +| ...args | `any` | Any arguments to check they're all a `string` type | + +The **return value** is a `boolean` value. [Example usage on playground][are-string] @@ -244,7 +246,6 @@ const areString = (...args: any): boolean => check('string', ...args); ### isArray Use `isArray()` or `is.array()` to check if **any** `value` is an `Array`, `Array` instance and `object` type. -The **return value** is a `boolean` indicating whether or not the `value` is an `Array`. ```typescript const isArray: IsArray = (value: any): value is Array => @@ -256,7 +257,9 @@ const isArray: IsArray = (value: any): value is Array => | Parameter | Type | Description | | :-------- | :---: | :---------- | -| value | `any` | Any `value` to check. | +| value | `any` | Any `value` to check | + +The **return value** is a `boolean` indicating whether or not the `value` is an `Array`. ```typescript // Example usage @@ -274,7 +277,6 @@ isArray(ARRAY_STRING); // true ### isBigInt Use `isBigInt()` or `is.bigInt()` to check if **any** `value` is a `bigint` type. -The **return value** is a `boolean` indicating whether or not the `value` is a `bigint`. ```typescript const isBigInt: IsBigInt = (value: any): value is bigint => @@ -284,7 +286,9 @@ const isBigInt: IsBigInt = (value: any): value is bigint => | Parameter | Type | Description | | :-------- | :---: | :---------- | -| value | `any` | Any `value` to check. | +| value | `any` | Any `value` to check | + +The **return value** is a `boolean` indicating whether or not the `value` is a `bigint`. ```typescript // Example usage @@ -302,7 +306,6 @@ isBigInt(BIGINT); // true ### isBoolean Use `isBoolean()` or `is.boolean()` to check if **any** `value` is a `boolean` type not instance of `Boolean` and `Object` or `object` type instance of `Boolean` and `Object`. -The **return value** is a `boolean` indicating whether or not the `value` is a `boolean`. ```typescript const isBoolean: IsBoolean = (value: any): value is boolean => @@ -312,7 +315,9 @@ const isBoolean: IsBoolean = (value: any): value is boolean => | Parameter | Type | Description | | :---------| :---: | :---------- | -| value | `any` | Any `value` to check. | +| value | `any` | Any `value` to check | + +The **return value** is a `boolean` indicating whether or not the `value` is a `boolean`. ```typescript // Example usage @@ -323,14 +328,13 @@ isBoolean(BOOLEAN); // true isBoolean(BOOLEAN_INSTANCE); // true ``` -[Example usage on playground][is-boolean] | [How to detect `boolean` type][detect-boolean] +[Example usage on playground][is-boolean] | [How to detect the `boolean` type][detect-boolean] ---- ### isDefined Use `isDefined()` or `is.defined()` to check if an **unknown** `value` is NOT an `undefined` type and is NOT equal to `undefined`. -The **return value** is a `boolean` indicating whether or not the `value` is defined. ```typescript const isDefined: IsDefined = (value: unknown): boolean => @@ -341,7 +345,9 @@ const isDefined: IsDefined = (value: unknown): boolean => | Parameter | Type | Description | | :-------- | :-------: | :---------- | -| value | `unknown` | An unknown `value` to check. | +| value | `unknown` | An unknown `value` to check | + +The **return value** is a `boolean` indicating whether or not the `value` is defined. ```typescript // Example usage @@ -357,7 +363,6 @@ isDefined(defined); // false ### isFunction Use `isFunction()` or `is.function()` to check if **any** `value` is a `function` type, an instance `Function` and `Object`. -The **return value** is a `boolean` indicating whether or not the `value` is a `function`. ```typescript const isFunction: IsFunction = (value: any): value is Func => @@ -369,7 +374,9 @@ const isFunction: IsFunction = (value: any): value is Func => | Parameter | Type | Description | | :-------- | :---: | :---------- | -| value | `any` | Any `value` to check. | +| value | `any` | Any `value` to check | + +The **return value** is a `boolean` indicating whether or not the `value` is a `function`. ```typescript // Example usage @@ -387,8 +394,7 @@ isFunction(() => 5); // true ### isInstance -Use `isInstance()` or `is.instance()` to check if **any** value is an `object` of a generic `Obj` type equal to an `instance` of `Constructor` type. -The **return value** is a `boolean` indicating whether or not the `value` is an `instance`. +Use `isInstance()` or `is.instance()` to check if **any** value is an `object` of a generic `Obj` type equal to an `instance` of [`Constructor`](#Constructor) type. ```typescript const isInstance: IsInstance = (value: any, instance: Constructor): value is Obj => @@ -399,10 +405,12 @@ const isInstance: IsInstance = (value: any, instance: Constructor): va : false; ``` -| Parameter | Type | Description | -| :-------- | :----------------: | :---------- | -| value | `any` | Any `value` to compare with the `instance`. | -| instance | `Constructor` | The name of the generic `Obj` type to create an `instance` to compare with the `value`. | +| Parameter | Type | Description | +| :-------- | :--------------------------------: | :---------- | +| value | `any` | Any `value` to compare with the `instance` | +| instance | [`Constructor`](#Constructor) | The name of the generic `Obj` type to create an `instance` to compare with the `value` | + +The **return value** is a `boolean` indicating whether or not the `value` is an `instance`. ```typescript // Example usage @@ -424,7 +432,6 @@ isInstance(TWO, TWO); // true and type error ### isKey Use `isKey()` or `is.key()` to determine if **any** `value` is one of the `string`, `number`, or `symbol`. -The **return value** is a `boolean` indicating whether or not the `value` is a `Key` type. ```typescript const isKey: IsKey = (value: any): value is Key => isString(value) || isNumber(value) || isSymbol(value); @@ -432,14 +439,15 @@ const isKey: IsKey = (value: any): value is Key => isString(value) || isNumber(v | Parameter | Type | Description | | :-------- | :---: |:----------- | -| value | `any` | Any `value` to check. | +| value | `any` | Any `value` to check | + +The **return value** is a `boolean` indicating whether or not the `value` is a [`Key`](#Key). ---- ### isNull Use `isNull()` or `is.null()` to check if **any** `value` is an `object` type and equal to `null`. -The **return value** is a `boolean` indicating whether or not the `value` is `null`. ```typescript const isNull: IsNull = (value: any): value is null => @@ -450,7 +458,9 @@ const isNull: IsNull = (value: any): value is null => | Parameter | Type | Description | | :-------- | :---: |------------ | -| value | `any` | Any `value` to check. | +| value | `any` | Any `value` to check | + +The **return value** is a `boolean` indicating whether or not the `value` is `null`. ```typescript // Example usage @@ -467,8 +477,7 @@ isNull(NUMBER); // false ### isNumber -Use `isNumber()` or `is.number()` to check if **any** `value` is a '`number`' type not an instance of `Number` and `Object` or `'object'` type instance of `Number` and `Object`. -The **return value** is a `boolean` indicating whether or not the `value` is a `number`. +Use `isNumber()` or `is.number()` to check if **any** `value` is a `number` type not an instance of `Number` and `Object` or `object` type instance of `Number` and `Object`. ```typescript const isNumber: IsNumber = (value: any): value is number => @@ -479,16 +488,17 @@ const isNumber: IsNumber = (value: any): value is number => | Parameter | Type | Description | | :-------- | :---: | :---------- | -| value | `any` | Any ``value`` to check. | +| value | `any` | Any `value` to check | -[Example usage on playground][is-number] | [How to detect `number` type][detect-number] +The **return value** is a `boolean` indicating whether or not the `value` is a `number`. + +[Example usage on playground][is-number] | [How to detect a `number` type][detect-number] ---- ### isObject Use `isObject()` or `is.object()` to check if **any** `value` is a generic `Obj` `object` type and `Object` instance with the possibility of containing `key`. -The **return value** is a `boolean` indicating whether or not the `value` is an `object`. ```typescript const isObject: IsObject = (value: any, key?: Key): value is Obj => @@ -501,16 +511,40 @@ const isObject: IsObject = (value: any, key?: Key): value is Obj = | Parameter | Type | Description | | :-------- | :------: | :---------- | -| value | `any` | Any `value` to check. | -| key? | `Key` | Property name to find in `value`. | +| value | `any` | Any `value` to check | +| key? | `Key` | Property name to find in `value` | + +The **return value** is a `boolean` indicating whether or not the `value` is an `object`. -[Example usage on playground][is-object] | [How to detect `object` type][detect-object] +[Example usage on playground][is-object] | [How to detect an `object` type][detect-object] + +---- + +### isObjectKey + +Use `isObject()` or `is.object()` to check if **any** `value` is a generic `Obj` `object` type and `Object` instance with the possibility of containing the `key`. + +```typescript +const isObject: IsObject = (value: any, key?: Key): value is Obj => + (typeOf(value) === 'object' && typeof value === 'object' && value instanceof Object === true) + ? isKey(key) + ? key in value + : true + : false; +``` + +| Parameter | Type | Description | +| :-------- | :-----------: | :---------- | +| value | `any` | Any `value` to check | +| key? | [`Key`](#key) | Property name to find in `value` | + +The **return value** is a `boolean` indicating whether or not the `value` is an `object`. ---- ### isPrimitive -Use `isPrimitive()` or `is.primitive()` to check if **any** `value` is a generic `Type` type one of the primitive `'boolean'`, `'bigint'`, `'number'`, `'string'`, `'symbol'`, `'undefined'` type. The return value is a `boolean` value. +Use `isPrimitive()` or `is.primitive()` to check if **any** `value` is a generic `Type` from the [`Primitives`](#Primitives). ```typescript const isPrimitive: IsPrimitive = (value: any, type: Primitives): value is Type => { @@ -524,32 +558,36 @@ const isPrimitive: IsPrimitive = (value: any, type: Primitives): value is case 'undefined': return isUndefined(value); } } + return false; }; ``` -| Parameter | Type | Description | -| :-------- | :----------: | :---------- | -| value | `any` | Any `value` to check if it's a generic `Type` type from on of the `type`. | -| type | `Primitives` | One of the `Primitives` `'boolean'`, `'bigint'`, `'number'`, `'string'`, `'symbol'`, `'undefined'` type to check `value`. | +| Parameter | Type | Description | +| :-------- | :-------------------------: | :---------- | +| value | `any` | Any `value` to check if it's a generic `Type` from the `type` | +| type | [`Primitives`](#Primitives) | Type from the [`Primitives`](#Primitives) to check the `value` | -[Example usage][is-primitive] +The **return value** is a `boolean` indicating whether or not the `value` is a type from the [`Primitives`](#Primitives). + +[Example usage on playground][is-primitive] ---- ### isString Use `isString()` or `is.string()` to check if **any** `value` is a `string` type, not instance of `Object` and `String` or `object` type and instance of `String` and `Object`. -The **return value** is a `boolean` indicating whether or not the `value` is a `string`. ```typescript const isString: IsString = (value: any, callback: ResultCallback = errorCallback): value is string => callback(typeOf(value) === 'string' && (isStringObject(value) || isStringType(value))); ``` -| Parameter | Type | Description | -| :-------- | :--------------: | :---------- | -| value | `any` | Any value to check. | -| callback | `ResultCallback` | `ResultCallback` function to handle result before return eg. to throw an `Error`. | +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :---------- | +| value | `any` | Any value to check | +| callback | [`ResultCallback`](#ResultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before return eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a `string`. [Example usage on playground][is-string] | [How to detect `string` type][detect-string] @@ -558,7 +596,6 @@ const isString: IsString = (value: any, callback: ResultCallback = errorCallback ### isSymbol Use `isSymbol()` or `is.symbol()` to check if **any** `value` is a `symbol` type. -The **return value** is a `boolean` indicating whether or not the `value` is a `symbol`. ```typescript const isSymbol: IsSymbol = (value: any): value is symbol => @@ -568,7 +605,9 @@ const isSymbol: IsSymbol = (value: any): value is symbol => | Parameter | Type | Description | | :-------- | :---: | :---------- | -| value | `any` | Any `value` to check if it's a `symbol` type. | +| value | `any` | Any `value` to check | + +The **return value** is a `boolean` indicating whether or not the `value` is a `symbol`. [Example usage on playground][is-symbol] | [How to detect `symbol` type][detect-symbol] @@ -576,7 +615,7 @@ const isSymbol: IsSymbol = (value: any): value is symbol => ### isType -Use `isType()` or `is.type()` Check if **any** `value` is a generic `Type` type constructor, `'function'`, `'object'` or primitive type. The return value is a `boolean` value. +Use `isType()` or `is.type()` to check if **any** `value` is a generic `Type` from the [`Types`](#Types). ```typescript const isType: IsType = (value: any, type: Types): value is Type => { @@ -598,8 +637,10 @@ const isType: IsType = (value: any, type: Types): value is Type => { | Parameter | Type | Description | | :-------- | :-----------: | :---------- | -| value | `any` | Any value to check it is a generic `Type` type from one of the `type`. | -| type | `Types` | Generic constructor `Type`, `'function'`, `'object'` or one of the `Primitives` `'bigint'`, `'boolean'`, `'number'`, `'symbol'`, `'string'`, `'undefined'` to check `value` type. | +| value | `any` | Any `value` to check if its type is from the `type` | +| type | `Types` | One from the `Types` to check the `value` | + +The **return value** is a `boolean` indicating whether or not the `value` is a type from the [`Types`](#Types). [Example usage on playground][is-type] @@ -608,7 +649,6 @@ const isType: IsType = (value: any, type: Types): value is Type => { ### isUndefined Use `isUndefined()` or `is.undefined()` to check if **any** `value` is an `undefined` type and equal to `undefined`. -The **return value** is a `boolean` indicating whether or not the `value` is undefined. ```typescript const isUndefined: IsUndefined = (value: any): value is undefined => @@ -619,16 +659,17 @@ const isUndefined: IsUndefined = (value: any): value is undefined => | Parameter | Type | Description | | :-------- | :---: | :---------- | -| value | `any` | Any `value` to check. | +| value | `any` | Any `value` to check | + +The **return value** is a `boolean` indicating whether or not the `value` is `undefined`. -[Example usage on playground][is-undefined] | [How to detect `'undefined'` type][detect-undefined] +[Example usage on playground][is-undefined] | [How to detect `undefined` type][detect-undefined] ---- ### isNotBoolean Use `isNotBoolean()` or `is.not.boolean()` to check if an **unknown** `value` is NOT a `'boolean'` type, NOT equal to `true` or `false` and NOT an instance of a `Boolean`. -The return value is a `boolean` value. ```typescript const isNotBoolean: IsNotBoolean = (value: unknown): boolean => @@ -643,6 +684,8 @@ const isNotBoolean: IsNotBoolean = (value: unknown): boolean => | :-------- | :-------: | :---------- | | value | `unknown` | An unknown `value` to check if it's NOT a `'boolean'` type, NOT equal to `true` or `false` and NOT an instance of `Boolean`. | +The **return value** is a `boolean` indicating whether or not the `value` is `undefined`. + ---- ### isNotDefined @@ -872,7 +915,7 @@ const guardType: GuardType = (value: Type, type: Types): value is Ty | Parameter | Type | Description | |-------------| :---: |---------------| -| value | `Type` | A generic `Type ` `value` to guard. | +| value | `Type` | A generic `Type` `value` to guard. | | type | `Types` | Constructor generic `Type`, `'function'`, `'object'` or one of the `Primitives` `'boolean'`, `'bigint'`, `'number'`, `'string'`, `'symbol'`, `'undefined'` to check `value`. | [Example usage][guard-type] From 80679d64e06fb66ce0fb11e642c54859360df963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Thu, 22 Apr 2021 14:00:45 +0200 Subject: [PATCH 044/201] refactor(): add check, update imports, update jsdoc - add check `null` - reorder alphabetically imports - categorize imports - update jsdoc `returns`, `type` and general description --- packages/type/src/is/lib/is-primitive.func.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/type/src/is/lib/is-primitive.func.ts b/packages/type/src/is/lib/is-primitive.func.ts index 58b81b46..884b8be8 100644 --- a/packages/type/src/is/lib/is-primitive.func.ts +++ b/packages/type/src/is/lib/is-primitive.func.ts @@ -1,16 +1,19 @@ -import { IsPrimitive } from '../type/is-primitive.type'; -import { Primitives } from '../../type/primitives.type'; -import { isString } from './is-string.func'; +// Function. import { isBigInt } from './is-big-int.func'; import { isBoolean } from './is-boolean.func'; +import { isNull } from './is-null.func'; import { isNumber } from './is-number.func'; +import { isString } from './is-string.func'; import { isSymbol } from './is-symbol.func'; import { isUndefined } from './is-undefined.func'; +// Type. +import { IsPrimitive } from '../type/is-primitive.type'; +import { Primitives } from '../../type/primitives.type'; /** - * Checks if any `value` is a generic type from one of the `Primitives`. - * Use the `guardPrimitive()` function to type-guard generic type also. - * @param value Any `value` to check if it's a generic type from the argument `type`. - * @param type One of the `Primitives` `'bigint'`, `'boolean'`, `'number'`, `'string'`, `'symbol'`, `'undefined'` type to check `value`. + * Checks if any `value` is a generic `Type` from the `Primitives`. + * @param value Any `value` to check if it's a type from the `type`. + * @param type Name of the type from the `Primitives` to check the `value`. + * @returns A `boolean` indicating whether or not the `value` is a type from the `Primitives`. */ export const isPrimitive: IsPrimitive = (value: any, type: Primitives): value is Type => { if (isString(type)) { @@ -18,6 +21,7 @@ export const isPrimitive: IsPrimitive = (value: any, type: Primitives): va case 'bigint': return isBigInt(value); case 'boolean': return isBoolean(value); case 'number': return isNumber(value); + case 'null': return isNull(value); case 'string': return isString(value); case 'symbol': return isSymbol(value); case 'undefined': return isUndefined(value); From 5e3836687316a7340ae77eb30805bd9e6ba76881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Thu, 22 Apr 2021 14:04:45 +0200 Subject: [PATCH 045/201] docs(isPrimitive): update `value` description --- packages/type/src/is/lib/is-primitive.func.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/is/lib/is-primitive.func.ts b/packages/type/src/is/lib/is-primitive.func.ts index 884b8be8..8d54da36 100644 --- a/packages/type/src/is/lib/is-primitive.func.ts +++ b/packages/type/src/is/lib/is-primitive.func.ts @@ -11,7 +11,7 @@ import { IsPrimitive } from '../type/is-primitive.type'; import { Primitives } from '../../type/primitives.type'; /** * Checks if any `value` is a generic `Type` from the `Primitives`. - * @param value Any `value` to check if it's a type from the `type`. + * @param value Any `value` to check if it's a generic `Type` from the `type`. * @param type Name of the type from the `Primitives` to check the `value`. * @returns A `boolean` indicating whether or not the `value` is a type from the `Primitives`. */ From d03b9dca960732d3f3c13e304b6a4352543aa275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Thu, 22 Apr 2021 17:29:04 +0200 Subject: [PATCH 046/201] refactor(Primitives): add 'null' type. --- packages/type/src/type/primitives.type.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/type/primitives.type.ts b/packages/type/src/type/primitives.type.ts index 18f0165a..252ed352 100644 --- a/packages/type/src/type/primitives.type.ts +++ b/packages/type/src/type/primitives.type.ts @@ -1 +1 @@ -export type Primitives = 'bigint' | 'boolean' | 'number' | 'symbol' | 'string' | 'undefined'; +export type Primitives = 'bigint' | 'boolean' | 'null' | 'number' | 'symbol' | 'string' | 'undefined'; From 6e8b24666ef248b0eb34adc6fdd43b24475761d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Thu, 22 Apr 2021 17:39:24 +0200 Subject: [PATCH 047/201] refactor(isType): update code and jsdoc - add `null` check - change the way of checking by using `isPrimitive` function - reorder alphabetically and categorize imports - update generale jsdoc description - update jsdoc `value`, `type` fields - update jsdoc returns --- packages/type/src/is/lib/is-type.func.ts | 44 +++++++++++++++--------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/packages/type/src/is/lib/is-type.func.ts b/packages/type/src/is/lib/is-type.func.ts index b11bd469..15a15c68 100644 --- a/packages/type/src/is/lib/is-type.func.ts +++ b/packages/type/src/is/lib/is-type.func.ts @@ -1,32 +1,42 @@ -import { IsType } from '../type/is-type.type'; -import { Types } from '../../type/types.type'; -import { isString } from './is-string.func'; +// Function. import { isBigInt } from './is-big-int.func'; import { isBoolean } from './is-boolean.func'; +import { isFunction } from './is-function.func'; +import { isInstance } from './is-instance.func'; import { isNumber } from './is-number.func'; +import { isObject } from './is-object.func'; +import { isPrimitive } from './is-primitive.func'; +import { isString } from './is-string.func'; import { isSymbol } from './is-symbol.func'; import { isUndefined } from './is-undefined.func'; -import { isObject } from './is-object.func'; -import { isFunction } from './is-function.func'; -import { isInstance } from './is-instance.func'; +// Type. +import { IsType } from '../type/is-type.type'; +import { Types } from '../../type/types.type'; +import { isNotNull } from '../not/lib/is-not-null.func'; /** - * Checks if any `value` is a generic `Type` type constructor, `'function'`, `'object'` or primitive type. - * Use the `guardType()` to type-guard generic `Type` type also. - * @param value Any value to check if it's a generic `Type` type from one of the `type`. - * @param type Generic constructor `Type`, `'function'`, `'object'` or one of the `Primitives` `'bigint'`, `'boolean'`, `'number'`, `'string'`, `'symbol'`, `'undefined'` to check `value` type. + * Checks if any `value` is a generic `Type` from the `Types`. + * @param value Any `value` to check if its type is from the `type`. + * @param type One type from the `Types` to check the `value`. + * @returns A `boolean` indicating whether or not the `value` is a type from the `Types`. */ export const isType: IsType = (value: any, type: Types): value is Type => { if (isString(type)) { switch (type) { - case 'bigint': return isBigInt(value); - case 'boolean': return isBoolean(value); + // Primitives. + case 'bigint': + case 'boolean': + case 'number': + case 'null' : + case 'string': + case 'symbol': + case 'undefined': return isPrimitive(value, type); + // Function. case 'function': return isFunction(value); - case 'number': return isNumber(value); + // Object. case 'object': return isObject(value); - case 'string': return isString(value); - case 'symbol': return isSymbol(value); - case 'undefined': return isUndefined(value); } + } else if (isNotNull(type)) { + return isInstance(value, type); } - return type ? isInstance(value, type) : false; + return false; }; From f171ba3080c6acd08f06728c5dfc3ee39c2300d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 23 Apr 2021 12:40:32 +0200 Subject: [PATCH 048/201] test(isType): add test --- packages/type/src/is/test/is-type.spec.ts | 82 +++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 packages/type/src/is/test/is-type.spec.ts diff --git a/packages/type/src/is/test/is-type.spec.ts b/packages/type/src/is/test/is-type.spec.ts new file mode 100644 index 00000000..4b587dc2 --- /dev/null +++ b/packages/type/src/is/test/is-type.spec.ts @@ -0,0 +1,82 @@ +// Function. +import { isType } from '../lib/is-type.func'; +// Variables. +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from './variables/big-int.const'; +import { Class, CLASS } from './variables/class.const'; +import { FALSE, TRUE, TRUE_INSTANCE, FALSE_INSTANCE, FALSE_EXPECTATION, TRUE_EXPECTATION } from './variables/boolean.const'; +import { FUNCTION } from './variables/function.const'; +import { NULL } from './variables/null.const'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; +import { OBJECT_ONE, OBJECT_TWO, OBJECT_ONE_NEW, OBJECT_TWO_NEW, ObjectTwo, ObjectOne } from './variables/object.const'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; +import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; +import { UNDEFINED } from './variables/undefined.const'; + +describe(`isType`, () => { + // Defined. + it('is DEFINED', () => expect(isType).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + // ... instance. + describe(`instance`, () => it(`${Class}`, () => expect(isType(CLASS, Class)).toBe(TRUE))); + + // ... function. + describe(`function`, () => { + it(`${FUNCTION}`, () => expect(isType(FUNCTION, 'function')).toBe(TRUE)); + it(`${CLASS}`, () => expect(isType(Class, 'function')).toBe(TRUE)); + }); + + // ... objects. + describe('object', () => { + it(`${JSON.stringify(CLASS)}`, () => expect(isType(CLASS, 'object')).toBe(TRUE)); + it(`${JSON.stringify(OBJECT_ONE)}`, () => expect(isType(OBJECT_ONE, 'object')).toBe(TRUE)); + it(`${JSON.stringify(OBJECT_TWO)}`, () => expect(isType(OBJECT_TWO, 'object')).toBe(TRUE)); + it(`new Object(${JSON.stringify(OBJECT_ONE_NEW)})`, () => expect(isType(OBJECT_ONE_NEW, 'object')).toBe(TRUE)); + it(`new Object(${JSON.stringify(OBJECT_TWO_NEW)})`, () => expect(isType(OBJECT_TWO_NEW, 'object')).toBe(TRUE)); + }); + + // ... primitives. + describe(`primitive`, () => { + // bigint + describe(`bigint`, () => { + it(`${BIGINT}`, () => expect(isType(BIGINT, 'bigint')).toBe(TRUE)); + it(`${BIGINT_EXPECTATION}`, () => expect(isType(BIGINT_INSTANCE, 'bigint')).toBe(TRUE)); + }); + + // boolean + describe(`boolean`, () => { + it(`${TRUE}`, () => expect(isType(TRUE, 'boolean')).toBe(TRUE)); + it(`${FALSE}`, () => expect(isType(FALSE, 'boolean')).toBe(TRUE)); + it(`${FALSE_EXPECTATION}`, () => expect(isType(TRUE_INSTANCE, 'boolean')).toBe(TRUE)); + it(`${TRUE_EXPECTATION}`, () => expect(isType(FALSE_INSTANCE, 'boolean')).toBe(TRUE)); + }); + + // null + it(`${NULL}`, () => expect(isType(NULL, 'null')).toBe(TRUE)); + + // number + describe(`number`, () => { + it(`${NUMBER}`, () => expect(isType(NUMBER, 'number')).toBe(TRUE)); + it(`Number(${NUMBER})`, () => expect(isType(NUMBER_INSTANCE, 'number')).toBe(TRUE)); + it(`new Number(${NUMBER})`, () => expect(isType(NUMBER_NEW_INSTANCE, 'number')).toBe(TRUE)); + }); + + // string + describe(`string`, () => { + it(`${STRING}`, () => expect(isType(STRING, 'string')).toBe(TRUE)); + it(`String(${STRING})`, () => expect(isType(STRING_INSTANCE, 'string')).toBe(TRUE)); + it(`new String(${STRING})`, () => expect(isType(STRING_NEW_INSTANCE, 'string')).toBe(TRUE)); + }); + + // symbol + describe(`symbol`, () => { + it(`Symbol(${NUMBER})`, () => expect(isType(SYMBOL_NUMBER, 'symbol')).toBe(TRUE)); + it(`Symbol(${STRING})`, () => expect(isType(SYMBOL_STRING, 'symbol')).toBe(TRUE)); + }); + + // undefined + it(`${UNDEFINED}`, () => expect(isType(UNDEFINED, 'undefined')).toBe(TRUE)); + }); + }); +}); From 9ed3cd1da148bb4aced58bc43e10b6d64b02d7c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 23 Apr 2021 12:41:35 +0200 Subject: [PATCH 049/201] chore(Primitives): sort alphabetically --- packages/type/src/type/primitives.type.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/type/primitives.type.ts b/packages/type/src/type/primitives.type.ts index 252ed352..ab1ade93 100644 --- a/packages/type/src/type/primitives.type.ts +++ b/packages/type/src/type/primitives.type.ts @@ -1 +1 @@ -export type Primitives = 'bigint' | 'boolean' | 'null' | 'number' | 'symbol' | 'string' | 'undefined'; +export type Primitives = 'bigint' | 'boolean' | 'null' | 'number' | 'string' | 'symbol' | 'undefined'; From 65c103b56267de4ce1c25dc70a0e60017758e518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 23 Apr 2021 12:42:17 +0200 Subject: [PATCH 050/201] test: update --- packages/type/src/is/test/is-object.spec.ts | 8 +- packages/type/src/is/test/is-string.spec.ts | 134 +++++++++++--------- 2 files changed, 77 insertions(+), 65 deletions(-) diff --git a/packages/type/src/is/test/is-object.spec.ts b/packages/type/src/is/test/is-object.spec.ts index c66641c2..becbe9e8 100644 --- a/packages/type/src/is/test/is-object.spec.ts +++ b/packages/type/src/is/test/is-object.spec.ts @@ -21,7 +21,7 @@ describe('isObject', () => { it('is DEFINED', () => { expect(isObject).toBeDefined(); }); - it(`Class | CLASS`, () => { + it(`CLASS instance of class`, () => { expect(isObject(CLASS)).toBeTruthy(); }); it(`'object' | Object`, () => { @@ -40,7 +40,7 @@ describe('isObject', () => { expect(isObject(FALSE_INSTANCE)).toBeFalsy(); expect(isObject(TRUE_INSTANCE)).toBeFalsy(); }); - it(`Class | CLASS`, () => { + it(`Class`, () => { expect(isObject(Class)).toBeFalsy(); }); it(`'function' | Function`, () => { @@ -50,12 +50,12 @@ describe('isObject', () => { expect(isObject(null)).toBeFalsy(); expect(isObject(NULL)).toBeFalsy(); }); - it(`'number' | Number`, () => { + it(`number and instance of Number`, () => { expect(isObject(NUMBER)).toBeFalsy(); expect(isObject(NUMBER_INSTANCE)).toBeFalsy(); expect(isObject(NUMBER_NEW_INSTANCE)).toBeFalsy(); }); - it(`'string' | String`, () => { + it(`string | String`, () => { expect(isObject(STRING)).toBeFalsy(); expect(isObject(STRING_INSTANCE)).toBeFalsy(); expect(isObject(STRING_NEW_INSTANCE)).toBeFalsy(); diff --git a/packages/type/src/is/test/is-string.spec.ts b/packages/type/src/is/test/is-string.spec.ts index c46e0b11..3d154b81 100644 --- a/packages/type/src/is/test/is-string.spec.ts +++ b/packages/type/src/is/test/is-string.spec.ts @@ -1,72 +1,84 @@ -/** - * Checks - * ✓ typeof === 'string' && instanceof String === false && instanceof Object === false - * ✓ typeof === 'object' && instanceof String === true && instanceof Object === true - */ - -import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; -import { BIGINT, BIGINT_INSTANCE } from './variables/big-int.const'; +// Function. +import { isString } from '../lib/is-string.func'; +// Variables. +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from './variables/big-int.const'; import { Class, CLASS } from './variables/class.const'; +import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE, FALSE_EXPECTATION, TRUE_EXPECTATION } from './variables/boolean.const'; import { FUNCTION } from './variables/function.const'; -import { notDefined } from './variables.const'; import { NULL } from './variables/null.const'; import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; -import { OBJECT_ONE, OBJECT_TWO } from './variables/object.const'; +import { OBJECT_ONE, OBJECT_TWO, ObjectOne, ObjectTwo, OBJECT_ONE_NEW, OBJECT_TWO_NEW } from './variables/object.const'; import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; import { UNDEFINED } from './variables/undefined.const'; -import { isString } from '../lib/is-string.func'; -describe('isString', () => { - // TRUE - it('is DEFINED', () => { - expect(isString).toBeDefined(); - }); - it(`'string' | String`, () => { - expect(isString(STRING)).toBeTruthy(); - expect(isString(STRING_INSTANCE)).toBeTruthy(); - expect(isString(STRING_NEW_INSTANCE)).toBeTruthy(); - }); +/** + * Checks + * ✓ typeof === 'string' && instanceof String === false && instanceof Object === false + * ✓ typeof === 'object' && instanceof String === true && instanceof Object === true + */ +describe(`isString`, () => { + // Defined. + it('is DEFINED', () => expect(isString).toBeDefined()); - // FALSE - it(`'bigint'`, () => { - expect(isString(BIGINT)).toBeFalsy(); - expect(isString(BIGINT_INSTANCE)).toBeFalsy(); - }); - it(`'boolean' | Boolean`, () => { - expect(isString(FALSE)).toBeFalsy(); - expect(isString(TRUE)).toBeFalsy(); - expect(isString(FALSE_INSTANCE)).toBeFalsy(); - expect(isString(TRUE_INSTANCE)).toBeFalsy(); - expect(isString(Boolean(false))).toBeFalsy(); - expect(isString(Boolean(true))).toBeFalsy(); - }); - it(`Class | CLASS`, () => { - expect(isString(Class)).toBeFalsy(); - expect(isString(CLASS)).toBeFalsy(); - }); - it(`'function' | Function`, () => { - expect(isString(FUNCTION)).toBeFalsy(); - }); - it(`null | NULL`, () => { - expect(isString(null)).toBeFalsy(); - expect(isString(NULL)).toBeFalsy(); - }); - it(`'number' | Number`, () => { - expect(isString(NUMBER)).toBeFalsy(); - expect(isString(NUMBER_INSTANCE)).toBeFalsy(); - expect(isString(NUMBER_NEW_INSTANCE)).toBeFalsy(); - }); - it(`'object' | Object`, () => { - expect(isString(OBJECT_ONE)).toBeFalsy(); - expect(isString(OBJECT_TWO)).toBeFalsy(); - }); - it(`'symbol'`, () => { - expect(isString(SYMBOL_NUMBER)).toBeFalsy(); - expect(isString(SYMBOL_STRING)).toBeFalsy(); - }); - it(`'undefined'`, () => { - expect(isString(notDefined)).toBeFalse(); - expect(isString(UNDEFINED)).toBeFalse(); + // Checks ... + describe(`checks`, () => { + // ... arrays. + describe(`array`, () => { + // it(`${FUNCTION}`, () => expect(isString(FUNCTION, 'function')).toBe(FALSE)); + // it(`${Class}`, () => expect(isString(Class, 'function')).toBe(FALSE)); + }); + // ... function. + describe(`function`, () => { + it(`${FUNCTION}`, () => expect(isString(FUNCTION)).toBe(FALSE)); + it(`${Class}`, () => expect(isString(Class)).toBe(FALSE)); + }); + // ... objects. + describe('object', () => { + it(`${JSON.stringify(CLASS)}`, () => expect(isString(CLASS)).toBe(FALSE)); + it(`${JSON.stringify(OBJECT_ONE)}`, () => expect(isString(OBJECT_ONE)).toBe(FALSE)); + it(`${JSON.stringify(OBJECT_TWO)}`, () => expect(isString(OBJECT_TWO)).toBe(FALSE)); + it(`new Object(${JSON.stringify(OBJECT_ONE_NEW)})`, () => expect(isString(OBJECT_ONE_NEW)).toBe(FALSE)); + it(`new Object(${JSON.stringify(OBJECT_TWO_NEW)})`, () => expect(isString(OBJECT_TWO_NEW)).toBe(FALSE)); + }); + // ... primitives. + describe(`primitive`, () => { + // bigint + describe(`bigint`, () => { + it(`${BIGINT}`, () => expect(isString(BIGINT)).toBe(FALSE)); + it(`${BIGINT_EXPECTATION}`, () => expect(isString(BIGINT_INSTANCE)).toBe(FALSE)); + }); + + // boolean + describe(`boolean`, () => { + it(`${TRUE}`, () => expect(isString(TRUE)).toBe(FALSE)); + it(`${FALSE}`, () => expect(isString(FALSE)).toBe(FALSE)); + it(`${FALSE_EXPECTATION}`, () => expect(isString(TRUE_INSTANCE)).toBe(FALSE)); + it(`${TRUE_EXPECTATION}`, () => expect(isString(FALSE_INSTANCE)).toBe(FALSE)); + }); + + // null + it(`${NULL}`, () => expect(isString(NULL)).toBe(FALSE)) + + // number + describe(`number`, () => { + it(`${NUMBER}`, () => expect(isString(NUMBER)).toBe(FALSE)); + it(`Number(${NUMBER})`, () => expect(isString(NUMBER_INSTANCE)).toBe(FALSE)); + it(`new Number(${NUMBER})`, () => expect(isString(NUMBER_NEW_INSTANCE)).toBe(FALSE)); + }); + // string + describe(`string`, () => { + it(`${STRING}`, () => expect(isString(STRING)).toBe(TRUE)); + it(`String(${STRING})`, () => expect(isString(STRING_INSTANCE)).toBe(TRUE)); + it(`new String(${STRING})`, () => expect(isString(STRING_NEW_INSTANCE)).toBe(TRUE)); + }); + // symbol + describe(`symbol`, () => { + it(`Symbol(${NUMBER})`, () => expect(isString(SYMBOL_NUMBER)).toBe(FALSE)); + it(`Symbol(${STRING})`, () => expect(isString(SYMBOL_STRING)).toBe(FALSE)); + }); + // undefined + it(`${UNDEFINED}`, () => expect(isString(UNDEFINED)).toBe(FALSE)); + }); }); }); From e8eab026bca053b011e6a3a9b9f3565828305059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 23 Apr 2021 12:44:41 +0200 Subject: [PATCH 051/201] chore(isUndefined): update jsdoc, imports - categorize and sort alphabetically imports - update `value` and `returns` field jsdoc --- packages/type/src/is/lib/is-undefined.func.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/type/src/is/lib/is-undefined.func.ts b/packages/type/src/is/lib/is-undefined.func.ts index 3034a90d..2339aa2b 100644 --- a/packages/type/src/is/lib/is-undefined.func.ts +++ b/packages/type/src/is/lib/is-undefined.func.ts @@ -1,9 +1,11 @@ -import { IsUndefined } from '../type/is-undefined.type'; +// Function. import { typeOf } from '../../lib/type-of.func'; +// Type. +import { IsUndefined } from '../type/is-undefined.type'; /** - * Checks if any `value` is an `'undefined'` type and equal to `undefined`. - * @param value Any `value` to check if it's an `'undefined'` type and equal to `undefined`. - * @returns boolean. + * Checks if any `value` is an `undefined` type and equal to `undefined`. + * @param value Any `value` to check. + * @returns A `boolean` indicating whether or not the `value` is `undefined`. */ export const isUndefined: IsUndefined = (value: any): value is undefined => typeOf(value) === 'undefined' && From 79e855bb44682c2577a2b92736f22a08928160e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 23 Apr 2021 12:52:07 +0200 Subject: [PATCH 052/201] chore(is): update Added - `isKey` function in `key` property - `objectKey` function in `objectKey` property Changed - `bigInt` will be removed in favor of `bigint` to have strict names as `Primitives` - reorder alphabetically imports --- packages/type/src/is/lib/is.object.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/type/src/is/lib/is.object.ts b/packages/type/src/is/lib/is.object.ts index d3cc099a..53b3251c 100644 --- a/packages/type/src/is/lib/is.object.ts +++ b/packages/type/src/is/lib/is.object.ts @@ -1,34 +1,39 @@ -// Interface. -import { Is } from '../interface/is.interface'; -// Functions. +// Function. import { isArray } from './is-array.func'; import { isBigInt } from './is-big-int.func'; import { isBoolean } from './is-boolean.func'; import { isDefined } from './is-defined.func'; import { isFunction } from './is-function.func'; import { isInstance } from './is-instance.func'; +import { isKey } from './is-key.func'; import { isNull } from './is-null.func'; import { isNumber } from './is-number.func'; import { isObject } from './is-object.func'; +import { isObjectKey } from './is-object-key.func'; import { isPrimitive } from './is-primitive.func'; import { isString } from './is-string.func'; import { isSymbol } from './is-symbol.func'; import { isType } from './is-type.func'; import { isUndefined } from './is-undefined.func'; -// Objects. +// Object. import { isNot } from '../not/lib/is-not.object'; +// Interface. +import { Is } from '../interface/is.interface'; export const is: Is = { array: isArray, - bigInt: isBigInt, + bigint: isBigInt, + bigInt: isBigInt, // deprecated boolean: isBoolean, defined: isDefined, function: isFunction, instance: isInstance, + key: isKey, not: isNot, null: isNull, number: isNumber, object: isObject, + objectKey: isObjectKey, primitive: isPrimitive, string: isString, symbol: isSymbol, From ff506285fbc8d298e6c7dad3e5d2b09edd075b30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 23 Apr 2021 18:22:18 +0200 Subject: [PATCH 053/201] test: move `notDefined` to proper file, order alphabetically imports --- .../type/src/guard/test/guard-array.spec.ts | 18 +++-------------- .../src/is/not/test/is-not-boolean.spec.ts | 16 +++++++-------- packages/type/src/is/test/is-array.spec.ts | 2 +- packages/type/src/is/test/is-big-int.spec.ts | 2 +- packages/type/src/is/test/is-boolean.spec.ts | 18 ++++++++--------- packages/type/src/is/test/is-defined.spec.ts | 15 +++++++------- packages/type/src/is/test/is-function.spec.ts | 4 ++-- packages/type/src/is/test/is-instance.spec.ts | 8 ++------ packages/type/src/is/test/is-null.spec.ts | 3 +-- packages/type/src/is/test/is-number.spec.ts | 12 +++++------ packages/type/src/is/test/is-object.spec.ts | 20 ++++++++++--------- 11 files changed, 51 insertions(+), 67 deletions(-) diff --git a/packages/type/src/guard/test/guard-array.spec.ts b/packages/type/src/guard/test/guard-array.spec.ts index 1c73f5c2..721fc838 100644 --- a/packages/type/src/guard/test/guard-array.spec.ts +++ b/packages/type/src/guard/test/guard-array.spec.ts @@ -1,11 +1,10 @@ // Function. import { guardArray } from '../lib/guard-array.func'; - // Variables. +import { BIGINT, BIGINT_INSTANCE } from '../../is/test/variables/big-int.const'; import { Class } from '../../is/test/variables/class.const'; import { Func } from '../../type/func.type'; import { ObjectOne, ObjectTwo, OBJECT_ONE, OBJECT_TWO } from '../../is/test/variables/object.const'; -import { BIGINT, BIGINT_INSTANCE } from '../../is/test/variables/big-int.const'; import { ARRAY_BIGINT, ARRAY_BOOLEAN, @@ -16,8 +15,8 @@ import { ARRAY_OBJECT_ONE, ARRAY_OBJECT_TWO, ARRAY_STRING, - ARRAY_SYMBOL_STRING, ARRAY_SYMBOL_NUMBER, + ARRAY_SYMBOL_STRING, ARRAY_UNDEFINED } from '../../is/test/variables/array.const'; import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from '../../is/test/variables/boolean.const'; @@ -25,8 +24,8 @@ import { FUNCTION } from '../../is/test/variables/function.const'; import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from '../../is/test/variables/number.const'; import { STRING, STRING_INSTANCE } from '../../is/test/variables/string.const'; import { SYMBOL_NUMBER, SYMBOL_STRING } from '../../is/test/variables/symbol.const'; -import { notDefined } from '../../is/test/variables.const'; import { UNDEFINED } from '../../is/test/variables/undefined.const'; +import { notDefined } from '../../is/test/variables/not-defined.const'; describe('guardArray', () => { // TRUE @@ -62,26 +61,15 @@ describe('guardArray', () => { expect(guardArray(FALSE_INSTANCE)).toBeFalsy(); expect(guardArray(TRUE_INSTANCE)).toBeFalsy(); }); - // it(`'function' | Function`, () => { - // expect(guardArray([FUNCTION])).toBeTrue(); - // }); it(`'number' | Number`, () => { expect(guardArray(NUMBER)).toBeFalsy(); expect(guardArray(NUMBER_INSTANCE)).toBeFalsy(); expect(guardArray(NUMBER_NEW_INSTANCE)).toBeFalsy(); }); - // it(`'object' | Object`, () => { - // expect(guardArray([OBJECT_ONE])).toBeTruthy(); - // expect(guardArray([OBJECT_TWO])).toBeTruthy(); - // }); it(`'string' | String`, () => { expect(guardArray(STRING)).toBeFalsy(); expect(guardArray(STRING_INSTANCE)).toBeFalsy(); }); - it(`'symbol'`, () => { - expect(guardArray(SYMBOL_NUMBER)).toBeFalsy(); - expect(guardArray(SYMBOL_STRING)).toBeFalsy(); - }); it(`'undefined'`, () => { expect(guardArray(notDefined)).toBeFalse(); expect(guardArray(UNDEFINED)).toBeFalse(); diff --git a/packages/type/src/is/not/test/is-not-boolean.spec.ts b/packages/type/src/is/not/test/is-not-boolean.spec.ts index 9fe71a7d..6e2b4678 100644 --- a/packages/type/src/is/not/test/is-not-boolean.spec.ts +++ b/packages/type/src/is/not/test/is-not-boolean.spec.ts @@ -1,17 +1,17 @@ // Function. import { isNotBoolean } from '../lib/is-not-boolean.func'; // Variables. -import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from '../../test/variables/boolean.const'; import { BIGINT, BIGINT_INSTANCE } from '../../test/variables/big-int.const'; import { Class, CLASS } from '../../test/variables/class.const'; -import { notDefined } from '../../test/variables.const'; -import { UNDEFINED } from '../../test/variables/undefined.const'; -import { SYMBOL_NUMBER, SYMBOL_STRING } from '../../test/variables/symbol.const'; -import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from '../../test/variables/string.const'; -import { OBJECT_ONE, OBJECT_TWO } from '../../test/variables/object.const'; -import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from '../../test/variables/number.const'; -import { NULL } from '../../test/variables/null.const'; +import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from '../../test/variables/boolean.const'; import { FUNCTION } from '../../test/variables/function.const'; +import { NULL } from '../../test/variables/null.const'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from '../../test/variables/number.const'; +import { OBJECT_ONE, OBJECT_TWO } from '../../test/variables/object.const'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from '../../test/variables/string.const'; +import { SYMBOL_NUMBER, SYMBOL_STRING } from '../../test/variables/symbol.const'; +import { UNDEFINED } from '../../test/variables/undefined.const'; +import { notDefined } from '../../test/variables/not-defined.const'; describe('isNotBoolean', () => { // TRUE diff --git a/packages/type/src/is/test/is-array.spec.ts b/packages/type/src/is/test/is-array.spec.ts index 9bd2322e..9310b9a6 100644 --- a/packages/type/src/is/test/is-array.spec.ts +++ b/packages/type/src/is/test/is-array.spec.ts @@ -7,7 +7,6 @@ import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean. import { OBJECT_ONE, OBJECT_TWO, ObjectOne, ObjectTwo } from './variables/object.const'; import { STRING, STRING_INSTANCE } from './variables/string.const'; import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; -import { notDefined } from './variables.const'; import { UNDEFINED } from './variables/undefined.const'; import { ARRAY_BIGINT, @@ -25,6 +24,7 @@ import { } from './variables/array.const'; import { Class } from './variables/class.const'; import { Func } from '../../type/func.type'; +import { notDefined } from './variables/not-defined.const'; describe('isArray', () => { diff --git a/packages/type/src/is/test/is-big-int.spec.ts b/packages/type/src/is/test/is-big-int.spec.ts index 1fca731a..6ab857f6 100644 --- a/packages/type/src/is/test/is-big-int.spec.ts +++ b/packages/type/src/is/test/is-big-int.spec.ts @@ -6,7 +6,6 @@ import { isBigInt } from '../lib/is-big-int.func'; import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; import { BIGINT, BIGINT_INSTANCE } from './variables/big-int.const'; import { FUNCTION } from './variables/function.const'; -import { notDefined } from './variables.const'; import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; import { OBJECT_ONE, OBJECT_TWO } from './variables/object.const'; import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; @@ -14,6 +13,7 @@ import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; import { UNDEFINED } from './variables/undefined.const'; import { CLASS, Class } from './variables/class.const'; import { NULL } from './variables/null.const'; +import { notDefined } from './variables/not-defined.const'; describe('isBigInt', () => { // TRUE diff --git a/packages/type/src/is/test/is-boolean.spec.ts b/packages/type/src/is/test/is-boolean.spec.ts index b7d55008..a019d6be 100644 --- a/packages/type/src/is/test/is-boolean.spec.ts +++ b/packages/type/src/is/test/is-boolean.spec.ts @@ -1,22 +1,22 @@ -/** - * Checks - * ✓ typeof === 'boolean' - * ✓ instanceof Boolean - */ - +// Function. import { isBoolean } from '../lib/is-boolean.func'; -import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; +// Variables. import { BIGINT, BIGINT_INSTANCE } from './variables/big-int.const'; import { Class, CLASS } from './variables/class.const'; +import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; import { FUNCTION } from './variables/function.const'; -import { notDefined } from './variables.const'; import { NULL } from './variables/null.const'; import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; import { OBJECT_ONE, OBJECT_TWO } from './variables/object.const'; import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; import { UNDEFINED } from './variables/undefined.const'; - +import { notDefined } from './variables/not-defined.const'; +/** + * Checks + * ✓ typeof === 'boolean' + * ✓ instanceof Boolean + */ describe('isBoolean', () => { // TRUE it('is DEFINED', () => { diff --git a/packages/type/src/is/test/is-defined.spec.ts b/packages/type/src/is/test/is-defined.spec.ts index 7b39bbd9..2c19fab4 100644 --- a/packages/type/src/is/test/is-defined.spec.ts +++ b/packages/type/src/is/test/is-defined.spec.ts @@ -1,24 +1,23 @@ -/** - * Checks - * ✓ typeof !== 'undefined' - * ✓ vale !== undefined - */ - // Function. import { isDefined } from '../lib/is-defined.func'; // Variables. -import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; import { BIGINT, BIGINT_INSTANCE } from './variables/big-int.const'; import { Class, CLASS } from './variables/class.const'; +import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; import { FUNCTION } from './variables/function.const'; -import { notDefined } from './variables.const'; import { NULL } from './variables/null.const'; import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; import { OBJECT_ONE, OBJECT_TWO } from './variables/object.const'; import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; import { UNDEFINED } from './variables/undefined.const'; +import { notDefined } from './variables/not-defined.const'; +/** + * Checks + * ✓ typeof !== 'undefined' + * ✓ vale !== undefined + */ describe('isDefined', () => { // TRUE it('is DEFINED', () => { diff --git a/packages/type/src/is/test/is-function.spec.ts b/packages/type/src/is/test/is-function.spec.ts index 7b7d7817..50166f96 100644 --- a/packages/type/src/is/test/is-function.spec.ts +++ b/packages/type/src/is/test/is-function.spec.ts @@ -1,17 +1,17 @@ // Function. import { isFunction } from '../lib/is-function.func'; // Variables. -import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; import { BIGINT, BIGINT_INSTANCE } from './variables/big-int.const'; import { Class, CLASS } from './variables/class.const'; +import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; import { FUNCTION } from './variables/function.const'; -import { notDefined } from './variables.const'; import { NULL } from './variables/null.const'; import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; import { OBJECT_ONE, OBJECT_TWO } from './variables/object.const'; import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; import { UNDEFINED } from './variables/undefined.const'; +import { notDefined } from './variables/not-defined.const'; describe('isFunction', () => { // TRUE diff --git a/packages/type/src/is/test/is-instance.spec.ts b/packages/type/src/is/test/is-instance.spec.ts index 3de85144..90e88edf 100644 --- a/packages/type/src/is/test/is-instance.spec.ts +++ b/packages/type/src/is/test/is-instance.spec.ts @@ -5,13 +5,13 @@ import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean. import { BIGINT, BIGINT_INSTANCE } from './variables/big-int.const'; import { Class, CLASS } from './variables/class.const'; import { FUNCTION } from './variables/function.const'; -import { notDefined } from './variables.const'; import { NULL } from './variables/null.const'; import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; // import { OBJECT_ONE, OBJECT_TWO } from './variables/object.const'; import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; import { UNDEFINED } from './variables/undefined.const'; +import { notDefined } from './variables/not-defined.const'; describe('isInstance', () => { // TRUE. @@ -56,13 +56,9 @@ describe('isInstance', () => { expect(isInstance(STRING_INSTANCE, STRING_INSTANCE)).toBeFalse(); expect(isInstance(STRING_NEW_INSTANCE, STRING_NEW_INSTANCE)).toBeFalse(); }); - it(`'symbol'`, () => { - expect(isInstance(SYMBOL_NUMBER, SYMBOL_NUMBER)).toBeFalse(); - expect(isInstance(SYMBOL_STRING, SYMBOL_STRING)).toBeFalse(); - }); // FALSE - it(`'undefined'`, () => { + it(`undefined`, () => { expect(isInstance(notDefined, notDefined)).toBeFalse(); expect(isInstance(UNDEFINED, UNDEFINED)).toBeFalse(); }); diff --git a/packages/type/src/is/test/is-null.spec.ts b/packages/type/src/is/test/is-null.spec.ts index 4017e633..3314551a 100644 --- a/packages/type/src/is/test/is-null.spec.ts +++ b/packages/type/src/is/test/is-null.spec.ts @@ -1,19 +1,18 @@ // Function. import { isNull } from '../lib/is-null.func'; - // Variables. import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; import { BIGINT, BIGINT_INSTANCE } from './variables/big-int.const'; import { Class, CLASS } from './variables/class.const'; import { FUNCTION } from './variables/function.const'; -import { notDefined } from './variables.const'; import { NULL } from './variables/null.const'; import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; import { OBJECT_ONE, OBJECT_TWO } from './variables/object.const'; import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; import { UNDEFINED } from './variables/undefined.const'; +import { notDefined } from './variables/not-defined.const'; describe('isNull', () => { // TRUE diff --git a/packages/type/src/is/test/is-number.spec.ts b/packages/type/src/is/test/is-number.spec.ts index 68b382ce..dca6f3b5 100644 --- a/packages/type/src/is/test/is-number.spec.ts +++ b/packages/type/src/is/test/is-number.spec.ts @@ -1,14 +1,8 @@ -/** - * Checks - * ✓ typeof === 'number' - * ✓ instanceof Number - */ import { isNumber } from '../lib/is-number.func'; import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; import { BIGINT, BIGINT_INSTANCE } from './variables/big-int.const'; import { FUNCTION } from './variables/function.const'; -import { notDefined } from './variables.const'; import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; import { OBJECT_ONE, OBJECT_TWO } from './variables/object.const'; import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; @@ -16,7 +10,13 @@ import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; import { UNDEFINED } from './variables/undefined.const'; import { CLASS, Class } from './variables/class.const'; import { NULL } from './variables/null.const'; +import { notDefined } from './variables/not-defined.const'; +/** + * Checks + * ✓ typeof === 'number' + * ✓ instanceof Number + */ describe('isNumber', () => { // TRUE it('is DEFINED', () => { diff --git a/packages/type/src/is/test/is-object.spec.ts b/packages/type/src/is/test/is-object.spec.ts index becbe9e8..d4780d9b 100644 --- a/packages/type/src/is/test/is-object.spec.ts +++ b/packages/type/src/is/test/is-object.spec.ts @@ -1,21 +1,23 @@ -/** - * Checks - * ✓ typeof === 'object' - * ✓ instanceof Object - */ +// Function. import { isObject } from '../lib/is-object.func'; -import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; +// Variables. import { BIGINT, BIGINT_INSTANCE } from './variables/big-int.const'; +import { CLASS, Class } from './variables/class.const'; +import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; import { FUNCTION } from './variables/function.const'; -import { notDefined } from './variables.const'; +import { NULL } from './variables/null.const'; import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; import { OBJECT_ONE, OBJECT_TWO, ObjectOne, ObjectTwo } from './variables/object.const'; import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; import { UNDEFINED } from './variables/undefined.const'; -import { CLASS, Class } from './variables/class.const'; -import { NULL } from './variables/null.const'; +import { notDefined } from './variables/not-defined.const'; +/** + * Checks + * ✓ typeof === 'object' + * ✓ instanceof Object + */ describe('isObject', () => { // TRUE it('is DEFINED', () => { From 25c86da74c76d711f2394dbac21eedee07277ee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 23 Apr 2021 18:24:15 +0200 Subject: [PATCH 054/201] chore: add `notDefined` to its own file, update path to it --- .../type/src/is/test/variables/array.const.ts | 16 ++++++++++------ .../src/is/test/variables/not-defined.const.ts | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 packages/type/src/is/test/variables/not-defined.const.ts diff --git a/packages/type/src/is/test/variables/array.const.ts b/packages/type/src/is/test/variables/array.const.ts index 11daf6c2..a7b88bfb 100644 --- a/packages/type/src/is/test/variables/array.const.ts +++ b/packages/type/src/is/test/variables/array.const.ts @@ -1,13 +1,17 @@ -import { FALSE, TRUE, TRUE_INSTANCE, FALSE_INSTANCE } from './boolean.const'; -import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './number.const'; -import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './string.const'; +// Variables. import { BIGINT, BIGINT_INSTANCE } from './big-int.const'; -import { NULL } from './null.const'; import { Class } from './class.const'; +import { FALSE, TRUE, TRUE_INSTANCE, FALSE_INSTANCE } from './boolean.const'; +import { NULL } from './null.const'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './number.const'; import { ObjectOne, ObjectTwo } from './object.const'; -import { Func } from '../../../type/func.type'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './string.const'; import { UNDEFINED } from './undefined.const'; -import { notDefined } from '../variables.const'; + +// Type. +import { Func } from '../../../type/func.type'; +import { notDefined } from './not-defined.const'; + // Arrays. // Array with `bigint`. export const ARRAY_BIGINT: Array = [BIGINT, BIGINT_INSTANCE, 9007199254740991n]; diff --git a/packages/type/src/is/test/variables/not-defined.const.ts b/packages/type/src/is/test/variables/not-defined.const.ts new file mode 100644 index 00000000..d0483860 --- /dev/null +++ b/packages/type/src/is/test/variables/not-defined.const.ts @@ -0,0 +1 @@ +export let notDefined: any; // typeof === 'undefined' From f60a4522bf8fb3fe011d700721c280ae391d99af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 23 Apr 2021 18:25:53 +0200 Subject: [PATCH 055/201] refactor(isObjectKey): add `Type = object` to returned value, update jsdoc --- packages/type/src/is/lib/is-object-key.func.ts | 6 +++--- packages/type/src/is/type/is-object-key.type.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/type/src/is/lib/is-object-key.func.ts b/packages/type/src/is/lib/is-object-key.func.ts index be9783ca..ca97244c 100644 --- a/packages/type/src/is/lib/is-object-key.func.ts +++ b/packages/type/src/is/lib/is-object-key.func.ts @@ -9,10 +9,10 @@ import { Key } from '../../type/key.type'; * Determines if any `object` has its own specified keys of the `Key` type. * @param object Any `object` to check if it contains a specified `key`. * @param key `Key` type or an array of `Key` type to check. - * @returns A `boolean` indicating whether or not the `object` has its own specified keys of `Key` type. + * @returns A `boolean` indicating whether or not the `object` has its own specified keys of `Key`. */ -export const isObjectKey: IsObjectKey = (object: any, key: Key | Key[]): object is object => - isObject(object) ? +export const isObjectKey: IsObjectKey = (object: any, key: Key | Key[]): object is Type => + isObject(object) ? isArray(key) ? key.every(k => isKey(k) ? ({}).hasOwnProperty.call(object, k) === true : false) : isKey(key) ? diff --git a/packages/type/src/is/type/is-object-key.type.ts b/packages/type/src/is/type/is-object-key.type.ts index 7b133268..e1961aa6 100644 --- a/packages/type/src/is/type/is-object-key.type.ts +++ b/packages/type/src/is/type/is-object-key.type.ts @@ -1,2 +1,2 @@ import { Key } from '../../type/key.type'; -export type IsObjectKey = (object: any, key: Key | Key[]) => object is object; +export type IsObjectKey = (object: any, key: Key | Key[]) => object is Type; From 9560ddc74079c60f50aa1d75ef8dd4b35b1c8db0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 23 Apr 2021 18:26:56 +0200 Subject: [PATCH 056/201] chore: add expectation for test --- packages/type/src/is/test/variables/big-int.const.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/type/src/is/test/variables/big-int.const.ts b/packages/type/src/is/test/variables/big-int.const.ts index fb37af3c..e66af580 100644 --- a/packages/type/src/is/test/variables/big-int.const.ts +++ b/packages/type/src/is/test/variables/big-int.const.ts @@ -13,3 +13,5 @@ export const BIGINT: any = 9007199254740991n; // typeof === 'bigint' * instanceof Object === false */ export const BIGINT_INSTANCE: any = BigInt('9007199254740991'); // typeof === 'bigint' + +export const BIGINT_EXPECTATION = `BigInt('9007199254740991')`; From a97daa5087d46cdb8bc5bf39e1017a3227975d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 23 Apr 2021 18:27:09 +0200 Subject: [PATCH 057/201] chore: remove unnecessary `notDefined` --- packages/type/src/is/test/variables.const.ts | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 packages/type/src/is/test/variables.const.ts diff --git a/packages/type/src/is/test/variables.const.ts b/packages/type/src/is/test/variables.const.ts deleted file mode 100644 index 3fce92af..00000000 --- a/packages/type/src/is/test/variables.const.ts +++ /dev/null @@ -1,8 +0,0 @@ -// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures -/** - * Check typeof === 'undefined', 'boolean', 'function', 'number', 'object', 'string', 'bigint', 'symbol' - * Check instanceof String, Boolean, Number, Function, Object - */ -export let notDefined: any; // typeof === 'undefined' - - From a6991024f72d26bb71fabe0b0fdf88415776e897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 23 Apr 2021 18:28:03 +0200 Subject: [PATCH 058/201] chore: add expectation for test, use constant to create instance --- packages/type/src/is/test/variables/boolean.const.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/type/src/is/test/variables/boolean.const.ts b/packages/type/src/is/test/variables/boolean.const.ts index 79fa33b2..d17bedd2 100644 --- a/packages/type/src/is/test/variables/boolean.const.ts +++ b/packages/type/src/is/test/variables/boolean.const.ts @@ -18,5 +18,8 @@ export const TRUE: any = true; // typeof === 'boolean' * instanceof Boolean === true * instanceof Object === true */ -export const FALSE_INSTANCE: any = new Boolean(false); // instanceof Boolean -export const TRUE_INSTANCE: any = new Boolean(true); // instanceof Boolean +export const FALSE_INSTANCE: any = new Boolean(FALSE); // instanceof Boolean +export const TRUE_INSTANCE: any = new Boolean(TRUE); // instanceof Boolean + +export const FALSE_EXPECTATION = `new Boolean(${FALSE})`; +export const TRUE_EXPECTATION = `new Boolean(${TRUE})`; From 5c592e5c17cccbdb4127baef27f01496816d15b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 23 Apr 2021 18:31:17 +0200 Subject: [PATCH 059/201] chore(Class): add more properties to class Added - property with number key - property with symbol number key - property with symbol string key - getter with key number - getter with key string - getter with key as symbol number - getter with key as symbol string --- .../type/src/is/test/variables/class.const.ts | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/type/src/is/test/variables/class.const.ts b/packages/type/src/is/test/variables/class.const.ts index 9cc98c59..0d152fac 100644 --- a/packages/type/src/is/test/variables/class.const.ts +++ b/packages/type/src/is/test/variables/class.const.ts @@ -1,4 +1,6 @@ import { STRING } from './string.const'; +import { NUMBER } from './number.const'; +import { SYMBOL_STRING, SYMBOL_NUMBER } from './symbol.const'; /** * typeof === 'function' @@ -7,8 +9,30 @@ import { STRING } from './string.const'; * instanceof Object === true */ export class Class { - x = 5; + + 1030405027 = 'my new number'; + 5 = 'my number'; + + firstName = 'My name'; + surname = 'Surname'; + + x = NUMBER; y = STRING; + + get [NUMBER](): number { + return this.x; + } + get [STRING](): string { + return this.y; + } + + get [SYMBOL_NUMBER](): number { + return this.x; + } + + get [SYMBOL_STRING](): string { + return this.y; + } } /** From dd4ede9116c2aea7f0ef3babf43b5f25c11ed9c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 23 Apr 2021 18:31:36 +0200 Subject: [PATCH 060/201] chore: use constant to create number instance --- packages/type/src/is/test/variables/number.const.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/type/src/is/test/variables/number.const.ts b/packages/type/src/is/test/variables/number.const.ts index e1119823..eccb1374 100644 --- a/packages/type/src/is/test/variables/number.const.ts +++ b/packages/type/src/is/test/variables/number.const.ts @@ -17,7 +17,7 @@ export const NUMBER: any = 10304050; * instanceof Number === false * instanceof Object === false */ -export const NUMBER_INSTANCE: any = Number(10304050); +export const NUMBER_INSTANCE: any = Number(NUMBER); /** * typeof === 'number' @@ -25,4 +25,4 @@ export const NUMBER_INSTANCE: any = Number(10304050); * instanceof Number === true * instanceof Object === true */ -export const NUMBER_NEW_INSTANCE: any = new Number(10304050); +export const NUMBER_NEW_INSTANCE: any = new Number(NUMBER); From 109fa1cfb04fed944a2f4998eacf66723b68efca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 23 Apr 2021 18:42:12 +0200 Subject: [PATCH 061/201] chore(OBJECT_ONE): add properties Added - property key as number - property key as string - property key as symbol number - property key as symbol string --- .../src/is/test/variables/object.const.ts | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/type/src/is/test/variables/object.const.ts b/packages/type/src/is/test/variables/object.const.ts index 7cf76366..3088398c 100644 --- a/packages/type/src/is/test/variables/object.const.ts +++ b/packages/type/src/is/test/variables/object.const.ts @@ -1,4 +1,14 @@ -export interface ObjectOne { x: number; } +import { SYMBOL_NUMBER, SYMBOL_STRING } from './symbol.const'; +import { STRING } from './string.const'; +import { NUMBER } from './number.const'; +export interface ObjectOne { + 'key as string'?: boolean; + 1030405027?: string; + 5?: string; + [SYMBOL_NUMBER]?: string; + [SYMBOL_STRING]?: number; + x: number; +} export interface ObjectTwo { x: string; y: number; } /** * @example https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects @@ -12,7 +22,16 @@ export interface ObjectTwo { x: string; y: number; } * instanceof String === false * instanceof Symbol === false */ -export const OBJECT_ONE: ObjectOne = { x: 3000 }; +export const OBJECT_ONE: ObjectOne = { + 'key as string': true, + 1030405027: 'key is number', + 5: 'key is also number', + [NUMBER]: 'key is number', + [STRING]: 'key is string', + [SYMBOL_NUMBER]: 'key is symbol number', + [SYMBOL_STRING]: 6, + x: 3000 +}; /** * typeof === 'object' From 2921caeaf5dd9ff2dc12d79a2ec25d575abf20f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 23 Apr 2021 18:42:51 +0200 Subject: [PATCH 062/201] chore: change type from any to unique symbol --- packages/type/src/is/test/variables/symbol.const.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/type/src/is/test/variables/symbol.const.ts b/packages/type/src/is/test/variables/symbol.const.ts index 40ba9a8b..72ba6f5c 100644 --- a/packages/type/src/is/test/variables/symbol.const.ts +++ b/packages/type/src/is/test/variables/symbol.const.ts @@ -13,5 +13,5 @@ import { STRING } from './string.const'; * instanceof String === false * instanceof Symbol === false */ -export const SYMBOL_NUMBER: any = Symbol(NUMBER); -export const SYMBOL_STRING: any = Symbol(STRING); +export const SYMBOL_NUMBER: unique symbol = Symbol(NUMBER); +export const SYMBOL_STRING: unique symbol = Symbol(STRING); From 8ae31f4d83951447fe5f43c0d22c0b9bdc674290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 23 Apr 2021 18:45:46 +0200 Subject: [PATCH 063/201] test(isObjectKey): add --- README.md | 55 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 2caab274..c3b77a3b 100644 --- a/README.md +++ b/README.md @@ -498,7 +498,7 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` ### isObject -Use `isObject()` or `is.object()` to check if **any** `value` is a generic `Obj` `object` type and `Object` instance with the possibility of containing `key`. +Use `isObject()` or `is.object()` to check if **any** `value` is a generic `Obj` `object` type and `Object` instance with the possibility of containing the `key`. ```typescript const isObject: IsObject = (value: any, key?: Key): value is Obj => @@ -509,10 +509,10 @@ const isObject: IsObject = (value: any, key?: Key): value is Obj = : false; ``` -| Parameter | Type | Description | -| :-------- | :------: | :---------- | -| value | `any` | Any `value` to check | -| key? | `Key` | Property name to find in `value` | +| Parameter | Type | Description | +| :-------- | :-----------: | :---------- | +| value | `any` | Any `value` to check | +| key? | [`Key`](#Key) | Property name to find in `value` | The **return value** is a `boolean` indicating whether or not the `value` is an `object`. @@ -553,6 +553,7 @@ const isPrimitive: IsPrimitive = (value: any, type: Primitives): value is case 'bigint': return isBigInt(value); case 'boolean': return isBoolean(value); case 'number': return isNumber(value); + case 'null': return isNull(value); case 'string': return isString(value); case 'symbol': return isSymbol(value); case 'undefined': return isUndefined(value); @@ -565,7 +566,7 @@ const isPrimitive: IsPrimitive = (value: any, type: Primitives): value is | Parameter | Type | Description | | :-------- | :-------------------------: | :---------- | | value | `any` | Any `value` to check if it's a generic `Type` from the `type` | -| type | [`Primitives`](#Primitives) | Type from the [`Primitives`](#Primitives) to check the `value` | +| type | [`Primitives`](#Primitives) | Name of the type from the [`Primitives`](#Primitives) to check the `value` | The **return value** is a `boolean` indicating whether or not the `value` is a type from the [`Primitives`](#Primitives). @@ -584,7 +585,7 @@ const isString: IsString = (value: any, callback: ResultCallback = errorCallback | Parameter | Type | Description | | :-------- | :---------------------------------: | :---------- | -| value | `any` | Any value to check | +| value | `any` | Any `value` to check | | callback | [`ResultCallback`](#ResultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before return eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `string`. @@ -600,7 +601,7 @@ Use `isSymbol()` or `is.symbol()` to check if **any** `value` is a `symbol` type ```typescript const isSymbol: IsSymbol = (value: any): value is symbol => typeOf(value) === 'symbol' && - typeof value === 'symbol';s + typeof value === 'symbol'; ``` | Parameter | Type | Description | @@ -621,24 +622,30 @@ Use `isType()` or `is.type()` to check if **any** `value` is a generic `Type` fr const isType: IsType = (value: any, type: Types): value is Type => { if (isString(type)) { switch (type) { - case 'bigint': return isBigInt(value); - case 'boolean': return isBoolean(value); + // Primitives. + case 'bigint': + case 'boolean': + case 'number': + case 'null' : + case 'string': + case 'symbol': + case 'undefined': return isPrimitive(value, type); + // Function. case 'function': return isFunction(value); - case 'number': return isNumber(value); + // Object. case 'object': return isObject(value); - case 'string': return isString(value); - case 'symbol': return isSymbol(value); - case 'undefined': return isUndefined(value); } + } else if (isNotNull(type)) { + return isInstance(value, type); } - return type ? isInstance(value, type) : false; + return false; }; ``` -| Parameter | Type | Description | -| :-------- | :-----------: | :---------- | -| value | `any` | Any `value` to check if its type is from the `type` | -| type | `Types` | One from the `Types` to check the `value` | +| Parameter | Type | Description | +| :-------- | :---------------------: | :---------- | +| value | `any` | Any `value` to check if its type is from the `type` | +| type | [`Types`](#Types) | One type from the `Types` to check the `value` | The **return value** is a `boolean` indicating whether or not the `value` is a type from the [`Types`](#Types). @@ -669,7 +676,7 @@ The **return value** is a `boolean` indicating whether or not the `value` is `un ### isNotBoolean -Use `isNotBoolean()` or `is.not.boolean()` to check if an **unknown** `value` is NOT a `'boolean'` type, NOT equal to `true` or `false` and NOT an instance of a `Boolean`. +Use `isNotBoolean()` or `is.not.boolean()` to check if an **unknown** `value` is NOT a `boolean` type, NOT equal to `true` or `false` and NOT an instance of a `Boolean`. ```typescript const isNotBoolean: IsNotBoolean = (value: unknown): boolean => @@ -907,7 +914,7 @@ const guardString: GuardString = (value: string): value is string => isString(va ### guardType -Use `guardType()` or `guard.is.type()` to guard the `value` to be a generic `Type` type from one of the `Types` type. The return value is a `boolean` value. +Use `guardType()` or `guard.is.type()` to guard the `value` to be a generic `Type` type from the `Types` type. ```typescript const guardType: GuardType = (value: Type, type: Types): value is Type => isType(value, type); @@ -918,7 +925,9 @@ const guardType: GuardType = (value: Type, type: Types): value is Ty | value | `Type` | A generic `Type` `value` to guard. | | type | `Types` | Constructor generic `Type`, `'function'`, `'object'` or one of the `Primitives` `'boolean'`, `'bigint'`, `'number'`, `'string'`, `'symbol'`, `'undefined'` to check `value`. | -[Example usage][guard-type] +The return value is a `boolean` value. + +[Example usage on playground][guard-type] ## Common Types @@ -956,7 +965,7 @@ type Primitive = bigint | boolean | null | number | string | symbol | undefined; ### Primitives ```typescript -type Primitives = 'bigint' | 'boolean' | 'number' | 'string' | 'symbol' | 'undefined'; +type Primitives = 'bigint' | 'boolean' | 'null' | 'number' | 'symbol' | 'string' | 'undefined'; ``` ### ResultCallback From 899d9485fda7d6705a114056e1983fb3e0f317de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 23 Apr 2021 18:46:14 +0200 Subject: [PATCH 064/201] test(isString): simplify names --- packages/type/src/is/test/is-string.spec.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/type/src/is/test/is-string.spec.ts b/packages/type/src/is/test/is-string.spec.ts index 3d154b81..37b67709 100644 --- a/packages/type/src/is/test/is-string.spec.ts +++ b/packages/type/src/is/test/is-string.spec.ts @@ -30,16 +30,16 @@ describe(`isString`, () => { }); // ... function. describe(`function`, () => { - it(`${FUNCTION}`, () => expect(isString(FUNCTION)).toBe(FALSE)); - it(`${Class}`, () => expect(isString(Class)).toBe(FALSE)); + it(`FUNCTION`, () => expect(isString(FUNCTION)).toBe(FALSE)); + it(`Class`, () => expect(isString(Class)).toBe(FALSE)); }); // ... objects. describe('object', () => { - it(`${JSON.stringify(CLASS)}`, () => expect(isString(CLASS)).toBe(FALSE)); - it(`${JSON.stringify(OBJECT_ONE)}`, () => expect(isString(OBJECT_ONE)).toBe(FALSE)); - it(`${JSON.stringify(OBJECT_TWO)}`, () => expect(isString(OBJECT_TWO)).toBe(FALSE)); - it(`new Object(${JSON.stringify(OBJECT_ONE_NEW)})`, () => expect(isString(OBJECT_ONE_NEW)).toBe(FALSE)); - it(`new Object(${JSON.stringify(OBJECT_TWO_NEW)})`, () => expect(isString(OBJECT_TWO_NEW)).toBe(FALSE)); + it(`CLASS`, () => expect(isString(CLASS)).toBe(FALSE)); + it(`OBJECT_ONE`, () => expect(isString(OBJECT_ONE)).toBe(FALSE)); + it(`OBJECT_TWO`, () => expect(isString(OBJECT_TWO)).toBe(FALSE)); + it(`new Object(OBJECT_ONE_NEW})`, () => expect(isString(OBJECT_ONE_NEW)).toBe(FALSE)); + it(`new Object(OBJECT_TWO_NEW})`, () => expect(isString(OBJECT_TWO_NEW)).toBe(FALSE)); }); // ... primitives. describe(`primitive`, () => { From 638bc1a27d916add24ede45a0dfd2499eb8c779b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 23 Apr 2021 18:46:27 +0200 Subject: [PATCH 065/201] test(isType): simplify names --- packages/type/src/is/test/is-type.spec.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/type/src/is/test/is-type.spec.ts b/packages/type/src/is/test/is-type.spec.ts index 4b587dc2..eaf903ff 100644 --- a/packages/type/src/is/test/is-type.spec.ts +++ b/packages/type/src/is/test/is-type.spec.ts @@ -19,7 +19,7 @@ describe(`isType`, () => { // Checks ... describe(`checks`, () => { // ... instance. - describe(`instance`, () => it(`${Class}`, () => expect(isType(CLASS, Class)).toBe(TRUE))); + describe(`instance`, () => it(`Class`, () => expect(isType(CLASS, Class)).toBe(TRUE))); // ... function. describe(`function`, () => { @@ -29,11 +29,11 @@ describe(`isType`, () => { // ... objects. describe('object', () => { - it(`${JSON.stringify(CLASS)}`, () => expect(isType(CLASS, 'object')).toBe(TRUE)); - it(`${JSON.stringify(OBJECT_ONE)}`, () => expect(isType(OBJECT_ONE, 'object')).toBe(TRUE)); - it(`${JSON.stringify(OBJECT_TWO)}`, () => expect(isType(OBJECT_TWO, 'object')).toBe(TRUE)); - it(`new Object(${JSON.stringify(OBJECT_ONE_NEW)})`, () => expect(isType(OBJECT_ONE_NEW, 'object')).toBe(TRUE)); - it(`new Object(${JSON.stringify(OBJECT_TWO_NEW)})`, () => expect(isType(OBJECT_TWO_NEW, 'object')).toBe(TRUE)); + it(`CLASS`, () => expect(isType(CLASS, 'object')).toBe(TRUE)); + it(`OBJECT_ONE`, () => expect(isType(OBJECT_ONE, 'object')).toBe(TRUE)); + it(`OBJECT_ONE_NEW`, () => expect(isType(OBJECT_TWO, 'object')).toBe(TRUE)); + it(`new Object(OBJECT_ONE_NEW)`, () => expect(isType(OBJECT_ONE_NEW, 'object')).toBe(TRUE)); + it(`new Object(OBJECT_TWO_NEW)`, () => expect(isType(OBJECT_TWO_NEW, 'object')).toBe(TRUE)); }); // ... primitives. From 91775498b21252da2f35b10f2b915a9c54a0260e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 23 Apr 2021 18:54:40 +0200 Subject: [PATCH 066/201] test(isObjectKey): add --- .../type/src/is/test/is-object-key.spec.ts | 141 ++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 packages/type/src/is/test/is-object-key.spec.ts diff --git a/packages/type/src/is/test/is-object-key.spec.ts b/packages/type/src/is/test/is-object-key.spec.ts new file mode 100644 index 00000000..b19e5197 --- /dev/null +++ b/packages/type/src/is/test/is-object-key.spec.ts @@ -0,0 +1,141 @@ +// Function. +import { isObjectKey } from '../lib/is-object-key.func'; +// Variables. +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from './variables/big-int.const'; +import { Class, CLASS } from './variables/class.const'; +import { FALSE, TRUE, TRUE_INSTANCE, FALSE_INSTANCE, FALSE_EXPECTATION, TRUE_EXPECTATION } from './variables/boolean.const'; +import { FUNCTION } from './variables/function.const'; +import { NULL } from './variables/null.const'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; +import { OBJECT_ONE, OBJECT_TWO, OBJECT_ONE_NEW, OBJECT_TWO_NEW, ObjectTwo, ObjectOne } from './variables/object.const'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; +import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; +import { UNDEFINED } from './variables/undefined.const'; + +describe(`isObjectKey`, () => { + // Defined. + it('is DEFINED', () => expect(isObjectKey).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + // ... instance. + describe(`instance`, () => { + describe(`CLASS`, () => { + // number. + it('has number key', () => { + expect(isObjectKey(CLASS, 1030405027)).toBe(TRUE); + expect(isObjectKey(CLASS, 5)).toBe(TRUE); + expect(isObjectKey(CLASS, NUMBER)).toBe(FALSE); // It doesn't find getter + expect(isObjectKey(CLASS, [5, 1030405027])).toBe(TRUE); + }); + + // string. + it('has string key', () => { + expect(isObjectKey(CLASS, 'surname')).toBe(TRUE); + expect(isObjectKey(CLASS, ['firstName', 'surname'])).toBe(TRUE); + }); + + // symbol. + it('has symbol key', () => { + expect(isObjectKey(CLASS, SYMBOL_NUMBER)).toBe(FALSE); + expect(isObjectKey(CLASS, SYMBOL_STRING)).toBe(FALSE); + expect(isObjectKey(CLASS, [SYMBOL_NUMBER, SYMBOL_STRING])).toBe(FALSE); + }); + + // mixed. + it('has string and number key', () => expect(isObjectKey(CLASS, [1030405027, 'firstName', 'surname'])).toBe(TRUE)); + }); + }); + + // ... function. + describe(`function`, () => { + it(`FUNCTION`, () => expect(isObjectKey(FUNCTION, 'function')).toBe(FALSE)); + it(`CLASS`, () => expect(isObjectKey(Class, 'function')).toBe(FALSE)); + }); + + // ... objects. + describe('object', () => { + describe(`OBJECT_ONE`, () => { + // number. + it('has number key', () => { + expect(isObjectKey(OBJECT_ONE, 1030405027)).toBe(TRUE); + expect(isObjectKey(OBJECT_ONE, 5)).toBe(TRUE); + expect(isObjectKey(OBJECT_ONE, NUMBER)).toBe(TRUE); // It doesn't find getter + expect(isObjectKey(OBJECT_ONE, [5, 1030405027])).toBe(TRUE); + }); + + // string. + it('has string key', () => { + expect(isObjectKey(OBJECT_ONE, 'key as string')).toBe(TRUE); + expect(isObjectKey(OBJECT_ONE, 'x')).toBe(TRUE); + expect(isObjectKey(OBJECT_ONE, STRING)).toBe(TRUE); + expect(isObjectKey(OBJECT_ONE, ['key as string', 'x', STRING])).toBe(TRUE); + }); + + // symbol. + it('has symbol key', () => { + expect(isObjectKey(OBJECT_ONE, SYMBOL_NUMBER)).toBe(TRUE); + expect(isObjectKey(OBJECT_ONE, SYMBOL_STRING)).toBe(TRUE); + expect(isObjectKey(OBJECT_ONE, [SYMBOL_NUMBER, SYMBOL_STRING])).toBe(TRUE); + }); + + // mixed. + it('has mixed key', () => { + expect(isObjectKey(OBJECT_ONE, [ + 'key as string', + 'x', + 1030405027, + 5, + NUMBER, + STRING, + SYMBOL_NUMBER, + SYMBOL_STRING, + ])).toBe(TRUE); + }); + }); + }); + + // ... primitives. + describe(`primitive`, () => { + // bigint + describe(`bigint`, () => { + it(`${BIGINT}`, () => expect(isObjectKey(BIGINT, 'bigint')).toBe(FALSE)); + it(`${BIGINT_EXPECTATION}`, () => expect(isObjectKey(BIGINT_INSTANCE, 'bigint')).toBe(FALSE)); + }); + + // boolean + describe(`boolean`, () => { + it(`${TRUE}`, () => expect(isObjectKey(TRUE, 'boolean')).toBe(FALSE)); + it(`${FALSE}`, () => expect(isObjectKey(FALSE, 'boolean')).toBe(FALSE)); + it(`${FALSE_EXPECTATION}`, () => expect(isObjectKey(TRUE_INSTANCE, 'boolean')).toBe(FALSE)); + it(`${TRUE_EXPECTATION}`, () => expect(isObjectKey(FALSE_INSTANCE, 'boolean')).toBe(FALSE)); + }); + + // null + it(`${NULL}`, () => expect(isObjectKey(NULL, 'null')).toBe(FALSE)); + + // number + describe(`number`, () => { + it(`${NUMBER}`, () => expect(isObjectKey(NUMBER, 'number')).toBe(FALSE)); + it(`Number(${NUMBER})`, () => expect(isObjectKey(NUMBER_INSTANCE, 'number')).toBe(FALSE)); + it(`new Number(${NUMBER})`, () => expect(isObjectKey(NUMBER_NEW_INSTANCE, 'number')).toBe(FALSE)); + }); + + // string + describe(`string`, () => { + it(`${STRING}`, () => expect(isObjectKey(STRING, 'string')).toBe(FALSE)); + it(`String(${STRING})`, () => expect(isObjectKey(STRING_INSTANCE, 'string')).toBe(FALSE)); + it(`new String(${STRING})`, () => expect(isObjectKey(STRING_NEW_INSTANCE, 'string')).toBe(FALSE)); + }); + + // symbol + describe(`symbol`, () => { + it(`Symbol(${NUMBER})`, () => expect(isObjectKey(SYMBOL_NUMBER, 'symbol')).toBe(FALSE)); + it(`Symbol(${STRING})`, () => expect(isObjectKey(SYMBOL_STRING, 'symbol')).toBe(FALSE)); + }); + + // undefined + it(`${UNDEFINED}`, () => expect(isObjectKey(UNDEFINED, 'undefined')).toBe(FALSE)); + }); + }); +}); From 0fb76c3b8db23d4b0e25218952f98507db1042bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 25 Apr 2021 18:31:44 +0200 Subject: [PATCH 067/201] refactor(isBooleanObject): update - add `IsBooleanObject` type - use `callback` param with default `errorCallback` - add jsdoc --- .../type/src/is/lib/is-boolean-object.func.ts | 19 +++++++++++++++---- .../src/is/type/is-boolean-object.type.ts | 2 ++ 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 packages/type/src/is/type/is-boolean-object.type.ts diff --git a/packages/type/src/is/lib/is-boolean-object.func.ts b/packages/type/src/is/lib/is-boolean-object.func.ts index 32f0ab9e..e4151916 100644 --- a/packages/type/src/is/lib/is-boolean-object.func.ts +++ b/packages/type/src/is/lib/is-boolean-object.func.ts @@ -1,4 +1,15 @@ -export const isBooleanObject = (value: any) => - typeof value === 'object' && - value instanceof Boolean === true && - value instanceof Object === true; +// Function. +import { errorCallback } from '../../lib/error-callback.func'; +// Type. +import { IsBooleanObject } from '../type/is-boolean-object.type'; +import { ResultCallback } from '../../type/result-callback.type'; +/** + * Checks if any `value` is an `object` type and instance of `Boolean` and `Object`. + * @function `isBooleanObject` + * @param value Any `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `errorCallback`. + * @returns A `boolean` indicating whether or not the `value` is a `Boolean` instance. + */ +export const isBooleanObject: IsBooleanObject = (value: any, callback: ResultCallback = errorCallback): value is boolean => + callback(typeof value === 'object' && value instanceof Boolean === true && value instanceof Object === true); diff --git a/packages/type/src/is/type/is-boolean-object.type.ts b/packages/type/src/is/type/is-boolean-object.type.ts new file mode 100644 index 00000000..6a7068cb --- /dev/null +++ b/packages/type/src/is/type/is-boolean-object.type.ts @@ -0,0 +1,2 @@ +import { ResultCallback } from '../../type/result-callback.type'; +export type IsBooleanObject = (value: any, callback?: ResultCallback) => value is boolean; From fc9c17477b76edd6f92e226b4d27eb34eae27919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 25 Apr 2021 18:32:23 +0200 Subject: [PATCH 068/201] test(isBooleanObject): add --- .../src/is/test/is-boolean-object.spec.ts | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 packages/type/src/is/test/is-boolean-object.spec.ts diff --git a/packages/type/src/is/test/is-boolean-object.spec.ts b/packages/type/src/is/test/is-boolean-object.spec.ts new file mode 100644 index 00000000..9b120e1b --- /dev/null +++ b/packages/type/src/is/test/is-boolean-object.spec.ts @@ -0,0 +1,71 @@ +// Function. +import { isBooleanObject } from '../lib/is-boolean-object.func'; +// Variables. +import { BIGINT, BIGINT_INSTANCE } from './variables/big-int.const'; +import { Class, CLASS } from './variables/class.const'; +import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; +import { FUNCTION } from './variables/function.const'; +import { NULL } from './variables/null.const'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; +import { OBJECT_ONE, OBJECT_TWO } from './variables/object.const'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; +import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; +import { UNDEFINED } from './variables/undefined.const'; +import { notDefined } from './variables/not-defined.const'; +/** + * Checks + * ✓ typeof === 'object' + * ✓ instanceof Object + * ✓ instanceof Boolean + */ +describe('isBooleanObject', () => { + // TRUE + it('is DEFINED', () => expect(isBooleanObject).toBeDefined()); + it(`Boolean`, () => { + expect(isBooleanObject(FALSE_INSTANCE)).toBe(TRUE); + expect(isBooleanObject(TRUE_INSTANCE)).toBe(TRUE); + }); + + // FALSE + it(`boolean`, () => { + expect(isBooleanObject(FALSE)).toBe(FALSE); + expect(isBooleanObject(TRUE)).toBe(FALSE); + expect(isBooleanObject(Boolean(false))).toBe(FALSE); + expect(isBooleanObject(Boolean(true))).toBe(FALSE); + }); + it(`'bigint'`, () => { + expect(isBooleanObject(BIGINT)).toBe(FALSE); + expect(isBooleanObject(BIGINT_INSTANCE)).toBe(FALSE); + }); + it(`Class | CLASS`, () => { + expect(isBooleanObject(Class)).toBe(FALSE); + expect(isBooleanObject(CLASS)).toBe(FALSE); + }); + it(`'function' | Function`, () => expect(isBooleanObject(FUNCTION)).toBe(FALSE)); + it(`null | NULL`, () => { + expect(isBooleanObject(null)).toBe(FALSE); + expect(isBooleanObject(NULL)).toBe(FALSE); + }); + it(`'number' | Number`, () => { + expect(isBooleanObject(NUMBER)).toBe(FALSE); + expect(isBooleanObject(NUMBER_INSTANCE)).toBe(FALSE); + expect(isBooleanObject(NUMBER_NEW_INSTANCE)).toBe(FALSE); + }); + it(`'object' | Object`, () => { + expect(isBooleanObject(OBJECT_ONE)).toBe(FALSE); + expect(isBooleanObject(OBJECT_TWO)).toBe(FALSE); + }); + it(`'string' | String`, () => { + expect(isBooleanObject(STRING)).toBe(FALSE); + expect(isBooleanObject(STRING_INSTANCE)).toBe(FALSE); + expect(isBooleanObject(STRING_NEW_INSTANCE)).toBe(FALSE); + }); + it(`'symbol'`, () => { + expect(isBooleanObject(SYMBOL_NUMBER)).toBe(FALSE); + expect(isBooleanObject(SYMBOL_STRING)).toBe(FALSE); + }); + it(`'undefined'`, () => { + expect(isBooleanObject(notDefined)).toBe(FALSE); + expect(isBooleanObject(UNDEFINED)).toBe(FALSE); + }); +}); From 8e0c1867f1a608891e79fb17258cd826bedc5b79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 25 Apr 2021 18:38:02 +0200 Subject: [PATCH 069/201] refactor(isBooleanType): update - add `IsBooleanType` - add `ResultCallback` parameter `callback` as `errorCallback` by default - add jsdoc --- .../type/src/is/lib/is-boolean-type.func.ts | 25 +++++++++++++++---- .../type/src/is/type/is-boolean-type.type.ts | 2 ++ 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 packages/type/src/is/type/is-boolean-type.type.ts diff --git a/packages/type/src/is/lib/is-boolean-type.func.ts b/packages/type/src/is/lib/is-boolean-type.func.ts index a638eab9..d2cb0069 100644 --- a/packages/type/src/is/lib/is-boolean-type.func.ts +++ b/packages/type/src/is/lib/is-boolean-type.func.ts @@ -1,5 +1,20 @@ -export const isBooleanType = (value: any) => - value instanceof Boolean === false && - value instanceof Object === false && - typeof value === 'boolean' && - (value === true || value === false); +// Function. +import { errorCallback } from '../../lib/error-callback.func'; +// Type. +import { IsBooleanType } from '../type/is-boolean-type.type'; +import { ResultCallback } from '../../type/result-callback.type'; +/** + * Checks if any `value` is a `boolean` type not an instance of `Boolean` and `Object`, and equal to `true` or `false`. + * @function `isBooleanType` + * @param value Any `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `errorCallback`. + * @returns A `boolean` indicating whether or not the `value` is a `boolean` type. + */ +export const isBooleanType: IsBooleanType = (value: any, callback: ResultCallback = errorCallback): value is boolean => + callback( + value instanceof Boolean === false && + value instanceof Object === false && + typeof value === 'boolean' && + (value === true || value === false) + ); diff --git a/packages/type/src/is/type/is-boolean-type.type.ts b/packages/type/src/is/type/is-boolean-type.type.ts new file mode 100644 index 00000000..66b74f80 --- /dev/null +++ b/packages/type/src/is/type/is-boolean-type.type.ts @@ -0,0 +1,2 @@ +import { ResultCallback } from '../../type/result-callback.type'; +export type IsBooleanType = (value: any, callback?: ResultCallback) => value is boolean; From fbe2effe512b1a2f3fadd289af674512ac36b418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 25 Apr 2021 18:39:39 +0200 Subject: [PATCH 070/201] refactor(IsBoolean): add `callback` --- packages/type/src/is/type/is-boolean.type.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/type/src/is/type/is-boolean.type.ts b/packages/type/src/is/type/is-boolean.type.ts index 544d315c..1a7dc6fb 100644 --- a/packages/type/src/is/type/is-boolean.type.ts +++ b/packages/type/src/is/type/is-boolean.type.ts @@ -1 +1,2 @@ -export type IsBoolean = (value: any) => value is boolean; +import { ResultCallback } from '../../type/result-callback.type'; +export type IsBoolean = (value: any, callback?: ResultCallback) => value is boolean; From 0c4cbb35b144d029fa0ae15a52ee8cf54fc1e57e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 25 Apr 2021 18:40:01 +0200 Subject: [PATCH 071/201] chore: add types --- packages/type/src/is/type/is-number-object.type.ts | 2 ++ packages/type/src/is/type/is-number-type.type.ts | 2 ++ packages/type/src/is/type/is-string-object.type.ts | 2 ++ packages/type/src/is/type/is-string-type.type.ts | 2 ++ 4 files changed, 8 insertions(+) create mode 100644 packages/type/src/is/type/is-number-object.type.ts create mode 100644 packages/type/src/is/type/is-number-type.type.ts create mode 100644 packages/type/src/is/type/is-string-object.type.ts create mode 100644 packages/type/src/is/type/is-string-type.type.ts diff --git a/packages/type/src/is/type/is-number-object.type.ts b/packages/type/src/is/type/is-number-object.type.ts new file mode 100644 index 00000000..9e894dd1 --- /dev/null +++ b/packages/type/src/is/type/is-number-object.type.ts @@ -0,0 +1,2 @@ +import { ResultCallback } from '../../type/result-callback.type'; +export type IsNumberObject = (value: any, callback?: ResultCallback) => value is number; diff --git a/packages/type/src/is/type/is-number-type.type.ts b/packages/type/src/is/type/is-number-type.type.ts new file mode 100644 index 00000000..ed9df0db --- /dev/null +++ b/packages/type/src/is/type/is-number-type.type.ts @@ -0,0 +1,2 @@ +import { ResultCallback } from '../../type/result-callback.type'; +export type IsNumberType = (value: any, callback?: ResultCallback) => value is number; diff --git a/packages/type/src/is/type/is-string-object.type.ts b/packages/type/src/is/type/is-string-object.type.ts new file mode 100644 index 00000000..62019501 --- /dev/null +++ b/packages/type/src/is/type/is-string-object.type.ts @@ -0,0 +1,2 @@ +import { ResultCallback } from '../../type/result-callback.type'; +export type IsStringObject = (value: any, callback?: ResultCallback) => value is string; diff --git a/packages/type/src/is/type/is-string-type.type.ts b/packages/type/src/is/type/is-string-type.type.ts new file mode 100644 index 00000000..bf8b4e4e --- /dev/null +++ b/packages/type/src/is/type/is-string-type.type.ts @@ -0,0 +1,2 @@ +import { ResultCallback } from '../../type/result-callback.type'; +export type IsStringType = (value: any, callback?: ResultCallback) => value is string; From 503b4094eddece7d7f164061866e7589b37d9ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 25 Apr 2021 18:40:20 +0200 Subject: [PATCH 072/201] test(isBoolean): update --- packages/type/src/is/test/is-boolean.spec.ts | 52 ++++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/packages/type/src/is/test/is-boolean.spec.ts b/packages/type/src/is/test/is-boolean.spec.ts index a019d6be..461976a3 100644 --- a/packages/type/src/is/test/is-boolean.spec.ts +++ b/packages/type/src/is/test/is-boolean.spec.ts @@ -23,50 +23,48 @@ describe('isBoolean', () => { expect(isBoolean).toBeDefined(); }); it(`'boolean' | Boolean`, () => { - expect(isBoolean(FALSE)).toBeTruthy(); - expect(isBoolean(TRUE)).toBeTruthy(); - expect(isBoolean(FALSE_INSTANCE)).toBeTruthy(); - expect(isBoolean(TRUE_INSTANCE)).toBeTruthy(); - expect(isBoolean(Boolean(false))).toBeTruthy(); - expect(isBoolean(Boolean(true))).toBeTruthy(); + expect(isBoolean(FALSE)).toBe(TRUE); + expect(isBoolean(TRUE)).toBe(TRUE); + expect(isBoolean(FALSE_INSTANCE)).toBe(TRUE); + expect(isBoolean(TRUE_INSTANCE)).toBe(TRUE); + expect(isBoolean(Boolean(false))).toBe(TRUE); + expect(isBoolean(Boolean(true))).toBe(TRUE); }); // FALSE it(`'bigint'`, () => { - expect(isBoolean(BIGINT)).toBeFalsy(); - expect(isBoolean(BIGINT_INSTANCE)).toBeFalsy(); + expect(isBoolean(BIGINT)).toBe(FALSE); + expect(isBoolean(BIGINT_INSTANCE)).toBe(FALSE); }); it(`Class | CLASS`, () => { - expect(isBoolean(Class)).toBeFalsy(); - expect(isBoolean(CLASS)).toBeFalsy(); - }); - it(`'function' | Function`, () => { - expect(isBoolean(FUNCTION)).toBeFalsy(); + expect(isBoolean(Class)).toBe(FALSE); + expect(isBoolean(CLASS)).toBe(FALSE); }); + it(`'function' | Function`, () => expect(isBoolean(FUNCTION)).toBe(FALSE)); it(`null | NULL`, () => { - expect(isBoolean(null)).toBeFalsy(); - expect(isBoolean(NULL)).toBeFalsy(); + expect(isBoolean(null)).toBe(FALSE); + expect(isBoolean(NULL)).toBe(FALSE); }); it(`'number' | Number`, () => { - expect(isBoolean(NUMBER)).toBeFalsy(); - expect(isBoolean(NUMBER_INSTANCE)).toBeFalsy(); - expect(isBoolean(NUMBER_NEW_INSTANCE)).toBeFalsy(); + expect(isBoolean(NUMBER)).toBe(FALSE); + expect(isBoolean(NUMBER_INSTANCE)).toBe(FALSE); + expect(isBoolean(NUMBER_NEW_INSTANCE)).toBe(FALSE); }); it(`'object' | Object`, () => { - expect(isBoolean(OBJECT_ONE)).toBeFalsy(); - expect(isBoolean(OBJECT_TWO)).toBeFalsy(); + expect(isBoolean(OBJECT_ONE)).toBe(FALSE); + expect(isBoolean(OBJECT_TWO)).toBe(FALSE); }); it(`'string' | String`, () => { - expect(isBoolean(STRING)).toBeFalsy(); - expect(isBoolean(STRING_INSTANCE)).toBeFalsy(); - expect(isBoolean(STRING_NEW_INSTANCE)).toBeFalsy(); + expect(isBoolean(STRING)).toBe(FALSE); + expect(isBoolean(STRING_INSTANCE)).toBe(FALSE); + expect(isBoolean(STRING_NEW_INSTANCE)).toBe(FALSE); }); it(`'symbol'`, () => { - expect(isBoolean(SYMBOL_NUMBER)).toBeFalsy(); - expect(isBoolean(SYMBOL_STRING)).toBeFalsy(); + expect(isBoolean(SYMBOL_NUMBER)).toBe(FALSE); + expect(isBoolean(SYMBOL_STRING)).toBe(FALSE); }); it(`'undefined'`, () => { - expect(isBoolean(notDefined)).toBeFalse(); - expect(isBoolean(UNDEFINED)).toBeFalse(); + expect(isBoolean(notDefined)).toBe(FALSE); + expect(isBoolean(UNDEFINED)).toBe(FALSE); }); }); From 816f6fbbb68f764617716b810b5d9d5f6e02d100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 25 Apr 2021 18:40:33 +0200 Subject: [PATCH 073/201] test(isBooleanType): add --- .../type/src/is/test/is-boolean-type.spec.ts | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 packages/type/src/is/test/is-boolean-type.spec.ts diff --git a/packages/type/src/is/test/is-boolean-type.spec.ts b/packages/type/src/is/test/is-boolean-type.spec.ts new file mode 100644 index 00000000..44e459da --- /dev/null +++ b/packages/type/src/is/test/is-boolean-type.spec.ts @@ -0,0 +1,71 @@ +// Function. +import { isBooleanType } from '../lib/is-boolean-type.func'; +// Variables. +import { BIGINT, BIGINT_INSTANCE } from './variables/big-int.const'; +import { Class, CLASS } from './variables/class.const'; +import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; +import { FUNCTION } from './variables/function.const'; +import { NULL } from './variables/null.const'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; +import { OBJECT_ONE, OBJECT_TWO } from './variables/object.const'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; +import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; +import { UNDEFINED } from './variables/undefined.const'; +import { notDefined } from './variables/not-defined.const'; +/** + * Checks + * ✓ typeof === 'boolean' + * ✓ value === true + * ✓ value === false + */ +describe('isBooleanType', () => { + // TRUE + it('is DEFINED', () => expect(isBooleanType).toBeDefined()); + it(`boolean`, () => { + expect(isBooleanType(FALSE)).toBe(TRUE); + expect(isBooleanType(TRUE)).toBe(TRUE); + expect(isBooleanType(Boolean(false))).toBe(TRUE); + expect(isBooleanType(Boolean(true))).toBe(TRUE); + }); + + // FALSE + it(`Boolean`, () => { + expect(isBooleanType(FALSE_INSTANCE)).toBe(FALSE); + expect(isBooleanType(TRUE_INSTANCE)).toBe(FALSE); + }); + it(`'bigint'`, () => { + expect(isBooleanType(BIGINT)).toBe(FALSE); + expect(isBooleanType(BIGINT_INSTANCE)).toBe(FALSE); + }); + it(`Class | CLASS`, () => { + expect(isBooleanType(Class)).toBe(FALSE); + expect(isBooleanType(CLASS)).toBe(FALSE); + }); + it(`'function' | Function`, () => expect(isBooleanType(FUNCTION)).toBe(FALSE)); + it(`null | NULL`, () => { + expect(isBooleanType(null)).toBe(FALSE); + expect(isBooleanType(NULL)).toBe(FALSE); + }); + it(`'number' | Number`, () => { + expect(isBooleanType(NUMBER)).toBe(FALSE); + expect(isBooleanType(NUMBER_INSTANCE)).toBe(FALSE); + expect(isBooleanType(NUMBER_NEW_INSTANCE)).toBe(FALSE); + }); + it(`'object' | Object`, () => { + expect(isBooleanType(OBJECT_ONE)).toBe(FALSE); + expect(isBooleanType(OBJECT_TWO)).toBe(FALSE); + }); + it(`'string' | String`, () => { + expect(isBooleanType(STRING)).toBe(FALSE); + expect(isBooleanType(STRING_INSTANCE)).toBe(FALSE); + expect(isBooleanType(STRING_NEW_INSTANCE)).toBe(FALSE); + }); + it(`'symbol'`, () => { + expect(isBooleanType(SYMBOL_NUMBER)).toBe(FALSE); + expect(isBooleanType(SYMBOL_STRING)).toBe(FALSE); + }); + it(`'undefined'`, () => { + expect(isBooleanType(notDefined)).toBe(FALSE); + expect(isBooleanType(UNDEFINED)).toBe(FALSE); + }); +}); From 20d7ba44da5b7c39bbcc69a2bbcaa9052baa148e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 25 Apr 2021 18:59:58 +0200 Subject: [PATCH 074/201] refactor(isBoolean): update - add `ResultCallback` parameter `callback` with default value `errorCallback` - set `isBooleanType` as first to check - add param `callback` to jsdoc --- packages/type/src/is/lib/is-boolean.func.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/type/src/is/lib/is-boolean.func.ts b/packages/type/src/is/lib/is-boolean.func.ts index 0ac122ec..517680ce 100644 --- a/packages/type/src/is/lib/is-boolean.func.ts +++ b/packages/type/src/is/lib/is-boolean.func.ts @@ -1,14 +1,17 @@ // Function. +import { errorCallback } from '../../lib/error-callback.func'; +import { isBooleanObject } from './is-boolean-object.func'; +import { isBooleanType } from './is-boolean-type.func'; import { typeOf } from '../../lib/type-of.func'; // Type. import { IsBoolean } from '../type/is-boolean.type'; -import { isBooleanObject } from './is-boolean-object.func'; -import { isBooleanType } from './is-boolean-type.func'; +import { ResultCallback } from '../../type/result-callback.type'; /** * Checks if any `value` is a `boolean` type not instance of `Boolean` and `Object` or `object` type instance of `Boolean` and `Object`. * @param value Any `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `errorCallback`. * @returns A `boolean` indicating whether or not the `value` is a `boolean`. */ -export const isBoolean: IsBoolean = (value: any): value is boolean => - typeOf(value) === 'boolean' && - (isBooleanObject(value) || isBooleanType(value)); +export const isBoolean: IsBoolean = (value: any, callback: ResultCallback = errorCallback): value is boolean => + callback(typeOf(value) === 'boolean' && (isBooleanType(value) || isBooleanObject(value))); From 23afa640169b9a3b226b118e3b55d1610507a29a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 25 Apr 2021 19:04:48 +0200 Subject: [PATCH 075/201] docs: update jsdoc --- packages/type/src/is/lib/is-key.func.ts | 2 +- packages/type/src/is/lib/is-object-key.func.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/type/src/is/lib/is-key.func.ts b/packages/type/src/is/lib/is-key.func.ts index bb92a4bf..2ea7fda6 100644 --- a/packages/type/src/is/lib/is-key.func.ts +++ b/packages/type/src/is/lib/is-key.func.ts @@ -6,7 +6,7 @@ import { isSymbol } from './is-symbol.func'; import { IsKey } from '../type/is-key.type'; import { Key } from '../../type/key.type'; /** - * Determines if any `value` is one of the `string`, `number`, or `symbol`. + * Checks if any `value` is one of the `string`, `number`, or `symbol`. * @param value Any `value` to check. * @returns A `boolean` indicating whether or not the `value` is a `Key` type. */ diff --git a/packages/type/src/is/lib/is-object-key.func.ts b/packages/type/src/is/lib/is-object-key.func.ts index ca97244c..615bf628 100644 --- a/packages/type/src/is/lib/is-object-key.func.ts +++ b/packages/type/src/is/lib/is-object-key.func.ts @@ -6,10 +6,10 @@ import { isObject } from './is-object.func'; import { IsObjectKey } from '../type/is-object-key.type'; import { Key } from '../../type/key.type'; /** - * Determines if any `object` has its own specified keys of the `Key` type. + * Checks if any `object` has its own specified keys of the `Key` type. * @param object Any `object` to check if it contains a specified `key`. * @param key `Key` type or an array of `Key` type to check. - * @returns A `boolean` indicating whether or not the `object` has its own specified keys of `Key`. + * @returns A `boolean` indicating whether or not the `object` has its own specified keys. */ export const isObjectKey: IsObjectKey = (object: any, key: Key | Key[]): object is Type => isObject(object) ? From 9167f503ea266c178029178570c2a2665d55ec8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 25 Apr 2021 19:05:02 +0200 Subject: [PATCH 076/201] test(is): update --- packages/type/src/is/test/is.spec.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/type/src/is/test/is.spec.ts b/packages/type/src/is/test/is.spec.ts index 8fdd2f3b..0a865d0b 100644 --- a/packages/type/src/is/test/is.spec.ts +++ b/packages/type/src/is/test/is.spec.ts @@ -3,7 +3,5 @@ import { is } from '../lib/is.object'; describe('is.', () => { // TRUE - it('is DEFINED', () => { - expect(is).toBeDefined(); - }); + it('is DEFINED', () => expect(is).toBeDefined()); }); From ecaeadbaa488e65cea7eb8c1d00a387dc234f316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 25 Apr 2021 19:06:39 +0200 Subject: [PATCH 077/201] refactor(isKey): change the order of checking to use string as first --- packages/type/src/is/lib/is-key.func.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/is/lib/is-key.func.ts b/packages/type/src/is/lib/is-key.func.ts index 2ea7fda6..165b6402 100644 --- a/packages/type/src/is/lib/is-key.func.ts +++ b/packages/type/src/is/lib/is-key.func.ts @@ -10,4 +10,4 @@ import { Key } from '../../type/key.type'; * @param value Any `value` to check. * @returns A `boolean` indicating whether or not the `value` is a `Key` type. */ -export const isKey: IsKey = (value: any): value is Key => isNumber(value) || isString(value) || isSymbol(value); +export const isKey: IsKey = (value: any): value is Key => isString(value) || isNumber(value) || isSymbol(value); From 5c9e544d081a9fa7a7be33b23ba401eee4836e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 25 Apr 2021 19:07:08 +0200 Subject: [PATCH 078/201] docs(README.md): update --- README.md | 146 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 125 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index c3b77a3b..7696f2c5 100644 --- a/README.md +++ b/README.md @@ -223,6 +223,14 @@ const isNot: IsNot = { }; ``` +## errorCallback + +Default function to handle `callback` parameter. + +```typescript +const errorCallback: ResultCallback = (result: boolean): boolean => result; +``` + ## Checks ### areString @@ -245,7 +253,7 @@ The **return value** is a `boolean` value. ### isArray -Use `isArray()` or `is.array()` to check if **any** `value` is an `Array`, `Array` instance and `object` type. +Use `isArray()` or `is.array()` to check if **any** `value` is an [`Array`][Array], [`Array`][Array] instance and `object` type. ```typescript const isArray: IsArray = (value: any): value is Array => @@ -259,7 +267,7 @@ const isArray: IsArray = (value: any): value is Array => | :-------- | :---: | :---------- | | value | `any` | Any `value` to check | -The **return value** is a `boolean` indicating whether or not the `value` is an `Array`. +The **return value** is a `boolean` indicating whether or not the `value` is an [`Array`][Array]. ```typescript // Example usage @@ -305,17 +313,17 @@ isBigInt(BIGINT); // true ### isBoolean -Use `isBoolean()` or `is.boolean()` to check if **any** `value` is a `boolean` type not instance of `Boolean` and `Object` or `object` type instance of `Boolean` and `Object`. +Use `isBoolean()` or `is.boolean()` to check if **any** `value` is a `boolean` type not instance of [`Boolean`][Boolean] and [`Object`][Object] or `object` type instance of [`Boolean`][Boolean] and [`Object`][Object]. ```typescript -const isBoolean: IsBoolean = (value: any): value is boolean => - typeOf(value) === 'boolean' && - (isBooleanObject(value) || isBooleanType(value)); +const isBoolean: IsBoolean = (value: any, callback: ResultCallback = errorCallback): value is boolean => + callback(typeOf(value) === 'boolean' && (isBooleanType(value) || isBooleanObject(value))); ``` | Parameter | Type | Description | | :---------| :---: | :---------- | | value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback) = [`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `boolean`. @@ -332,6 +340,65 @@ isBoolean(BOOLEAN_INSTANCE); // true ---- +### isBooleanObject + +Use `isBooleanObject()` or `is.booleanObject()` to check if **any** `value` is an `object` type and instance of [`Boolean`][Boolean] and [`Object`][Object]. + +```typescript +const isBooleanObject: IsBooleanObject = (value: any, callback: ResultCallback = errorCallback): value is boolean => + callback(typeof value === 'object' && value instanceof Boolean === true && value instanceof Object === true); +``` + +| Parameter | Type | Description | +| :---------| :---: | :---------- | +| value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback) = [`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a [`Boolean`][Boolean] instance. + +```typescript +// Example usage +const BOOLEAN = false; +const BOOLEAN_INSTANCE = new Boolean(false); + +isBooleanObject(BOOLEAN); // false +isBooleanObject(BOOLEAN_INSTANCE); // true +``` + +---- + +### isBooleanType + +Use `isBooleanType()` or `is.booleanType()` to check if **any** `value` is a `boolean` type not an instance of [`Boolean`][Boolean] and [`Object`][Object], and equal to `true` or `false`. + +```typescript +const isBooleanType: IsBooleanType = (value: any, callback: ResultCallback = errorCallback): value is boolean => + callback( + value instanceof Boolean === false && + value instanceof Object === false && + typeof value === 'boolean' && + (value === true || value === false) + ); +``` + +| Parameter | Type | Description | +| :---------| :---: | :---------- | +| value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback) = [`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a `boolean` type. + +```typescript +// Example usage +const BOOLEAN = false; +const BOOLEAN_INSTANCE = new Boolean(false); + +isBooleanType(BOOLEAN); // true +isBooleanType(BOOLEAN_INSTANCE); // false +``` + +---- + ### isDefined Use `isDefined()` or `is.defined()` to check if an **unknown** `value` is NOT an `undefined` type and is NOT equal to `undefined`. @@ -362,7 +429,7 @@ isDefined(defined); // false ### isFunction -Use `isFunction()` or `is.function()` to check if **any** `value` is a `function` type, an instance `Function` and `Object`. +Use `isFunction()` or `is.function()` to check if **any** `value` is a `function` type, an instance [`Function`][Function] and [`Object`][Object]. ```typescript const isFunction: IsFunction = (value: any): value is Func => @@ -431,7 +498,7 @@ isInstance(TWO, TWO); // true and type error ### isKey -Use `isKey()` or `is.key()` to determine if **any** `value` is one of the `string`, `number`, or `symbol`. +Use `isKey()` or `is.key()` to check if **any** `value` is one of the `string`, `number`, or `symbol`. ```typescript const isKey: IsKey = (value: any): value is Key => isString(value) || isNumber(value) || isSymbol(value); @@ -441,7 +508,7 @@ const isKey: IsKey = (value: any): value is Key => isString(value) || isNumber(v | :-------- | :---: |:----------- | | value | `any` | Any `value` to check | -The **return value** is a `boolean` indicating whether or not the `value` is a [`Key`](#Key). +The **return value** is a `boolean` indicating whether or not the `value` is a [`Key`](#Key) type. ---- @@ -522,23 +589,25 @@ The **return value** is a `boolean` indicating whether or not the `value` is an ### isObjectKey -Use `isObject()` or `is.object()` to check if **any** `value` is a generic `Obj` `object` type and `Object` instance with the possibility of containing the `key`. +Use `isObject()` or `is.object()` to check if **any** `object` has its own specified keys of the [`Key`](#Key). ```typescript -const isObject: IsObject = (value: any, key?: Key): value is Obj => - (typeOf(value) === 'object' && typeof value === 'object' && value instanceof Object === true) - ? isKey(key) - ? key in value - : true +const isObjectKey: IsObjectKey = (object: any, key: Key | Key[]): object is Type => + isObject(object) ? + isArray(key) ? + key.every(k => isKey(k) ? ({}).hasOwnProperty.call(object, k) === true : false) + : isKey(key) ? + ({}).hasOwnProperty.call(object, key) + : false : false; ``` -| Parameter | Type | Description | -| :-------- | :-----------: | :---------- | -| value | `any` | Any `value` to check | -| key? | [`Key`](#key) | Property name to find in `value` | +| Parameter | Type | Description | +| :-------- | :------------------------------: | :---------- | +| object | `any` | Any `object` to check | +| key | [`Key`](#key) \| [`Key`](#Key)[] | Property name to find in `object` | -The **return value** is a `boolean` indicating whether or not the `value` is an `object`. +The **return value** is a `boolean` indicating whether or not the `object` has its own specified keys. ---- @@ -586,7 +655,7 @@ const isString: IsString = (value: any, callback: ResultCallback = errorCallback | Parameter | Type | Description | | :-------- | :---------------------------------: | :---------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before return eg. to throw an `Error` | +| callback | [`ResultCallback`](#ResultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `string`. @@ -594,6 +663,26 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` ---- +### isStringObject + +Use `isStringObject()` or `is.stringObject()` to check if **any** `value` is a `string` type, not instance of [`Object`][Object] and [`String`][String] or `object` type and instance of [`String`][String] and [`Object`][Object]. + +```typescript +const isString: IsString = (value: any, callback: ResultCallback = errorCallback): value is string => + callback(typeOf(value) === 'string' && (isStringObject(value) || isStringType(value))); +``` + +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :---------- | +| value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is an instance of a [`String`][String]. + +[Example usage on playground][is-string] | [How to detect `string` type][detect-string] + +---- + ### isSymbol Use `isSymbol()` or `is.symbol()` to check if **any** `value` is a `symbol` type. @@ -614,6 +703,15 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` ---- +### isStringType + +```typescript +const isStringType: IsStringType = (value: any, callback: ResultCallback = errorCallback): value is string => + callback(value instanceof Object === false && value instanceof String === false && typeof value === 'string'); +``` + +---- + ### isType Use `isType()` or `is.type()` to check if **any** `value` is a generic `Type` from the [`Types`](#Types). @@ -1012,6 +1110,12 @@ How do I know when to release 1.0.0? MIT © angular-package ([license](https://github.com/angular-package/type/blob/main/LICENSE)) +[Array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array +[Boolean]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean +[Function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions +[Object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object +[String]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String + [new]: https://img.shields.io/badge/-new-red [type-npm-svg]: https://badge.fury.io/js/%40angular-package%2Ftype.svg From f2641a3aa9f974bcf9b60465a4f0153a95c656d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 25 Apr 2021 22:40:35 +0200 Subject: [PATCH 079/201] feat(isNumberObject): function to check if any value is a `Number` instance --- packages/type/src/is/lib/is-number-object.func.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 packages/type/src/is/lib/is-number-object.func.ts diff --git a/packages/type/src/is/lib/is-number-object.func.ts b/packages/type/src/is/lib/is-number-object.func.ts new file mode 100644 index 00000000..d9874b13 --- /dev/null +++ b/packages/type/src/is/lib/is-number-object.func.ts @@ -0,0 +1,14 @@ +// Function. +import { errorCallback } from '../../lib/error-callback.func'; +// Type. +import { IsNumberObject } from '../type/is-number-object.type'; +import { ResultCallback } from '../../type/result-callback.type'; +/** + * Checks if any `value` is an `object` type an instance of `Number` and `Object`. + * @param value Any `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `errorCallback`. + * @returns A `boolean` indicating whether or not the `value` is a `Number` instance. + */ +export const isNumberObject: IsNumberObject = (value: any, callback: ResultCallback = errorCallback): value is number => + callback(typeof value === 'object' && value instanceof Number === true && value instanceof Object === true); From 90ffab11ad8ecf2074ae3233ef73d721e566ebe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 25 Apr 2021 22:40:59 +0200 Subject: [PATCH 080/201] feat(isNumberType): function to check if any `value` is a `number` type --- packages/type/src/is/lib/is-number-type.func.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 packages/type/src/is/lib/is-number-type.func.ts diff --git a/packages/type/src/is/lib/is-number-type.func.ts b/packages/type/src/is/lib/is-number-type.func.ts new file mode 100644 index 00000000..cf9584dd --- /dev/null +++ b/packages/type/src/is/lib/is-number-type.func.ts @@ -0,0 +1,14 @@ +// Function. +import { errorCallback } from '../../lib/error-callback.func'; +// Type. +import { IsNumberType } from '../type/is-number-type.type'; +import { ResultCallback } from '../../type/result-callback.type'; +/** + * Checks if any `value` is a `boolean` type not an instance of `Boolean` and `Object`, and equal to `true` or `false`. + * @param value Any `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `errorCallback`. + * @returns A `boolean` indicating whether or not the `value` is a `number` type. + */ +export const isNumberType: IsNumberType = (value: any, callback: ResultCallback = errorCallback): value is number => + callback(value instanceof Number === false && value instanceof Object === false && typeof value === 'number'); From 227111f2dfe969ddd2d0d14524a4e8077eadd1b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 25 Apr 2021 22:42:09 +0200 Subject: [PATCH 081/201] refactor(isNumber): update - add `ResultCallback` parameter `callback` with default `errorCallback` --- packages/type/src/is/lib/is-number.func.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/type/src/is/lib/is-number.func.ts b/packages/type/src/is/lib/is-number.func.ts index 0442ff93..c3421244 100644 --- a/packages/type/src/is/lib/is-number.func.ts +++ b/packages/type/src/is/lib/is-number.func.ts @@ -1,15 +1,15 @@ // Function. +import { errorCallback } from '../../lib/error-callback.func'; import { isNumberObject } from './is-number-object.func'; import { isNumberType } from './is-number-type.func'; import { typeOf } from '../../lib/type-of.func'; // Type. import { IsNumber } from '../type/is-number.type'; +import { ResultCallback } from '../../type/result-callback.type'; /** * Checks if any `value` is a `number` type not an instance of `Number` and `Object` or `object` type instance of `Number` and `Object`. * @param value Any value to check. * @returns A `boolean` indicating whether or not the `value` is a `number`. */ -export const isNumber: IsNumber = (value: any): value is number => - typeOf(value) === 'number' && - isFinite(value) === true && - (isNumberObject(value) || isNumberType(value)); +export const isNumber: IsNumber = (value: any, callback: ResultCallback = errorCallback): value is number => + callback(typeOf(value) === 'number' && isFinite(value) === true && (isNumberType(value) || isNumberObject(value))); From b982e8346c2be51158d3ddf6f3e12c8e40c3dd9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 25 Apr 2021 22:42:42 +0200 Subject: [PATCH 082/201] feat(isStringObject): function to check if any `value` is a `String` instance --- packages/type/src/is/lib/is-string-object.func.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 packages/type/src/is/lib/is-string-object.func.ts diff --git a/packages/type/src/is/lib/is-string-object.func.ts b/packages/type/src/is/lib/is-string-object.func.ts new file mode 100644 index 00000000..0a8db9de --- /dev/null +++ b/packages/type/src/is/lib/is-string-object.func.ts @@ -0,0 +1,14 @@ +// Function. +import { errorCallback } from '../../lib/error-callback.func'; +// Type. +import { IsStringObject } from '../type/is-string-object.type'; +import { ResultCallback } from '../../type/result-callback.type'; +/** + * Checks if any `value` is an `object` type instance of `String` and `Object`. + * @param value Any `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `errorCallback`. + * @returns A `boolean` indicating whether or not the `value` is a `String` instance. + */ +export const isStringObject: IsStringObject = (value: any, callback: ResultCallback = errorCallback): value is string => + callback(value instanceof Object === true && value instanceof String === true && typeof value === 'object'); From 0e8858d79a3d0b129afc3202bdfc7680b4e2257c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 25 Apr 2021 22:43:15 +0200 Subject: [PATCH 083/201] feat(isStringType): function to check if any `value` is a `string` --- packages/type/src/is/lib/is-string-type.func.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 packages/type/src/is/lib/is-string-type.func.ts diff --git a/packages/type/src/is/lib/is-string-type.func.ts b/packages/type/src/is/lib/is-string-type.func.ts new file mode 100644 index 00000000..a3ebfe78 --- /dev/null +++ b/packages/type/src/is/lib/is-string-type.func.ts @@ -0,0 +1,14 @@ +// Function. +import { errorCallback } from '../../lib/error-callback.func'; +// Type. +import { IsStringType } from '../type/is-string-type.type'; +import { ResultCallback } from '../../type/result-callback.type'; +/** + * Checks if any `value` is a `string` type not instance of `String` and `Object`. + * @param value Any `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `errorCallback`. + * @returns A `boolean` indicating whether or not the value is a `string`. + */ +export const isStringType: IsStringType = (value: any, callback: ResultCallback = errorCallback): value is string => + callback(value instanceof Object === false && value instanceof String === false && typeof value === 'string'); From 0cdf5a2cdf3354c48edba4c32748d034fcb06c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 25 Apr 2021 22:53:51 +0200 Subject: [PATCH 084/201] refactor(guardArray): update - change param name from `value` to `array` - categorize imports - update jsdoc --- packages/type/src/guard/lib/guard-array.func.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/type/src/guard/lib/guard-array.func.ts b/packages/type/src/guard/lib/guard-array.func.ts index fbcc11c1..2135fa80 100644 --- a/packages/type/src/guard/lib/guard-array.func.ts +++ b/packages/type/src/guard/lib/guard-array.func.ts @@ -1,9 +1,10 @@ +// Function. import { isArray } from '../../is/lib/is-array.func'; +// Type. import { GuardArray } from '../type/guard-array.type'; /** - * Guard the `value` to be a generic `Array` `Type`. - * Use `isArray()` function to check ONLY. - * @param value Array generic type value to guard. - * @returns boolean. + * Guard the `array` value to be a generic `Array` of `Type`. + * @param array A generic `Type` `Array` value to guard. + * @returns A `boolean` indicating whether or not the `value` is an `Array` of `Type`. */ -export const guardArray: GuardArray = (value: Array): value is Array => isArray(value); +export const guardArray: GuardArray = (array: Array): array is Array => isArray(array); From 0968a95ab7f0b54edf671203bda33b3569f95465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 12:12:11 +0200 Subject: [PATCH 085/201] refactor(guardArray): change parameter name to `value` and update jsdoc --- packages/type/src/guard/lib/guard-array.func.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/type/src/guard/lib/guard-array.func.ts b/packages/type/src/guard/lib/guard-array.func.ts index 2135fa80..beda4de3 100644 --- a/packages/type/src/guard/lib/guard-array.func.ts +++ b/packages/type/src/guard/lib/guard-array.func.ts @@ -3,8 +3,8 @@ import { isArray } from '../../is/lib/is-array.func'; // Type. import { GuardArray } from '../type/guard-array.type'; /** - * Guard the `array` value to be a generic `Array` of `Type`. - * @param array A generic `Type` `Array` value to guard. - * @returns A `boolean` indicating whether or not the `value` is an `Array` of `Type`. + * Guard the `value` to be an `Array` of a generic `Type`. + * @param value A generic `Type` `Array` `value` to guard. + * @returns A `boolean` indicating whether or not the `value` is an `Array` of a generic `Type`. */ -export const guardArray: GuardArray = (array: Array): array is Array => isArray(array); +export const guardArray: GuardArray = (value: Array): value is Array => isArray(value); From 953c75a1600d295e43a6ab03504c7d5e0ddf6072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 12:16:49 +0200 Subject: [PATCH 086/201] refactor(guardFunction): change parameter name to value, update jsdoc, categorize imports --- packages/type/src/guard/lib/guard-function.func.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/type/src/guard/lib/guard-function.func.ts b/packages/type/src/guard/lib/guard-function.func.ts index 6e25ae2f..1f8d6d15 100644 --- a/packages/type/src/guard/lib/guard-function.func.ts +++ b/packages/type/src/guard/lib/guard-function.func.ts @@ -1,9 +1,11 @@ -import { GuardFunction } from '../type/guard-function.type'; +// Function. import { isFunction } from '../../is/lib/is-function.func'; +// Type. +import { GuardFunction } from '../type/guard-function.type'; import { Func } from '../../type/func.type'; /** - * Guard the `func` value to be a `Func` type. - * @param func `Func` type value to guard. - * @returns boolean. + * Guard the `value` to be a `Func` type. + * @param value Type `Func` `value` to guard. + * @returns A `boolean` indicating whether or not the `value` is a `Func` type. */ -export const guardFunction: GuardFunction = (func: Func): func is Func => isFunction(func); +export const guardFunction: GuardFunction = (value: Func): value is Func => isFunction(value); From c15af0451b6e748eecad11c9a59896cb8fa10613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 12:26:38 +0200 Subject: [PATCH 087/201] refactor(guardKey): update - change the return type - use `isKey` function to check - update jsdoc --- packages/type/src/guard/lib/guard-key.func.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/type/src/guard/lib/guard-key.func.ts b/packages/type/src/guard/lib/guard-key.func.ts index 8fb43b53..a7a65b15 100644 --- a/packages/type/src/guard/lib/guard-key.func.ts +++ b/packages/type/src/guard/lib/guard-key.func.ts @@ -1,14 +1,11 @@ // Function. -import { isNumber } from '../../is/lib/is-number.func'; -import { isString } from '../../is/lib/is-string.func'; -import { isSymbol } from '../../is/lib/is-symbol.func'; +import { isKey } from '../../is/lib/is-key.func'; // Type. import { GuardKey } from '../type/guard-key.type'; import { Key } from '../../type/key.type'; - /** - * Guard the `value` of `Key type to be one of the `string`, `number`, or `symbol` type. - * @param value A generic `Key` type `value` to guard. - * @returns A `boolean` indicating whether or not the `value` is one of the `string`, `number` or `symbol` type. + * Guard the `value` to be one of the `string`, `number`, or `symbol` type. + * @param value A `Key` type `value` to guard. + * @returns A `boolean` indicating whether or not the `value` is a `Key`. */ -export const guardKey: GuardKey = (value: Key): boolean => isString(value) || isNumber(value) || isSymbol(value); +export const guardKey: GuardKey = (value: Key): value is Key => isKey(value); From c0576bb7b605e7eb3dcf54b7a4c3a8fa35e0bb76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 12:27:53 +0200 Subject: [PATCH 088/201] docs(guardKey): update --- packages/type/src/guard/lib/guard-key.func.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/guard/lib/guard-key.func.ts b/packages/type/src/guard/lib/guard-key.func.ts index a7a65b15..9663cf31 100644 --- a/packages/type/src/guard/lib/guard-key.func.ts +++ b/packages/type/src/guard/lib/guard-key.func.ts @@ -4,7 +4,7 @@ import { isKey } from '../../is/lib/is-key.func'; import { GuardKey } from '../type/guard-key.type'; import { Key } from '../../type/key.type'; /** - * Guard the `value` to be one of the `string`, `number`, or `symbol` type. + * Guard the `value` to be one of the `string`, `number`, or `symbol`. * @param value A `Key` type `value` to guard. * @returns A `boolean` indicating whether or not the `value` is a `Key`. */ From cce8679eba2c3de275ee3b6ff5f4421bde4c7c5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 12:30:48 +0200 Subject: [PATCH 089/201] docs(guardNumber): categorize imports and update jsdoc `returns` and `value` --- packages/type/src/guard/lib/guard-number.func.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/type/src/guard/lib/guard-number.func.ts b/packages/type/src/guard/lib/guard-number.func.ts index be32399b..fb53e6d3 100644 --- a/packages/type/src/guard/lib/guard-number.func.ts +++ b/packages/type/src/guard/lib/guard-number.func.ts @@ -1,9 +1,10 @@ +// Function. import { isNumber } from '../../is/lib/is-number.func'; +// Type. import { GuardNumber } from '../type/guard-number.type'; /** - * Guard the `value` to be a `number` type. - * Use `isNumber()` function for check ONLY. - * @param value Type `number` value to guard. - * @returns boolean + * Guard the `value` to be a `number`. + * @param value A `number` type `value` to guard. + * @returns A `boolean` indicating whether or not the `value` is a `number`. */ export const guardNumber: GuardNumber = (value: number): value is number => isNumber(value); From c08254c7dece925f7db04ff96666d3a39e9ec08a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 12:42:08 +0200 Subject: [PATCH 090/201] refactor(guardObject): update - change parameter name to `value` - categorize imports - update jsdoc --- packages/type/src/guard/lib/guard-object.func.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/type/src/guard/lib/guard-object.func.ts b/packages/type/src/guard/lib/guard-object.func.ts index 246fa895..57ff1c91 100644 --- a/packages/type/src/guard/lib/guard-object.func.ts +++ b/packages/type/src/guard/lib/guard-object.func.ts @@ -1,9 +1,10 @@ -import { GuardObject } from '../type/guard-object.type'; +// Function. import { isObject } from '../../is/lib/is-object.func'; +// Type. +import { GuardObject } from '../type/guard-object.type'; /** - * Guard the `obj` value to be a generic object `Obj`. - * Use `isObject()` function for check ONLY. - * @param object Generic `Obj` type value to guard. - * @returns boolean + * Guard the `value` to be an `object` of a generic `Obj` type. + * @param value A generic `Obj` type `value` to guard. + * @returns A `boolean` indicating whether or not the `value` is an `object` of a generic `Obj`. */ -export const guardObject: GuardObject = (object: Obj): object is Obj => isObject(object); +export const guardObject: GuardObject = (value: Obj): value is Obj => isObject(value); From 3f8e1715a4ea9a504263f60c8f0c15979ae5f80f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 13:03:01 +0200 Subject: [PATCH 091/201] refactor(guardObjectKey): update - change parameter name from `object` to `value` - categorize imports - update jsdoc --- .../type/src/guard/lib/guard-object-key.func.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/type/src/guard/lib/guard-object-key.func.ts b/packages/type/src/guard/lib/guard-object-key.func.ts index 854c8a8c..3f872e00 100644 --- a/packages/type/src/guard/lib/guard-object-key.func.ts +++ b/packages/type/src/guard/lib/guard-object-key.func.ts @@ -1,12 +1,13 @@ +// Function. import { guardObject } from './guard-object.func'; +import { isKey } from '../../is/lib/is-key.func'; +// Type. import { GuardObjectKey } from '../type/guard-object-key.type'; -import { isString } from '../../is/lib/is-string.func'; /** - * Guard the `object` to be a generic `Obj` type and to contains the `key` property. - * Use `isObject()` function for check ONLY. - * @param object Generic `Obj` type `value` that contains the `key` property to guard. - * @param key Name of the property that the `object` contains. - * @returns boolean + * Guard the `value` to be an `object` of a generic `Obj` type that contains the `key` property of the `Key` type. + * @param value A generic `Obj` type `value` that contains the `key` property to guard. + * @param key A `Key` type name of the property that the `object` contains. + * @returns A `boolean` indicating whether or not the `value` is an `object` of a generic `Obj` containing the `Key`. */ -export const guardObjectKey: GuardObjectKey = (object: Obj, key: Key): object is Obj => - guardObject(object) ? isString(key) ? key in object : true : false; +export const guardObjectKey: GuardObjectKey = (value: Obj, key: Key): value is Obj => + guardObject(value) ? isKey(key) ? key in value : true : false; From a8ea20db3c448e42b557ccb13df87c7392853208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 13:34:51 +0200 Subject: [PATCH 092/201] refactor(guardPrimitive): update - `Type` extends `Primitive` - categorize imports - update jsdoc --- .../type/src/guard/lib/guard-primitive.func.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/type/src/guard/lib/guard-primitive.func.ts b/packages/type/src/guard/lib/guard-primitive.func.ts index 27c73727..78aa9dae 100644 --- a/packages/type/src/guard/lib/guard-primitive.func.ts +++ b/packages/type/src/guard/lib/guard-primitive.func.ts @@ -1,10 +1,14 @@ +// Function. +import { isPrimitive } from '../../is/lib/is-primitive.func'; +// Type. import { GuardPrimitive } from '../type/guard-primitive.type'; +import { Primitive } from '../../type/primitive.type'; import { Primitives } from '../../type/primitives.type'; -import { isPrimitive } from '../../is/lib/is-primitive.func'; /** - * Guard the `value` to be a generic `Type` from one of the `Primitives`. - * Use `isPrimitive()` function for check ONLY. - * @param value A generic `Type` type value to guard. - * @param type One of the `Primitives` `'boolean'`, `'bigint'`, `'number'`, `'string'`, `'symbol'`, `'undefined'` to check `value`. + * Guard the `value` to be the `Type` from the `Primitives`. + * @param value A generic `Type` `value` to guard. + * @param type One of the `Primitives` to check the `value`. + * @returns A `boolean` indicating whether or not the `value` is the `Type` from the `Primitives`. */ -export const guardPrimitive: GuardPrimitive = (value: Type, type: Primitives): value is Type => isPrimitive(value, type); +export const guardPrimitive: GuardPrimitive = (value: Type, type: Primitives): value is Type => + isPrimitive(value, type); From 47f746e3f80e686522f55bf4c3a4744a09af122b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 13:37:41 +0200 Subject: [PATCH 093/201] docs(guardString): categorize imports, update jsdoc --- packages/type/src/guard/lib/guard-string.func.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/type/src/guard/lib/guard-string.func.ts b/packages/type/src/guard/lib/guard-string.func.ts index 6b810b3d..14e8fd56 100644 --- a/packages/type/src/guard/lib/guard-string.func.ts +++ b/packages/type/src/guard/lib/guard-string.func.ts @@ -1,8 +1,10 @@ -import { GuardString } from '../type/guard-string.type'; +// Function. import { isString } from '../../is/lib/is-string.func'; +// Type. +import { GuardString } from '../type/guard-string.type'; /** - * Guard the `value` to be a `string` type. - * Use `isString()` function for check ONLY. - * @param value String type value to guard. + * Guard the `value` to be a `string`. + * @param value A `string` type `value` to guard. + * @returns A `boolean` indicating whether or not the `value` is a `string`. */ export const guardString: GuardString = (value: string): value is string => isString(value); From a2a53116f2c60e923ea9e85025c0bfa0d9406b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 16:52:17 +0200 Subject: [PATCH 094/201] refactor(isPrimitive): update - change the generic `Type` to use `Primitive` type - update jsdoc --- packages/type/src/is/lib/is-primitive.func.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/type/src/is/lib/is-primitive.func.ts b/packages/type/src/is/lib/is-primitive.func.ts index 8d54da36..4a4f3f06 100644 --- a/packages/type/src/is/lib/is-primitive.func.ts +++ b/packages/type/src/is/lib/is-primitive.func.ts @@ -8,14 +8,15 @@ import { isSymbol } from './is-symbol.func'; import { isUndefined } from './is-undefined.func'; // Type. import { IsPrimitive } from '../type/is-primitive.type'; +import { Primitive } from '../../type/primitive.type'; import { Primitives } from '../../type/primitives.type'; /** - * Checks if any `value` is a generic `Type` from the `Primitives`. - * @param value Any `value` to check if it's a generic `Type` from the `type`. - * @param type Name of the type from the `Primitives` to check the `value`. - * @returns A `boolean` indicating whether or not the `value` is a type from the `Primitives`. + * Checks if any `value` is a `Primitive` type from the `type` of the `Primitives` type. + * @param value Any `value` to check if it's a `Primitive` from the `type`. + * @param type A `string` name of the `type` from the `Primitives` to check the `value`. + * @returns A `boolean` indicating whether or not the `value` is a `type` from the `Primitives`. */ -export const isPrimitive: IsPrimitive = (value: any, type: Primitives): value is Type => { +export const isPrimitive: IsPrimitive = (value: any, type: Primitives): value is T => { if (isString(type)) { switch (type) { case 'bigint': return isBigInt(value); From 57b85e5c5a51b211e99e2ebf4cd8c88388eb35b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 16:56:49 +0200 Subject: [PATCH 095/201] refactor(IsPrimitive): use `Primitive` type --- packages/type/src/is/type/is-primitive.type.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/type/src/is/type/is-primitive.type.ts b/packages/type/src/is/type/is-primitive.type.ts index c951bbbe..ad805fc4 100644 --- a/packages/type/src/is/type/is-primitive.type.ts +++ b/packages/type/src/is/type/is-primitive.type.ts @@ -1,2 +1,4 @@ import { Primitives } from '../../type/primitives.type'; -export type IsPrimitive = (value: any, type: Primitives) => value is Type; +import { Primitive } from '../../type/primitive.type'; +export type IsPrimitive = (value: any, type: Primitives) => value is T; + From 85bc471e8f53a19f3f3c54733f681b2cbbe01061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 17:04:14 +0200 Subject: [PATCH 096/201] refactor(isType): update - change a generic `Type` to use the `Type` - update jsdoc --- packages/type/src/is/lib/is-type.func.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/type/src/is/lib/is-type.func.ts b/packages/type/src/is/lib/is-type.func.ts index 15a15c68..cb52d781 100644 --- a/packages/type/src/is/lib/is-type.func.ts +++ b/packages/type/src/is/lib/is-type.func.ts @@ -1,25 +1,21 @@ // Function. -import { isBigInt } from './is-big-int.func'; -import { isBoolean } from './is-boolean.func'; import { isFunction } from './is-function.func'; import { isInstance } from './is-instance.func'; -import { isNumber } from './is-number.func'; import { isObject } from './is-object.func'; import { isPrimitive } from './is-primitive.func'; import { isString } from './is-string.func'; -import { isSymbol } from './is-symbol.func'; -import { isUndefined } from './is-undefined.func'; // Type. import { IsType } from '../type/is-type.type'; +import { Type } from '../../type/type.type'; import { Types } from '../../type/types.type'; import { isNotNull } from '../not/lib/is-not-null.func'; /** - * Checks if any `value` is a generic `Type` from the `Types`. + * Checks if any `value` is a `Type` from the `type` of the `Types` type. * @param value Any `value` to check if its type is from the `type`. - * @param type One type from the `Types` to check the `value`. - * @returns A `boolean` indicating whether or not the `value` is a type from the `Types`. + * @param type A `string` or generic `Constructor` type from the `Types` to check the `value`. + * @returns A `boolean` indicating whether or not the `value` is a `type` from the `Types`. */ -export const isType: IsType = (value: any, type: Types): value is Type => { +export const isType: IsType = (value: any, type: Types): value is T => { if (isString(type)) { switch (type) { // Primitives. @@ -33,10 +29,10 @@ export const isType: IsType = (value: any, type: Types): value is Ty // Function. case 'function': return isFunction(value); // Object. - case 'object': return isObject(value); + case 'object': return isObject(value); } } else if (isNotNull(type)) { - return isInstance(value, type); + return isInstance(value, type); } return false; }; From 625b9078e5e932b34693842057525de984a7fe1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 17:05:23 +0200 Subject: [PATCH 097/201] refactor(IsType)L use the `Type` instead of generic `Type` --- packages/type/src/is/type/is-type.type.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/type/src/is/type/is-type.type.ts b/packages/type/src/is/type/is-type.type.ts index 546a16cd..f4de98b1 100644 --- a/packages/type/src/is/type/is-type.type.ts +++ b/packages/type/src/is/type/is-type.type.ts @@ -1,2 +1,3 @@ +import { Type } from '../../type/type.type'; import { Types } from '../../type/types.type'; -export type IsType = (value: any, type: Types) => value is Type; +export type IsType = (value: any, type: Types) => value is T; From d6510b405409b837eb89d2315d8be357e7d63e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 17:07:59 +0200 Subject: [PATCH 098/201] refactor(guardObject): update - generic `Obj` extends `object` - update `value ` jsdoc --- packages/type/src/guard/lib/guard-object.func.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/type/src/guard/lib/guard-object.func.ts b/packages/type/src/guard/lib/guard-object.func.ts index 57ff1c91..f22d4d00 100644 --- a/packages/type/src/guard/lib/guard-object.func.ts +++ b/packages/type/src/guard/lib/guard-object.func.ts @@ -4,7 +4,7 @@ import { isObject } from '../../is/lib/is-object.func'; import { GuardObject } from '../type/guard-object.type'; /** * Guard the `value` to be an `object` of a generic `Obj` type. - * @param value A generic `Obj` type `value` to guard. + * @param value A generic `Obj` type value to guard. * @returns A `boolean` indicating whether or not the `value` is an `object` of a generic `Obj`. */ -export const guardObject: GuardObject = (value: Obj): value is Obj => isObject(value); +export const guardObject: GuardObject = (value: Obj): value is Obj => isObject(value); From 23582171f8ba5ba25ef0ff98b85d138ac98b4a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 17:12:48 +0200 Subject: [PATCH 099/201] chore(type): update - add `Key`, `Primitive` , `Primitives`, `Types` jsdoc - add `Type` type --- packages/type/src/type/index.ts | 3 +++ packages/type/src/type/key.type.ts | 3 +++ packages/type/src/type/primitive.type.ts | 3 +++ packages/type/src/type/primitives.type.ts | 3 +++ packages/type/src/type/type.type.ts | 6 ++++++ packages/type/src/type/types.type.ts | 3 +++ 6 files changed, 21 insertions(+) create mode 100644 packages/type/src/type/type.type.ts diff --git a/packages/type/src/type/index.ts b/packages/type/src/type/index.ts index fdcd110b..1a88d7a5 100644 --- a/packages/type/src/type/index.ts +++ b/packages/type/src/type/index.ts @@ -1,6 +1,9 @@ export { Constructor } from './constructor.type'; export { CycleHook } from './cycle-hook.type'; export { Func } from './func.type'; +export { Key } from './key.type'; export { Primitive } from './primitive.type'; export { Primitives } from './primitives.type'; +export { ResultCallback } from './result-callback.type'; +export { Type } from './type.type'; export { Types } from './types.type'; diff --git a/packages/type/src/type/key.type.ts b/packages/type/src/type/key.type.ts index 76ae3142..0e37731d 100644 --- a/packages/type/src/type/key.type.ts +++ b/packages/type/src/type/key.type.ts @@ -1 +1,4 @@ +/** + * Name of the `object` property. + */ export type Key = number | string | symbol; diff --git a/packages/type/src/type/primitive.type.ts b/packages/type/src/type/primitive.type.ts index b68d2179..86588765 100644 --- a/packages/type/src/type/primitive.type.ts +++ b/packages/type/src/type/primitive.type.ts @@ -1 +1,4 @@ +/** + * All primitives. + */ export type Primitive = boolean | bigint | null | number | string | symbol | undefined; diff --git a/packages/type/src/type/primitives.type.ts b/packages/type/src/type/primitives.type.ts index ab1ade93..c09ad762 100644 --- a/packages/type/src/type/primitives.type.ts +++ b/packages/type/src/type/primitives.type.ts @@ -1 +1,4 @@ +/** + * All primitives as `string`. + */ export type Primitives = 'bigint' | 'boolean' | 'null' | 'number' | 'string' | 'symbol' | 'undefined'; diff --git a/packages/type/src/type/type.type.ts b/packages/type/src/type/type.type.ts new file mode 100644 index 00000000..db8ab3c9 --- /dev/null +++ b/packages/type/src/type/type.type.ts @@ -0,0 +1,6 @@ +import { Func } from './func.type'; +import { Primitive } from './primitive.type'; +/** + * Main types. + */ +export type Type = Func | object | Primitive; diff --git a/packages/type/src/type/types.type.ts b/packages/type/src/type/types.type.ts index 31ee2908..dae586b8 100644 --- a/packages/type/src/type/types.type.ts +++ b/packages/type/src/type/types.type.ts @@ -1,3 +1,6 @@ import { Constructor } from './constructor.type'; import { Primitives } from './primitives.type'; +/** + * Main types as `string` values. + */ export type Types = Constructor | 'function' | 'object' | Primitives; From 590e347b4024bc707637b4aa048e0619ae34e4bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 18:35:09 +0200 Subject: [PATCH 100/201] refactor(GuardType): change a generic `Type` to the `Type` --- packages/type/src/guard/type/guard-type.type.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/type/src/guard/type/guard-type.type.ts b/packages/type/src/guard/type/guard-type.type.ts index 9e04612a..2b74f63d 100644 --- a/packages/type/src/guard/type/guard-type.type.ts +++ b/packages/type/src/guard/type/guard-type.type.ts @@ -1,2 +1,3 @@ import { Types } from '../../type/types.type'; -export type GuardType = (value: Type, type: Types) => value is Type; +import { Type } from '../../type/type.type'; +export type GuardType = (value: T, type: Types) => value is T; From e203d5f5498fbc82a2b33c71b96a53b04156dc32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 18:35:45 +0200 Subject: [PATCH 101/201] refactor(GuardPrimitive): change a generic `Type` to the `Primitive` --- packages/type/src/guard/type/guard-primitive.type.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/type/src/guard/type/guard-primitive.type.ts b/packages/type/src/guard/type/guard-primitive.type.ts index a2680526..ffcff5b4 100644 --- a/packages/type/src/guard/type/guard-primitive.type.ts +++ b/packages/type/src/guard/type/guard-primitive.type.ts @@ -1,2 +1,3 @@ +import { Primitive } from '../../type/primitive.type'; import { Primitives } from '../../type/primitives.type'; -export type GuardPrimitive = (value: Type, type: Primitives) => value is Type; +export type GuardPrimitive = (value: T, type: Primitives) => value is T; From ad16835559b4d85e6665c2ccb5a6051a9c6d0aeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 18:39:40 +0200 Subject: [PATCH 102/201] refactor(GuardObject): change parameter to value, extends a generic `Obj` with `object` --- packages/type/src/guard/type/guard-object.type.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/guard/type/guard-object.type.ts b/packages/type/src/guard/type/guard-object.type.ts index 02ea3694..1139e329 100644 --- a/packages/type/src/guard/type/guard-object.type.ts +++ b/packages/type/src/guard/type/guard-object.type.ts @@ -1 +1 @@ -export type GuardObject = (object: Obj) => object is Obj; +export type GuardObject = (value: Obj) => value is Obj; From d5d01f861def65da752eb20d9449b2960d134947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 18:40:20 +0200 Subject: [PATCH 103/201] chore(type): add jsdoc --- packages/type/src/type/constructor.type.ts | 3 +++ packages/type/src/type/func.type.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/packages/type/src/type/constructor.type.ts b/packages/type/src/type/constructor.type.ts index 843ee122..5b3885dd 100644 --- a/packages/type/src/type/constructor.type.ts +++ b/packages/type/src/type/constructor.type.ts @@ -1 +1,4 @@ +/** + * Class type. + */ export type Constructor = new (...args: any[]) => Type; diff --git a/packages/type/src/type/func.type.ts b/packages/type/src/type/func.type.ts index 633f2266..9d3d92a4 100644 --- a/packages/type/src/type/func.type.ts +++ b/packages/type/src/type/func.type.ts @@ -1 +1,4 @@ +/** + * Function type. + */ export type Func = (...param: any) => any; From ec4102ce85c9311778d075a2d2193e92e6583e34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 18:41:03 +0200 Subject: [PATCH 104/201] style(isNot): sort alphabetically imports --- packages/type/src/is/not/lib/is-not.object.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/type/src/is/not/lib/is-not.object.ts b/packages/type/src/is/not/lib/is-not.object.ts index 5e23a269..71856213 100644 --- a/packages/type/src/is/not/lib/is-not.object.ts +++ b/packages/type/src/is/not/lib/is-not.object.ts @@ -1,11 +1,11 @@ import { IsNot } from '../interface/is-not.interface'; import { isNotBoolean } from './is-not-boolean.func'; -import { isNotNumber } from './is-not-number.func'; -import { isNotUndefined } from './is-not-undefined.func'; +import { isNotDefined } from './is-not-defined.func'; +import { isNotFunction } from './is-not-function.func'; import { isNotNull } from './is-not-null.func'; +import { isNotNumber } from './is-not-number.func'; import { isNotString } from './is-not-string.func'; -import { isNotFunction } from './is-not-function.func'; -import { isNotDefined } from './is-not-defined.func'; +import { isNotUndefined } from './is-not-undefined.func'; export const isNot: IsNot = { // TODO array: isArray, From b43a7d11d1589e8229924b1c7db156fca50a3e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 18:48:15 +0200 Subject: [PATCH 105/201] refactor(is): add functions - `bigint` - `booleanObject` - `booleanType` - `numberObject` - `numberType` - `stringObject` - `stringType` --- packages/type/src/is/lib/is.object.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/type/src/is/lib/is.object.ts b/packages/type/src/is/lib/is.object.ts index 53b3251c..3d20a7c9 100644 --- a/packages/type/src/is/lib/is.object.ts +++ b/packages/type/src/is/lib/is.object.ts @@ -2,16 +2,22 @@ import { isArray } from './is-array.func'; import { isBigInt } from './is-big-int.func'; import { isBoolean } from './is-boolean.func'; +import { isBooleanObject } from './is-boolean-object.func'; +import { isBooleanType } from './is-boolean-type.func'; import { isDefined } from './is-defined.func'; import { isFunction } from './is-function.func'; import { isInstance } from './is-instance.func'; import { isKey } from './is-key.func'; import { isNull } from './is-null.func'; import { isNumber } from './is-number.func'; +import { isNumberObject } from './is-number-object.func'; +import { isNumberType } from './is-number-type.func'; import { isObject } from './is-object.func'; import { isObjectKey } from './is-object-key.func'; import { isPrimitive } from './is-primitive.func'; import { isString } from './is-string.func'; +import { isStringObject } from './is-string-object.func'; +import { isStringType } from './is-string-type.func'; import { isSymbol } from './is-symbol.func'; import { isType } from './is-type.func'; import { isUndefined } from './is-undefined.func'; @@ -19,12 +25,14 @@ import { isUndefined } from './is-undefined.func'; import { isNot } from '../not/lib/is-not.object'; // Interface. import { Is } from '../interface/is.interface'; - +// `is`. export const is: Is = { array: isArray, - bigint: isBigInt, bigInt: isBigInt, // deprecated + bigint: isBigInt, boolean: isBoolean, + booleanObject: isBooleanObject, + booleanType: isBooleanType, defined: isDefined, function: isFunction, instance: isInstance, @@ -32,10 +40,14 @@ export const is: Is = { not: isNot, null: isNull, number: isNumber, + numberObject: isNumberObject, + numberType: isNumberType, object: isObject, objectKey: isObjectKey, primitive: isPrimitive, string: isString, + stringObject: isStringObject, + stringType: isStringType, symbol: isSymbol, type: isType, undefined: isUndefined From 77dd5b5cac7624e389ef4efa1ecfb4b1db082843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 18:53:22 +0200 Subject: [PATCH 106/201] docs(isType): update --- packages/type/src/is/lib/is-type.func.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/is/lib/is-type.func.ts b/packages/type/src/is/lib/is-type.func.ts index cb52d781..5509c4e8 100644 --- a/packages/type/src/is/lib/is-type.func.ts +++ b/packages/type/src/is/lib/is-type.func.ts @@ -13,7 +13,7 @@ import { isNotNull } from '../not/lib/is-not-null.func'; * Checks if any `value` is a `Type` from the `type` of the `Types` type. * @param value Any `value` to check if its type is from the `type`. * @param type A `string` or generic `Constructor` type from the `Types` to check the `value`. - * @returns A `boolean` indicating whether or not the `value` is a `type` from the `Types`. + * @returns A `boolean` indicating whether or not the `value` is a `Type` from the `type` of the `Types`. */ export const isType: IsType = (value: any, type: Types): value is T => { if (isString(type)) { From 1b9e239f660931c4ef30fe89c41b88246e142f8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 18:55:32 +0200 Subject: [PATCH 107/201] refactor(Is): add functions - `bigint` - `booleanObject` - `booleanType` - `key` - `numberObject` - `numberType` - `objectKey` - `stringObject` - `stringType` --- .../type/src/is/interface/is.interface.ts | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/type/src/is/interface/is.interface.ts b/packages/type/src/is/interface/is.interface.ts index 10aa8c45..69b16e1d 100644 --- a/packages/type/src/is/interface/is.interface.ts +++ b/packages/type/src/is/interface/is.interface.ts @@ -1,32 +1,49 @@ import { IsArray } from '../type/is-array.type'; -import { IsBoolean } from '../type/is-boolean.type'; import { IsBigInt } from '../type/is-big-int.type'; +import { IsBoolean } from '../type/is-boolean.type'; +import { IsBooleanObject } from '../type/is-boolean-object.type'; import { IsDefined } from '../type/is-defined.type'; import { IsFunction } from '../type/is-function.type'; +import { IsInstance } from '../type/is-instance.type'; +import { IsKey } from '../type/is-key.type'; import { IsNot } from '../not/interface/is-not.interface'; import { IsNull } from '../type/is-null.type'; import { IsNumber } from '../type/is-number.type'; import { IsObject } from '../type/is-object.type'; +import { IsObjectKey } from '../type/is-object-key.type'; import { IsPrimitive } from '../type/is-primitive.type'; import { IsString } from '../type/is-string.type'; +import { IsStringObject } from '../type/is-string-object.type'; +import { IsStringType } from '../type/is-string-type.type'; import { IsSymbol } from '../type/is-symbol.type'; import { IsType } from '../type/is-type.type'; import { IsUndefined } from '../type/is-undefined.type'; -import { IsInstance } from '../type/is-instance.type'; +import { IsBooleanType } from '../type/is-boolean-type.type'; +import { IsNumberObject } from '../type/is-number-object.type'; +import { IsNumberType } from '../type/is-number-type.type'; export interface Is { array: IsArray; bigInt: IsBigInt; + bigint: IsBigInt; boolean: IsBoolean; + booleanObject: IsBooleanObject; + booleanType: IsBooleanType; defined: IsDefined; function: IsFunction; instance: IsInstance; + key: IsKey; not: IsNot; null: IsNull; number: IsNumber; + numberObject: IsNumberObject; + numberType: IsNumberType; object: IsObject; + objectKey: IsObjectKey; primitive: IsPrimitive; string: IsString; + stringObject: IsStringObject; + stringType: IsStringType; symbol: IsSymbol; type: IsType; undefined: IsUndefined; From e95dc80d7c7e238c0cc3f84db269f9efb666dd8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 23:05:33 +0200 Subject: [PATCH 108/201] docs: update jsdoc --- packages/type/src/guard/lib/guard-function.func.ts | 4 ++-- packages/type/src/guard/lib/guard-object.func.ts | 2 +- packages/type/src/is/not/lib/is-not-boolean.func.ts | 10 +++++----- packages/type/src/is/not/lib/is-not-defined.func.ts | 10 +++++----- packages/type/src/is/not/lib/is-not-function.func.ts | 10 ++++++---- packages/type/src/is/not/lib/is-not-null.func.ts | 10 ++++++---- packages/type/src/is/not/lib/is-not-number.func.ts | 10 ++++++---- packages/type/src/is/not/lib/is-not-string.func.ts | 10 ++++++---- packages/type/src/is/not/lib/is-not-undefined.func.ts | 10 ++++++---- 9 files changed, 43 insertions(+), 33 deletions(-) diff --git a/packages/type/src/guard/lib/guard-function.func.ts b/packages/type/src/guard/lib/guard-function.func.ts index 1f8d6d15..85af962e 100644 --- a/packages/type/src/guard/lib/guard-function.func.ts +++ b/packages/type/src/guard/lib/guard-function.func.ts @@ -5,7 +5,7 @@ import { GuardFunction } from '../type/guard-function.type'; import { Func } from '../../type/func.type'; /** * Guard the `value` to be a `Func` type. - * @param value Type `Func` `value` to guard. - * @returns A `boolean` indicating whether or not the `value` is a `Func` type. + * @param value A `Func` type `value` to guard. + * @returns A `boolean` indicating whether or not the `value` is a `Func`. */ export const guardFunction: GuardFunction = (value: Func): value is Func => isFunction(value); diff --git a/packages/type/src/guard/lib/guard-object.func.ts b/packages/type/src/guard/lib/guard-object.func.ts index f22d4d00..0fe3a2fd 100644 --- a/packages/type/src/guard/lib/guard-object.func.ts +++ b/packages/type/src/guard/lib/guard-object.func.ts @@ -4,7 +4,7 @@ import { isObject } from '../../is/lib/is-object.func'; import { GuardObject } from '../type/guard-object.type'; /** * Guard the `value` to be an `object` of a generic `Obj` type. - * @param value A generic `Obj` type value to guard. + * @param value A generic `Obj` type `value` to guard. * @returns A `boolean` indicating whether or not the `value` is an `object` of a generic `Obj`. */ export const guardObject: GuardObject = (value: Obj): value is Obj => isObject(value); diff --git a/packages/type/src/is/not/lib/is-not-boolean.func.ts b/packages/type/src/is/not/lib/is-not-boolean.func.ts index d4b86a2b..92543c7a 100644 --- a/packages/type/src/is/not/lib/is-not-boolean.func.ts +++ b/packages/type/src/is/not/lib/is-not-boolean.func.ts @@ -1,11 +1,11 @@ +// Function. +import { typeOf } from '../../../lib/type-of.func'; // Type. import { IsNotBoolean } from '../type/is-not-boolean.type'; -import { typeOf } from '../../../lib/type-of.func'; /** - * Checks if an unknown `value` is NOT a `'boolean'` type, NOT equal to `true` or `false` and NOT instance of `Boolean`. - * @param value An unknown `value` to check if it's NOT a `'boolean'` type, - * NOT equal to `true` or `false` and NOT instance of `Boolean`. - * @returns boolean. + * Checks if an unknown `value` is NOT a `boolean` type, NOT equal to `true` or `false` and NOT instance of `Boolean`. + * @param value An unknown `value` to check. + * @returns A `boolean` indicating whether or not the `value` is not `boolean`. */ export const isNotBoolean: IsNotBoolean = (value: unknown): boolean => typeOf(value) !== 'boolean' && diff --git a/packages/type/src/is/not/lib/is-not-defined.func.ts b/packages/type/src/is/not/lib/is-not-defined.func.ts index 2a4c047d..54a1fd7e 100644 --- a/packages/type/src/is/not/lib/is-not-defined.func.ts +++ b/packages/type/src/is/not/lib/is-not-defined.func.ts @@ -1,11 +1,11 @@ +// Function. +import { typeOf } from '../../../lib/type-of.func'; // Type. import { IsNotDefined } from '../type/is-not-defined.type'; -import { typeOf } from '../../../lib/type-of.func'; - /** - * Checks if an unknown `value` is a `'undefined'` type and is equal to `undefined`. - * @param value An unknown `value` to check if it's an `'undefined'` type and is equal to `undefined`. - * @returns boolean. + * Checks if an unknown `value` is a `undefined` type and is equal to `undefined`. + * @param value An unknown `value` to check. + * @returns A `boolean` indicating whether or not the `value` is not defined. */ export const isNotDefined: IsNotDefined = (value: unknown): boolean => typeOf(value) === 'undefined' && diff --git a/packages/type/src/is/not/lib/is-not-function.func.ts b/packages/type/src/is/not/lib/is-not-function.func.ts index 6cd92485..fda68a8f 100644 --- a/packages/type/src/is/not/lib/is-not-function.func.ts +++ b/packages/type/src/is/not/lib/is-not-function.func.ts @@ -1,9 +1,11 @@ -import { IsNotFunction } from '../type/is-not-function.type'; +// Function. import { typeOf } from '../../../lib/type-of.func'; +// Type. +import { IsNotFunction } from '../type/is-not-function.type'; /** - * Checks if an unknown `value` is NOT a `'function'` type and NOT an instance of `Function`. - * @param value An unknown `value` to check if it's NOT a `'function'` type and NOT an instance of `Function`. - * @returns boolean. + * Checks if an unknown `value` is NOT a `function` type and NOT an instance of `Function`. + * @param value An unknown `value` to check. + * @returns A `boolean` indicating whether or not the `value` is not a `function`. */ export const isNotFunction: IsNotFunction = (value: unknown): boolean => typeOf(value) !== 'function' && diff --git a/packages/type/src/is/not/lib/is-not-null.func.ts b/packages/type/src/is/not/lib/is-not-null.func.ts index 49713731..1cbcdcd7 100644 --- a/packages/type/src/is/not/lib/is-not-null.func.ts +++ b/packages/type/src/is/not/lib/is-not-null.func.ts @@ -1,9 +1,11 @@ -import { IsNotNull } from '../type/is-not-null.type'; +// Function. import { typeOf } from '../../../lib/type-of.func'; +// Type. +import { IsNotNull } from '../type/is-not-null.type'; /** - * Checks if an unknown `value` is NOT a `'null'` type and NOT equal to `null`. - * @param value An unknown `value` to check if it's NOT a `'null'` type and NOT equal to `null`. - * @returns boolean + * Checks if an unknown `value` is NOT a `null` type and NOT equal to `null`. + * @param value An unknown `value` to check. + * @returns A `boolean` indicating whether or not the `value` is not `null`. */ export const isNotNull: IsNotNull = (value: unknown): boolean => typeOf(value) !== 'null' && diff --git a/packages/type/src/is/not/lib/is-not-number.func.ts b/packages/type/src/is/not/lib/is-not-number.func.ts index b668f67d..ac232589 100644 --- a/packages/type/src/is/not/lib/is-not-number.func.ts +++ b/packages/type/src/is/not/lib/is-not-number.func.ts @@ -1,9 +1,11 @@ -import { IsNotNumber } from '../type/is-not-number.type'; +// Function. import { typeOf } from '../../../lib/type-of.func'; +// Type. +import { IsNotNumber } from '../type/is-not-number.type'; /** - * Checks if an unknown `value` is NOT a `'number'` type and NOT an instance of `Number`. - * @param value An unknown value to check if it's NOT a `'number'` type, and NOT an instance of `Number`. - * @returns boolean + * Checks if any `value` is NOT a `number` type and NOT an instance of `Number`. + * @param value An unknown value to check. + * @returns A `boolean` indicating whether or not the `value` is not a `number`. */ export const isNotNumber: IsNotNumber = (value: any): boolean => typeOf(value) !== 'number' && diff --git a/packages/type/src/is/not/lib/is-not-string.func.ts b/packages/type/src/is/not/lib/is-not-string.func.ts index ec32371e..6abe382d 100644 --- a/packages/type/src/is/not/lib/is-not-string.func.ts +++ b/packages/type/src/is/not/lib/is-not-string.func.ts @@ -1,9 +1,11 @@ -import { IsNotString } from '../type/is-not-string.type'; +// Function. import { typeOf } from '../../../lib/type-of.func'; +// Type. +import { IsNotString } from '../type/is-not-string.type'; /** - * Checks if an unknown `value` is NOT a `'string'` type and NOT an instance of `String`. - * @param value An unknown `value` to check if it's NOT a `'string'` type and NOT an instance of `String`. - * @returns boolean. + * Checks if an unknown `value` is NOT a `string` type and NOT an instance of `String`. + * @param value An unknown `value` to check. + * @returns A `boolean` indicating whether or not the `value` is not a `string`. */ export const isNotString: IsNotString = (value: unknown): boolean => typeOf(value) !== 'string' && diff --git a/packages/type/src/is/not/lib/is-not-undefined.func.ts b/packages/type/src/is/not/lib/is-not-undefined.func.ts index 7333c595..2d78e874 100644 --- a/packages/type/src/is/not/lib/is-not-undefined.func.ts +++ b/packages/type/src/is/not/lib/is-not-undefined.func.ts @@ -1,9 +1,11 @@ -import { IsNotUndefined } from '../type/is-not-undefined.type'; +// Function. import { typeOf } from '../../../lib/type-of.func'; +// Type. +import { IsNotUndefined } from '../type/is-not-undefined.type'; /** - * Checks if an unknown `value` is NOT an `'undefined'` type and NOT equal to `undefined`. - * @param value An Unknown `value` to check if it's NOT an `'undefined'` type and NOT equal to `undefined`. - * @returns boolean. + * Checks if an unknown `value` is NOT an `undefined` type and NOT equal to `undefined`. + * @param value An unknown `value` to check. + * @returns A `boolean` indicating whether or not the `value` is not `undefined`. */ export const isNotUndefined: IsNotUndefined = (value: unknown): boolean => typeOf(value) !== 'undefined' && From 3d64d5e00abe558c22e369e848b28977f657c02c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 23:05:51 +0200 Subject: [PATCH 109/201] chore(is): export all features --- packages/type/src/is/index.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/type/src/is/index.ts b/packages/type/src/is/index.ts index 08dcb09f..99047c4c 100644 --- a/packages/type/src/is/index.ts +++ b/packages/type/src/is/index.ts @@ -2,16 +2,36 @@ export { isArray } from './lib/is-array.func'; export { isBigInt } from './lib/is-big-int.func'; export { isBoolean } from './lib/is-boolean.func'; +export { isBooleanObject } from './lib/is-boolean-object.func'; +export { isBooleanType } from './lib/is-boolean-type.func'; export { isDefined } from './lib/is-defined.func'; export { isFunction } from './lib/is-function.func'; export { isInstance } from './lib/is-instance.func'; -export { isNumber } from './lib/is-number.func'; +export { isKey } from './lib/is-key.func'; export { isNull } from './lib/is-null.func'; +export { isNumber } from './lib/is-number.func'; +export { isNumberObject } from './lib/is-number-object.func'; +export { isNumberType } from './lib/is-number-type.func'; export { isObject } from './lib/is-object.func'; +export { isObjectKey } from './lib/is-object-key.func'; export { isPrimitive } from './lib/is-primitive.func'; export { isString } from './lib/is-string.func'; +export { isStringObject } from './lib/is-string-object.func'; +export { isStringType } from './lib/is-string-type.func'; export { isSymbol } from './lib/is-symbol.func'; export { isType } from './lib/is-type.func'; export { isUndefined } from './lib/is-undefined.func'; -// `is` object with all above functions. +// `is` object. export { is } from './lib/is.object'; +// All `isNot` functions. +export { + isNotBoolean, + isNotDefined, + isNotFunction, + isNotNull, + isNotNumber, + isNotString, + isNotUndefined +} from './not'; +// `isNot`. +export { isNot } from './not'; From 618d556449431b3acb162dcfd657d4f1c0d6b2c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 23:06:25 +0200 Subject: [PATCH 110/201] refactor(GuardObjectKey): change param to `value` and extends `Obj` with `object` --- packages/type/src/guard/type/guard-object-key.type.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/guard/type/guard-object-key.type.ts b/packages/type/src/guard/type/guard-object-key.type.ts index dbcfc6c6..48b4fb46 100644 --- a/packages/type/src/guard/type/guard-object-key.type.ts +++ b/packages/type/src/guard/type/guard-object-key.type.ts @@ -1 +1 @@ -export type GuardObjectKey = (object: Obj, key: Key) => object is Obj; +export type GuardObjectKey = (value: Obj, key: Key) => value is Obj; From 9664350721b86bac9c46c6be0007eb809fda65e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 23:06:45 +0200 Subject: [PATCH 111/201] refactor(GuardFunction): change param name to `value` --- packages/type/src/guard/type/guard-function.type.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/guard/type/guard-function.type.ts b/packages/type/src/guard/type/guard-function.type.ts index 30071929..6a37aa45 100644 --- a/packages/type/src/guard/type/guard-function.type.ts +++ b/packages/type/src/guard/type/guard-function.type.ts @@ -1,2 +1,2 @@ import { Func } from '../../type/func.type'; -export type GuardFunction = (func: Func) => func is Func; +export type GuardFunction = (value: Func) => value is Func; From 9b67fb0c27d5981f94e62a9e9a4c74feb5a5416f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 23:07:02 +0200 Subject: [PATCH 112/201] chore: categorize imports --- packages/type/src/guard/lib/guard-is.object.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/type/src/guard/lib/guard-is.object.ts b/packages/type/src/guard/lib/guard-is.object.ts index 2d10715f..b0a53672 100644 --- a/packages/type/src/guard/lib/guard-is.object.ts +++ b/packages/type/src/guard/lib/guard-is.object.ts @@ -1,4 +1,4 @@ -import { GuardIs } from '../interface/guard-is.interface'; +// Function. import { guardArray } from './guard-array.func'; import { guardFunction } from './guard-function.func'; import { guardNumber } from './guard-number.func'; @@ -8,7 +8,9 @@ import { guardPrimitive } from './guard-primitive.func'; import { guardString } from './guard-string.func'; import { guardType } from './guard-type.func'; import { guardKey } from './guard-key.func'; - +// Interface. +import { GuardIs } from '../interface/guard-is.interface'; +// Object. export const guardIs: GuardIs = { // TODO: add other guards etc. boolean, null, undefined array: guardArray, From c2ab3300e4429dbd92acd7dd271f5cb794c25de6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 23:08:05 +0200 Subject: [PATCH 113/201] chore: update jsdoc, prettier code --- packages/type/src/guard/lib/guard-primitive.func.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/type/src/guard/lib/guard-primitive.func.ts b/packages/type/src/guard/lib/guard-primitive.func.ts index 78aa9dae..94ba710e 100644 --- a/packages/type/src/guard/lib/guard-primitive.func.ts +++ b/packages/type/src/guard/lib/guard-primitive.func.ts @@ -5,10 +5,10 @@ import { GuardPrimitive } from '../type/guard-primitive.type'; import { Primitive } from '../../type/primitive.type'; import { Primitives } from '../../type/primitives.type'; /** - * Guard the `value` to be the `Type` from the `Primitives`. - * @param value A generic `Type` `value` to guard. - * @param type One of the `Primitives` to check the `value`. - * @returns A `boolean` indicating whether or not the `value` is the `Type` from the `Primitives`. + * Guard the `value` to be the `Primitive` from a `type` of the `Primitives`. + * @param value A `Primitive` type `value` to guard. + * @param type A `string` type from the `Primitives` to check the `value`. + * @returns A `boolean` indicating whether or not the `value` is the `Primitive` from the `type`. */ -export const guardPrimitive: GuardPrimitive = (value: Type, type: Primitives): value is Type => - isPrimitive(value, type); +export const guardPrimitive: GuardPrimitive = + (value: Type, type: Primitives): value is Type => isPrimitive(value, type); From ce591c8c49006e925edaaabc537555a56179cc9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 23:08:32 +0200 Subject: [PATCH 114/201] refactor(guardType): use `Type` instead of generic, update jsdoc --- packages/type/src/guard/lib/guard-type.func.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/type/src/guard/lib/guard-type.func.ts b/packages/type/src/guard/lib/guard-type.func.ts index d9e77718..2e20cec4 100644 --- a/packages/type/src/guard/lib/guard-type.func.ts +++ b/packages/type/src/guard/lib/guard-type.func.ts @@ -1,10 +1,13 @@ +// Function. import { isType } from '../../is/lib/is-type.func'; +// Type. import { GuardType } from '../type/guard-type.type'; +import { Type } from '../../type/type.type'; import { Types } from '../../type/types.type'; /** - * Guard the `value` to be a generic `Type` type from one of the `Types` type. - * Use `isType()` function for check ONLY. - * @param value A generic `Type` value to guard. - * @param type Constructor generic `Type`, `'function'`, `'object'` or one of the `Primitives` `'boolean'`, `'bigint'`, `'number'`, `'string'`, `'symbol'`, `'undefined'` to check `value`. + * Guard the `value` to be the `Type` from a `type` of the `Types`. + * @param value A `Type` `value` to guard with the `type`. + * @param type A type from the `Types` to check the `value`. + * @returns A `boolean` indicating whether or not the `value` is a type from the `Types`. */ -export const guardType: GuardType = (value: Type, type: Types): value is Type => isType(value, type); +export const guardType: GuardType = (value: T, type: Types): value is T => isType(value, type); From a37001bb0c846c30baa74561c9c94f997127c898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 23:09:04 +0200 Subject: [PATCH 115/201] refactor(guardObjectKey): extends `Obj` with `object` , update `value` jsdoc --- packages/type/src/guard/lib/guard-object-key.func.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/type/src/guard/lib/guard-object-key.func.ts b/packages/type/src/guard/lib/guard-object-key.func.ts index 3f872e00..f0a13ce6 100644 --- a/packages/type/src/guard/lib/guard-object-key.func.ts +++ b/packages/type/src/guard/lib/guard-object-key.func.ts @@ -5,9 +5,9 @@ import { isKey } from '../../is/lib/is-key.func'; import { GuardObjectKey } from '../type/guard-object-key.type'; /** * Guard the `value` to be an `object` of a generic `Obj` type that contains the `key` property of the `Key` type. - * @param value A generic `Obj` type `value` that contains the `key` property to guard. + * @param value A generic `Obj` type `value` that contains the `key` to guard. * @param key A `Key` type name of the property that the `object` contains. * @returns A `boolean` indicating whether or not the `value` is an `object` of a generic `Obj` containing the `Key`. */ -export const guardObjectKey: GuardObjectKey = (value: Obj, key: Key): value is Obj => +export const guardObjectKey: GuardObjectKey = (value: Obj, key: Key): value is Obj => guardObject(value) ? isKey(key) ? key in value : true : false; From c84c27002b205137e159b13e223f8df6072fddfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 23:09:22 +0200 Subject: [PATCH 116/201] docs(README.md): update --- README.md | 280 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 191 insertions(+), 89 deletions(-) diff --git a/README.md b/README.md index 7696f2c5..a911c182 100644 --- a/README.md +++ b/README.md @@ -129,14 +129,14 @@ Guard ---- * [Installation](#installation) -* [Object](#are-object) - * [`are`](#are-object) - * [`guard`](#guard-object) - * [`is`](#is-object) -* [Checks](#checks) +* [Object](#objects) + * [`are`](#are) + * [`guard`](#guard) + * [`is`](#is) +* [Check](#check) * [are](#areString) * [is](#isArray) -* [Guards](#guards) +* [Guard](#guard) * [Types](#types) * [Git](#git) * [Commit](#commit) @@ -153,7 +153,9 @@ Install `@angular-package/type` package with command: npm i --save @angular-package/type ``` -## are Object +## Object + +### are Object `are` with some of **check are** functions. @@ -163,7 +165,7 @@ const are: Are = { }; ``` -## guard Object +### guard Object `guard` with all **guard** functions. @@ -184,30 +186,40 @@ const guard: Guard = { ``` -## is Object +### is Object `is` with all **check is** functions and **check is not** in `not` property. ```typescript const is: Is = { array: isArray, - bigInt: isBigInt, + bigInt: isBigInt, // deprecated + bigint: isBigInt, boolean: isBoolean, + booleanObject: isBooleanObject, + booleanType: isBooleanType, defined: isDefined, function: isFunction, + instance: isInstance, + key: isKey, not: isNot, null: isNull, number: isNumber, + numberObject: isNumberObject, + numberType: isNumberType, object: isObject, + objectKey: isObjectKey, primitive: isPrimitive, string: isString, + stringObject: isStringObject, + stringType: isStringType, symbol: isSymbol, type: isType, undefined: isUndefined }; ``` -## isNot Object +## isNot Object `isNot` with all **check is not** functions. @@ -231,7 +243,7 @@ Default function to handle `callback` parameter. const errorCallback: ResultCallback = (result: boolean): boolean => result; ``` -## Checks +## Check ### areString @@ -352,7 +364,7 @@ const isBooleanObject: IsBooleanObject = (value: any, callback: ResultCallback = | Parameter | Type | Description | | :---------| :---: | :---------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback) = [`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a [`Boolean`][Boolean] instance. @@ -384,7 +396,7 @@ const isBooleanType: IsBooleanType = (value: any, callback: ResultCallback = err | Parameter | Type | Description | | :---------| :---: | :---------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback) = [`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `boolean` type. @@ -508,7 +520,7 @@ const isKey: IsKey = (value: any): value is Key => isString(value) || isNumber(v | :-------- | :---: |:----------- | | value | `any` | Any `value` to check | -The **return value** is a `boolean` indicating whether or not the `value` is a [`Key`](#Key) type. +The **return value** is a `boolean` indicating whether or not the `value` is a [`Key`](#Key). ---- @@ -563,6 +575,42 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` ---- +### isNumberObject + +Use `isNumberObject()` or `is.numberObject()` to check if **any** `value` is an `object` type an instance of [`Number`][Number] and [`Object`][Object]. + +```typescript +const isNumberObject: IsNumberObject = (value: any, callback: ResultCallback = errorCallback): value is number => + callback(typeof value === 'object' && value instanceof Number === true && value instanceof Object === true); +``` + +| Parameter | Type | Description | +| :-------- | :---: | :---------- | +| value | `any` | Any `value` to check | + +The **return value** is a `boolean` indicating whether or not the `value` is a [`Number`][Number] instance. + +---- + +### isNumberType + +Use `isNumber()` or `is.number()` to check if **any** `value` is a `number` type not an instance of `Number` and `Object` or `object` type instance of `Number` and `Object`. + +```typescript +const isNumber: IsNumber = (value: any): value is number => + typeOf(value) === 'number' && + isFinite(value) === true && + (isNumberObject(value) || isNumberType(value)); +``` + +| Parameter | Type | Description | +| :-------- | :---: | :---------- | +| value | `any` | Any `value` to check | + +The **return value** is a `boolean` indicating whether or not the `value` is a `number`. + +---- + ### isObject Use `isObject()` or `is.object()` to check if **any** `value` is a generic `Obj` `object` type and `Object` instance with the possibility of containing the `key`. @@ -613,10 +661,10 @@ The **return value** is a `boolean` indicating whether or not the `object` has i ### isPrimitive -Use `isPrimitive()` or `is.primitive()` to check if **any** `value` is a generic `Type` from the [`Primitives`](#Primitives). +Use `isPrimitive()` or `is.primitive()` to check if **any** `value` is a [`Primitive`](#Primitive) type from the `type` of the [`Primitives`](#Primitives) type. ```typescript -const isPrimitive: IsPrimitive = (value: any, type: Primitives): value is Type => { +const isPrimitive: IsPrimitive = (value: any, type: Primitives): value is T => { if (isString(type)) { switch (type) { case 'bigint': return isBigInt(value); @@ -634,10 +682,10 @@ const isPrimitive: IsPrimitive = (value: any, type: Primitives): value is | Parameter | Type | Description | | :-------- | :-------------------------: | :---------- | -| value | `any` | Any `value` to check if it's a generic `Type` from the `type` | -| type | [`Primitives`](#Primitives) | Name of the type from the [`Primitives`](#Primitives) to check the `value` | +| value | `any` | Any `value` to check if it's a `Primitive` from the `type` | +| type | [`Primitives`](#Primitives) | A `string` name of the type from the [`Primitives`](#Primitives) to check the `value` | -The **return value** is a `boolean` indicating whether or not the `value` is a type from the [`Primitives`](#Primitives). +The **return value** is a `boolean` indicating whether or not the `value` is a `type` from the [`Primitives`](#Primitives). [Example usage on playground][is-primitive] @@ -659,27 +707,41 @@ const isString: IsString = (value: any, callback: ResultCallback = errorCallback The **return value** is a `boolean` indicating whether or not the `value` is a `string`. -[Example usage on playground][is-string] | [How to detect `string` type][detect-string] - ---- ### isStringObject -Use `isStringObject()` or `is.stringObject()` to check if **any** `value` is a `string` type, not instance of [`Object`][Object] and [`String`][String] or `object` type and instance of [`String`][String] and [`Object`][Object]. +Use `isStringObject()` or `is.stringObject()` to check if **any** `value` is an `object` type and instance of [`String`][String] and [`Object`][Object]. ```typescript -const isString: IsString = (value: any, callback: ResultCallback = errorCallback): value is string => - callback(typeOf(value) === 'string' && (isStringObject(value) || isStringType(value))); +const isStringObject: IsStringObject = (value: any, callback: ResultCallback = errorCallback): value is string => + callback(value instanceof Object === true && value instanceof String === true && typeof value === 'object'); ``` | Parameter | Type | Description | | :-------- | :---------------------------------: | :---------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a [`String`][String] instance. + +---- + +### isStringType + +Use `isStringObject()` or `is.stringObject()` to check if **any** `value` is a `string` type and **not** instance of [`String`][String] and [`Object`][Object]. + +```typescript +const isStringType: IsStringType = (value: any, callback: ResultCallback = errorCallback): value is string => + callback(value instanceof Object === false && value instanceof String === false && typeof value === 'string'); +``` -The **return value** is a `boolean` indicating whether or not the `value` is an instance of a [`String`][String]. +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :---------- | +| value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | -[Example usage on playground][is-string] | [How to detect `string` type][detect-string] +The **return value** is a `boolean` indicating whether or not the `value` is a `string`. ---- @@ -703,21 +765,12 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` ---- -### isStringType - -```typescript -const isStringType: IsStringType = (value: any, callback: ResultCallback = errorCallback): value is string => - callback(value instanceof Object === false && value instanceof String === false && typeof value === 'string'); -``` - ----- - ### isType -Use `isType()` or `is.type()` to check if **any** `value` is a generic `Type` from the [`Types`](#Types). +Use `isType()` or `is.type()` to check if **any** `value` is a [`Type`](#Type) from the `type` of the [`Types`](#Types) type. ```typescript -const isType: IsType = (value: any, type: Types): value is Type => { +const isType: IsType = (value: any, type: Types): value is T => { if (isString(type)) { switch (type) { // Primitives. @@ -731,10 +784,10 @@ const isType: IsType = (value: any, type: Types): value is Type => { // Function. case 'function': return isFunction(value); // Object. - case 'object': return isObject(value); + case 'object': return isObject(value); } } else if (isNotNull(type)) { - return isInstance(value, type); + return isInstance(value, type); } return false; }; @@ -743,9 +796,9 @@ const isType: IsType = (value: any, type: Types): value is Type => { | Parameter | Type | Description | | :-------- | :---------------------: | :---------- | | value | `any` | Any `value` to check if its type is from the `type` | -| type | [`Types`](#Types) | One type from the `Types` to check the `value` | +| type | [`Types`](#Types) | A `string` or generic `Constructor` type from the [`Types`](#Types) to check the `value` | -The **return value** is a `boolean` indicating whether or not the `value` is a type from the [`Types`](#Types). +The **return value** is a `boolean` indicating whether or not the `value` is a [`Type`](#Type) from the `type` of the [`Types`](#Types). [Example usage on playground][is-type] @@ -893,11 +946,11 @@ const isNotUndefined: IsNotUndefined = (value: unknown): boolean => |-----------| :-------: |-------------| | value | `unknown` | An Unknown `value` to check. | -## Guards +## Guard ### guardArray -Use `guardArray()` or `guard.is.array()` to guard the `value` to be a generic `Array` `Type`. The return value is a `boolean` value. +Use `guardArray()` or `guard.is.array()` to guard the `value` to be an [`Array`][Array] of a generic `Type`. ```typescript const guardArray: GuardArray = (value: Array): value is Array => isArray(value); @@ -905,31 +958,51 @@ const guardArray: GuardArray = (value: Array): value is Array | Parameter | Type | Description | |-----------| :-----------: |-------------| -| value | `Array` | Array generic `Type` type `value` to guard. | +| value | `Array` | A generic `Type` `Array` `value` to guard | + +The return value is a `boolean` indicating whether or not the `value` is an [`Array`][Array] of a generic `Type`. -[Example usage][guard-array] +[Example usage on playground][guard-array] ---- ### guardFunction -Use `guardFunction()` or `guard.is.function()` to guard the `func` value to be a `Func` type. The return value is a `boolean` value. +Use `guardFunction()` or `guard.is.function()` to guard the `value` to be a [`Func`](#Func) type. ```typescript -const guardFunction: GuardFunction = (func: Func): func is Func => isFunction(func); +const guardFunction: GuardFunction = (value: Func): value is Func => isFunction(value); ``` -| Parameter | Type | Description | -|-----------| :----: |--------------| -| func | `Func` | Type `Func` value to guard. | +| Parameter | Type | Description | +| :-------- | :-------------: | :---------------------------------- | +| value | [`Func`](#Func) | A [`Func`](#Func) type `value` to guard | -[Example usage][guard-function] +The return value is a `boolean` indicating whether or not the `value` is a [`Func`](#Func). + +[Example usage on playground][guard-function] + +---- + +### guardKey + +Use `guardKey()` or `guard.is.key()` to guard the `value` to be one of the `string`, `number`, or `symbol`. + +```typescript +const guardKey: GuardKey = (value: Key): value is Key => isKey(value); +``` + +| Parameter | Type | Description | +| :-------- | :-----------: | :---------- | +| value | [`Key`](#Key) | A [`Key`](#Key) type `value` to guard | + +The **return value** is a `boolean` indicating whether or not the `value` is a [`Key`](#Key). ---- ### guardNumber -Use `guardNumber()` or `guard.is.number()` to guard the `value` to be a `number` type. The return value is a `boolean` value. +Use `guardNumber()` or `guard.is.number()` to guard the `value` to be a `number`. ```typescript const guardNumber: GuardNumber = (value: number): value is number => isNumber(value); @@ -937,93 +1010,103 @@ const guardNumber: GuardNumber = (value: number): value is number => isNumber(va | Parameter | Type | Description | |-----------| :------: |--------------| -| value | `number` | Type `number` value to guard. | +| value | `number` | A `number` type `value` to guard. | -[Example usage][guard-number] +The **return value** is a `boolean` indicating whether or not the `value` is a `number`. + +[Example usage on playground][guard-number] ---- ### guardObject -Use `guardObject()` or `guard.is.object()` to guard the `object` value to be a generic `Obj` type. The return value is a `boolean` value. +Use `guardObject()` or `guard.is.object()` to guard the `value` to be an `object` of a generic `Obj` type. ```typescript -const guardObject: GuardObject = (object: Obj): object is Obj => isObject(object); +const guardObject: GuardObject = (value: Obj): value is Obj => isObject(value); ``` -| Parameter | Type | Description | -|-----------| :---: |-------------| -| object | `Obj` | Generic `Obj` type value to guard. | +| Parameter | Type | Description | +| :-------- | :--------------------: | :---------- | +| value | `Obj` extends `object` | A generic `Obj` type `value` to guard | + +The **return value** is a `boolean` indicating whether or not the `value` is an `object` of a generic `Obj`. -[Example usage][guard-object] +[Example usage on playground][guard-object] ---- ### guardObjectKey -Use `guardObjectKey()` or `guard.is.objectKey()` to guard the `object` to be a generic `Obj` type and to contains the `key` property. The return value is a `boolean` value. +Use `guardObjectKey()` or `guard.is.objectKey()` to guard the `value` to be an `object` of a generic `Obj` type that contains the `key` property of the [`Key`](#Key) type. ```typescript -const guardObjectKey: GuardObjectKey = (object: Obj, key: Key): object is Obj => - guardObject(object) ? isString(key) ? key in object : true : false; +const guardObjectKey: GuardObjectKey = (value: Obj, key: Key): value is Obj => + guardObject(value) ? isKey(key) ? key in value : true : false; ``` -| Parameter | Type | Description | -|-------------| :---: |---------------| -| object | `Obj` | Generic `Obj` type `value` that contains the `key` property to guard. | -| key | `Key` | Name of the property that the `object` contains. | +| Parameter | Type | Description | +| :-----------| :-----------: | :------------ | +| value | `Obj` | A generic `Obj` type `value` that contains the `key` to guard | +| key | `Key` | A `Key` type name of the property that the `object` contains | + +The **return value** is a `boolean` indicating whether or not the `value` is an `object` of a generic `Obj` containing the `Key`. -[Example usage][guard-object-key] +[Example usage on playground][guard-object-key] ---- ### guardPrimitive -Use `guardPrimitive()` or `guard.is.primitive()` to guard the `value` to be a generic `Type` from one of the `Primitives`. The return value is a `boolean` value. +Use `guardPrimitive()` or `guard.is.primitive()` to guard the `value` to be the [`Primitive`](#Primitive) from a `type` of the [`Primitives`](#Primitives). ```typescript -const guardPrimitive: GuardPrimitive = (value: Type, type: Primitives): value is Type => isPrimitive(value, type); +const guardPrimitive: GuardPrimitive = (value: Type, type: Primitives): value is Type => isPrimitive(value, type); ``` -| Parameter | Type | Description | -|-------------| :----------: |--------------| -| value | `Type` | A generic `Type` type `value` to guard. | -| type | `Primitives` | One of the `Primitives` `'boolean'`, `'bigint'`, `'number'`, `'string'`, `'symbol'`, `'undefined'` to check `value`. | +| Parameter | Type | Description | +| :---------- | :--------------------------------------: | :---------- | +| value | `Type` extends [`Primitive`](#Primitive) | A `Primitive` type `value` to guard | +| type | [`Primitives`](#Primitives) | A `string` type from the [`Primitives`](#Primitives) to check the `value` | -[Example usage][guard-primitive] +The return value is a `boolean` indicating whether or not the `value` is the [`Primitive`](#Primitive) from the `type`. + +[Example usage on playground][guard-primitive] ---- ### guardString -Use `guardString()` or `guard.is.string()` to guard the `value` to be a `string` type. The return value is a `boolean` value. +Use `guardString()` or `guard.is.string()` to guard the `value` to be a `string`. ```typescript const guardString: GuardString = (value: string): value is string => isString(value); ``` -| Parameter | Type | Description | -|-------------| :---: |---------------| -| value | `string` | String type value to guard. | +| Parameter | Type | Description | +|-------------| :------: |---------------| +| value | `string` | A `string` type `value` to guard | + +The return value is a `boolean` indicating whether or not the `value` is a `string`. -[Example usage][guard-string] +[Example usage on playground][guard-string] ---- ### guardType -Use `guardType()` or `guard.is.type()` to guard the `value` to be a generic `Type` type from the `Types` type. +Use `guardType()` or `guard.is.type()` to guard the `value` to be the [`Type`](#Type) from a `type` of the [`Types`](#Types). ```typescript -const guardType: GuardType = (value: Type, type: Types): value is Type => isType(value, type); +const guardType: GuardType = (value: T, type: Types): value is T => isType(value, type); ``` -| Parameter | Type | Description | -|-------------| :---: |---------------| -| value | `Type` | A generic `Type` `value` to guard. | -| type | `Types` | Constructor generic `Type`, `'function'`, `'object'` or one of the `Primitives` `'boolean'`, `'bigint'`, `'number'`, `'string'`, `'symbol'`, `'undefined'` to check `value`. | +| Parameter | Type | Description | +| :-------- | :-------------------------: | :---------- | +| value | `T` extends [`Type`](#Type) | A [`Type`](#Type) `value` to guard with the `type` | +| type | [`Types`](#Types) | A type from the [`Types`](#Types) to check the `value` | -The return value is a `boolean` value. +The return value is a `boolean` indicating whether or not the `value` is a `type` from the [`Types`](#Types). [Example usage on playground][guard-type] @@ -1044,24 +1127,32 @@ type CycleHook = 'ngAfterContentInit' | 'ngAfterContentChecked' | 'ngAfterViewIn ### Func +Function type. + ```typescript type Func = (...param: any) => any; ``` ### Key +Name of the `object` property. + ```typescript type Key = number | string | symbol; ``` ### Primitive +All [`Primitive`][Primitive] types. + ```typescript type Primitive = bigint | boolean | null | number | string | symbol | undefined; ``` ### Primitives +All [`Primitive`](#Primitive) types as `string`. + ```typescript type Primitives = 'bigint' | 'boolean' | 'null' | 'number' | 'symbol' | 'string' | 'undefined'; ``` @@ -1072,8 +1163,18 @@ type Primitives = 'bigint' | 'boolean' | 'null' | 'number' | 'symbol' | 'string' type ResultCallback = (result: boolean) => boolean; ``` +### Type + +Main types. + +```typescript +type Type = Func | object | Primitive; +``` + ### Types +Main types as `string`. + ```typescript type Types = Constructor | 'function' | 'object' | Primitives; ``` @@ -1114,6 +1215,7 @@ MIT © angular-package ([license](https://github.com/angular-package/type/blob/m [Boolean]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean [Function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions [Object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object +[Primitive]: https://developer.mozilla.org/en-US/docs/Glossary/Primitive [String]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String [new]: https://img.shields.io/badge/-new-red From 04a5ae5564e1c266d8fe32cf37d88d233a1e3621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 23:11:20 +0200 Subject: [PATCH 117/201] docs(README.md): fix table of contents --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a911c182..b2ee5e15 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ Guard ---- * [Installation](#installation) -* [Object](#objects) +* [Object](#object) * [`are`](#are) * [`guard`](#guard) * [`is`](#is) @@ -137,7 +137,7 @@ Guard * [are](#areString) * [is](#isArray) * [Guard](#guard) -* [Types](#types) +* [Common types](#common-types) * [Git](#git) * [Commit](#commit) * [Versioning](#versioning) From 10bd067f7aafa71af17b0d2711e16fd0eb5f3a13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 23:30:20 +0200 Subject: [PATCH 118/201] docs: update --- README.md | 22 +++++++++---------- .../type/src/guard/lib/guard-type.func.ts | 2 +- packages/type/src/is/lib/is-primitive.func.ts | 2 +- packages/type/src/is/lib/is-type.func.ts | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index b2ee5e15..aa1e1f75 100644 --- a/README.md +++ b/README.md @@ -335,7 +335,7 @@ const isBoolean: IsBoolean = (value: any, callback: ResultCallback = errorCallba | Parameter | Type | Description | | :---------| :---: | :---------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback) = [`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `boolean`. @@ -661,7 +661,7 @@ The **return value** is a `boolean` indicating whether or not the `object` has i ### isPrimitive -Use `isPrimitive()` or `is.primitive()` to check if **any** `value` is a [`Primitive`](#Primitive) type from the `type` of the [`Primitives`](#Primitives) type. +Use `isPrimitive()` or `is.primitive()` to check if **any** `value` is the [`Primitive`](#Primitive) type from a `type` of the [`Primitives`](#Primitives) type. ```typescript const isPrimitive: IsPrimitive = (value: any, type: Primitives): value is T => { @@ -736,7 +736,7 @@ const isStringType: IsStringType = (value: any, callback: ResultCallback = error callback(value instanceof Object === false && value instanceof String === false && typeof value === 'string'); ``` -| Parameter | Type | Description | +| Parameter | Type | Description | | :-------- | :---------------------------------: | :---------- | | value | `any` | Any `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -767,7 +767,7 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` ### isType -Use `isType()` or `is.type()` to check if **any** `value` is a [`Type`](#Type) from the `type` of the [`Types`](#Types) type. +Use `isType()` or `is.type()` to check if **any** `value` is the [`Type`](#Type) from a `type` of the [`Types`](#Types) type. ```typescript const isType: IsType = (value: any, type: Types): value is T => { @@ -793,12 +793,12 @@ const isType: IsType = (value: any, type: Types): value is T }; ``` -| Parameter | Type | Description | -| :-------- | :---------------------: | :---------- | -| value | `any` | Any `value` to check if its type is from the `type` | -| type | [`Types`](#Types) | A `string` or generic `Constructor` type from the [`Types`](#Types) to check the `value` | +| Parameter | Type | Description | +| :-------- | :------------------: | :---------- | +| value | `any` | Any `value` to check if its type is from the `type` | +| type | [`Types`](#Types) | A `string` or generic `Constructor` type from the [`Types`](#Types) to check the `value` | -The **return value** is a `boolean` indicating whether or not the `value` is a [`Type`](#Type) from the `type` of the [`Types`](#Types). +The **return value** is a `boolean` indicating whether or not the `value` is the [`Type`](#Type) from a `type` of the [`Types`](#Types). [Example usage on playground][is-type] @@ -1104,13 +1104,13 @@ const guardType: GuardType = (value: T, type: Types): value i | Parameter | Type | Description | | :-------- | :-------------------------: | :---------- | | value | `T` extends [`Type`](#Type) | A [`Type`](#Type) `value` to guard with the `type` | -| type | [`Types`](#Types) | A type from the [`Types`](#Types) to check the `value` | +| type | [`Types`](#Types) | A `string` or generic [`Constructor`](#Constructor) type from the [`Types`](#Types) to check the `value` | The return value is a `boolean` indicating whether or not the `value` is a `type` from the [`Types`](#Types). [Example usage on playground][guard-type] -## Common Types +## Common types ### Constructor diff --git a/packages/type/src/guard/lib/guard-type.func.ts b/packages/type/src/guard/lib/guard-type.func.ts index 2e20cec4..4c6d60b8 100644 --- a/packages/type/src/guard/lib/guard-type.func.ts +++ b/packages/type/src/guard/lib/guard-type.func.ts @@ -7,7 +7,7 @@ import { Types } from '../../type/types.type'; /** * Guard the `value` to be the `Type` from a `type` of the `Types`. * @param value A `Type` `value` to guard with the `type`. - * @param type A type from the `Types` to check the `value`. + * @param type A `string` or generic `Constructor` type from the `Types` to check the `value`. * @returns A `boolean` indicating whether or not the `value` is a type from the `Types`. */ export const guardType: GuardType = (value: T, type: Types): value is T => isType(value, type); diff --git a/packages/type/src/is/lib/is-primitive.func.ts b/packages/type/src/is/lib/is-primitive.func.ts index 4a4f3f06..4bba61bf 100644 --- a/packages/type/src/is/lib/is-primitive.func.ts +++ b/packages/type/src/is/lib/is-primitive.func.ts @@ -11,7 +11,7 @@ import { IsPrimitive } from '../type/is-primitive.type'; import { Primitive } from '../../type/primitive.type'; import { Primitives } from '../../type/primitives.type'; /** - * Checks if any `value` is a `Primitive` type from the `type` of the `Primitives` type. + * Checks if any `value` is the `Primitive` type from a `type` of the `Primitives` type. * @param value Any `value` to check if it's a `Primitive` from the `type`. * @param type A `string` name of the `type` from the `Primitives` to check the `value`. * @returns A `boolean` indicating whether or not the `value` is a `type` from the `Primitives`. diff --git a/packages/type/src/is/lib/is-type.func.ts b/packages/type/src/is/lib/is-type.func.ts index 5509c4e8..67e7cf4a 100644 --- a/packages/type/src/is/lib/is-type.func.ts +++ b/packages/type/src/is/lib/is-type.func.ts @@ -10,10 +10,10 @@ import { Type } from '../../type/type.type'; import { Types } from '../../type/types.type'; import { isNotNull } from '../not/lib/is-not-null.func'; /** - * Checks if any `value` is a `Type` from the `type` of the `Types` type. + * Checks if any `value` is the `Type` from a `type` of the `Types` type. * @param value Any `value` to check if its type is from the `type`. * @param type A `string` or generic `Constructor` type from the `Types` to check the `value`. - * @returns A `boolean` indicating whether or not the `value` is a `Type` from the `type` of the `Types`. + * @returns A `boolean` indicating whether or not the `value` is the `Type` from a `type` of the `Types`. */ export const isType: IsType = (value: any, type: Types): value is T => { if (isString(type)) { From e2c2611e4da14de5a7255f63be6711b1d451b7a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 23:42:06 +0200 Subject: [PATCH 119/201] refactor(IsObjectKey): change param name to `value` --- packages/type/src/is/type/is-object-key.type.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/is/type/is-object-key.type.ts b/packages/type/src/is/type/is-object-key.type.ts index e1961aa6..dc5e6763 100644 --- a/packages/type/src/is/type/is-object-key.type.ts +++ b/packages/type/src/is/type/is-object-key.type.ts @@ -1,2 +1,2 @@ import { Key } from '../../type/key.type'; -export type IsObjectKey = (object: any, key: Key | Key[]) => object is Type; +export type IsObjectKey = (value: any, key: Key | Key[]) => value is Type; From 1fe1841654e32f190a5e9963f237f63cb1ffc356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 23:42:45 +0200 Subject: [PATCH 120/201] refactor(isObjectKey): change param name to `value`, extends Type with `object` and update jsdoc --- packages/type/src/is/lib/is-object-key.func.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/type/src/is/lib/is-object-key.func.ts b/packages/type/src/is/lib/is-object-key.func.ts index 615bf628..05a28a25 100644 --- a/packages/type/src/is/lib/is-object-key.func.ts +++ b/packages/type/src/is/lib/is-object-key.func.ts @@ -6,16 +6,16 @@ import { isObject } from './is-object.func'; import { IsObjectKey } from '../type/is-object-key.type'; import { Key } from '../../type/key.type'; /** - * Checks if any `object` has its own specified keys of the `Key` type. - * @param object Any `object` to check if it contains a specified `key`. - * @param key `Key` type or an array of `Key` type to check. - * @returns A `boolean` indicating whether or not the `object` has its own specified keys. + * Checks if any `value` is an `object` with its own specified keys of the `Key` type. + * @param value Any `value` to check if it contains a specified `key`. + * @param key A `Key` type or an array of `Key` type to check the `value`. + * @returns A `boolean` indicating whether or not the `value` has its own specified keys. */ -export const isObjectKey: IsObjectKey = (object: any, key: Key | Key[]): object is Type => - isObject(object) ? +export const isObjectKey: IsObjectKey = (value: any, key: Key | Key[]): value is Type => + isObject(value) ? isArray(key) ? - key.every(k => isKey(k) ? ({}).hasOwnProperty.call(object, k) === true : false) + key.every(k => isKey(k) ? ({}).hasOwnProperty.call(value, k) === true : false) : isKey(key) ? - ({}).hasOwnProperty.call(object, key) + ({}).hasOwnProperty.call(value, key) : false : false; From 12863e5f76a57634a37dd5af79f8d6e442260081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 26 Apr 2021 23:42:58 +0200 Subject: [PATCH 121/201] docs(README.md): update --- README.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index aa1e1f75..ffc6d5fd 100644 --- a/README.md +++ b/README.md @@ -594,7 +594,7 @@ The **return value** is a `boolean` indicating whether or not the `value` is a [ ### isNumberType -Use `isNumber()` or `is.number()` to check if **any** `value` is a `number` type not an instance of `Number` and `Object` or `object` type instance of `Number` and `Object`. +Use `isNumber()` or `is.number()` to check if **any** `value` is a `number` type not an instance of [`Number`][Number] and [`Object`][Object] or `object` type instance of [`Number`][Number] and [`Object`][Object]. ```typescript const isNumber: IsNumber = (value: any): value is number => @@ -613,7 +613,7 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` ### isObject -Use `isObject()` or `is.object()` to check if **any** `value` is a generic `Obj` `object` type and `Object` instance with the possibility of containing the `key`. +Use `isObject()` or `is.object()` to check if **any** `value` is a generic `Obj` `object` type and [`Object`][Object] instance with the possibility of containing the `key`. ```typescript const isObject: IsObject = (value: any, key?: Key): value is Obj => @@ -637,25 +637,25 @@ The **return value** is a `boolean` indicating whether or not the `value` is an ### isObjectKey -Use `isObject()` or `is.object()` to check if **any** `object` has its own specified keys of the [`Key`](#Key). +Use `isObject()` or `is.object()` to check if **any** `value` is an `object` with its own specified keys of the [`Key`](#Key). ```typescript -const isObjectKey: IsObjectKey = (object: any, key: Key | Key[]): object is Type => - isObject(object) ? +const isObjectKey: IsObjectKey = (value: any, key: Key | Key[]): value is Type => + isObject(value) ? isArray(key) ? - key.every(k => isKey(k) ? ({}).hasOwnProperty.call(object, k) === true : false) + key.every(k => isKey(k) ? ({}).hasOwnProperty.call(value, k) === true : false) : isKey(key) ? - ({}).hasOwnProperty.call(object, key) + ({}).hasOwnProperty.call(value, key) : false : false; ``` | Parameter | Type | Description | | :-------- | :------------------------------: | :---------- | -| object | `any` | Any `object` to check | -| key | [`Key`](#key) \| [`Key`](#Key)[] | Property name to find in `object` | +| value | `any` | Any `value` to check if it contains a specified `key` | +| key | [`Key`](#key) \| [`Key`](#Key)[] | A [`Key`](#Key) type or an array of [`Key`](#Key) type to check the `value` | -The **return value** is a `boolean` indicating whether or not the `object` has its own specified keys. +The **return value** is a `boolean` indicating whether or not the `value` has its own specified keys. ---- @@ -1214,6 +1214,7 @@ MIT © angular-package ([license](https://github.com/angular-package/type/blob/m [Array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array [Boolean]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean [Function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions +[Number]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number [Object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object [Primitive]: https://developer.mozilla.org/en-US/docs/Glossary/Primitive [String]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String From db5ba394d280cdb084a13e38e1e185fe54bef192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 10:38:41 +0200 Subject: [PATCH 122/201] docs(isArray): update --- packages/type/src/is/lib/is-array.func.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/is/lib/is-array.func.ts b/packages/type/src/is/lib/is-array.func.ts index 0220e037..96e572de 100644 --- a/packages/type/src/is/lib/is-array.func.ts +++ b/packages/type/src/is/lib/is-array.func.ts @@ -3,7 +3,7 @@ import { typeOf } from '../../lib/type-of.func'; // Type. import { IsArray } from '../type/is-array.type'; /** - * Checks if any `value` is an `Array`, `Array` instance and `object` type. + * Checks if any `value` is an `Array`, `Array` instance, and `object` type. * @param value Any `value` to check. * @returns A `boolean` indicating whether or not the `value` is an `Array`. */ From b0bd90ec0ae64a16b975dbadefc693feb0886980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 10:43:55 +0200 Subject: [PATCH 123/201] test(isBigInt): update --- packages/type/src/is/test/is-big-int.spec.ts | 65 ++++++++++---------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/packages/type/src/is/test/is-big-int.spec.ts b/packages/type/src/is/test/is-big-int.spec.ts index 6ab857f6..7413e226 100644 --- a/packages/type/src/is/test/is-big-int.spec.ts +++ b/packages/type/src/is/test/is-big-int.spec.ts @@ -1,68 +1,65 @@ -/** - * Checks - * ✓ typeof === 'bigint' - */ -import { isBigInt } from '../lib/is-big-int.func'; -import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; import { BIGINT, BIGINT_INSTANCE } from './variables/big-int.const'; +import { CLASS, Class } from './variables/class.const'; +import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; import { FUNCTION } from './variables/function.const'; +import { NULL } from './variables/null.const'; import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; import { OBJECT_ONE, OBJECT_TWO } from './variables/object.const'; import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; import { UNDEFINED } from './variables/undefined.const'; -import { CLASS, Class } from './variables/class.const'; -import { NULL } from './variables/null.const'; +import { isBigInt } from '../lib/is-big-int.func'; import { notDefined } from './variables/not-defined.const'; - +/** + * Checks + * ✓ typeof === 'bigint' + */ describe('isBigInt', () => { // TRUE it('is DEFINED', () => { expect(isBigInt).toBeDefined(); }); it(`'bigint'`, () => { - expect(isBigInt(BIGINT)).toBeTruthy(); - expect(isBigInt(BIGINT_INSTANCE)).toBeTruthy(); + expect(isBigInt(BIGINT)).toBe(TRUE); + expect(isBigInt(BIGINT_INSTANCE)).toBe(TRUE); }); // FALSE it(`'boolean' | Boolean`, () => { - expect(isBigInt(FALSE)).toBeFalsy(); - expect(isBigInt(TRUE)).toBeFalsy(); - expect(isBigInt(FALSE_INSTANCE)).toBeFalsy(); - expect(isBigInt(TRUE_INSTANCE)).toBeFalsy(); + expect(isBigInt(FALSE)).toBe(FALSE); + expect(isBigInt(TRUE)).toBe(FALSE); + expect(isBigInt(FALSE_INSTANCE)).toBe(FALSE); + expect(isBigInt(TRUE_INSTANCE)).toBe(FALSE); }); it(`Class | CLASS`, () => { - expect(isBigInt(Class)).toBeFalsy(); - expect(isBigInt(CLASS)).toBeFalsy(); - }); - it(`'function' | Function`, () => { - expect(isBigInt(FUNCTION)).toBeFalsy(); + expect(isBigInt(Class)).toBe(FALSE); + expect(isBigInt(CLASS)).toBe(FALSE); }); + it(`'function' | Function`, () => expect(isBigInt(FUNCTION)).toBe(FALSE)); it(`null | NULL`, () => { - expect(isBigInt(null)).toBeFalsy(); - expect(isBigInt(NULL)).toBeFalsy(); + expect(isBigInt(null)).toBe(FALSE); + expect(isBigInt(NULL)).toBe(FALSE); }); it(`'number' | Number`, () => { - expect(isBigInt(NUMBER)).toBeFalsy(); - expect(isBigInt(NUMBER_INSTANCE)).toBeFalsy(); - expect(isBigInt(NUMBER_NEW_INSTANCE)).toBeFalsy(); + expect(isBigInt(NUMBER)).toBe(FALSE); + expect(isBigInt(NUMBER_INSTANCE)).toBe(FALSE); + expect(isBigInt(NUMBER_NEW_INSTANCE)).toBe(FALSE); }); it(`'object' | Object`, () => { - expect(isBigInt(OBJECT_ONE)).toBeFalsy(); - expect(isBigInt(OBJECT_TWO)).toBeFalsy(); + expect(isBigInt(OBJECT_ONE)).toBe(FALSE); + expect(isBigInt(OBJECT_TWO)).toBe(FALSE); }); it(`'string' | String`, () => { - expect(isBigInt(STRING)).toBeFalsy(); - expect(isBigInt(STRING_INSTANCE)).toBeFalsy(); - expect(isBigInt(STRING_NEW_INSTANCE)).toBeFalsy(); + expect(isBigInt(STRING)).toBe(FALSE); + expect(isBigInt(STRING_INSTANCE)).toBe(FALSE); + expect(isBigInt(STRING_NEW_INSTANCE)).toBe(FALSE); }); it(`'symbol'`, () => { - expect(isBigInt(SYMBOL_NUMBER)).toBeFalsy(); - expect(isBigInt(SYMBOL_STRING)).toBeFalsy(); + expect(isBigInt(SYMBOL_NUMBER)).toBe(FALSE); + expect(isBigInt(SYMBOL_STRING)).toBe(FALSE); }); it(`'undefined'`, () => { - expect(isBigInt(notDefined)).toBeFalse(); - expect(isBigInt(UNDEFINED)).toBeFalse(); + expect(isBigInt(notDefined)).toBe(FALSE); + expect(isBigInt(UNDEFINED)).toBe(FALSE); }); }); From 90e6df4e816164ba941d8eeb8af2e53810c533b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 14:12:38 +0200 Subject: [PATCH 124/201] test(isArray): use `toBe` --- packages/type/src/is/test/is-array.spec.ts | 81 ++++++++++------------ 1 file changed, 38 insertions(+), 43 deletions(-) diff --git a/packages/type/src/is/test/is-array.spec.ts b/packages/type/src/is/test/is-array.spec.ts index 9310b9a6..d8372eae 100644 --- a/packages/type/src/is/test/is-array.spec.ts +++ b/packages/type/src/is/test/is-array.spec.ts @@ -1,13 +1,15 @@ - -import { isArray } from '../lib/is-array.func'; -import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; import { BIGINT, BIGINT_INSTANCE } from './variables/big-int.const'; -import { FUNCTION } from './variables/function.const'; +import { Class } from './variables/class.const'; import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; +import { FUNCTION } from './variables/function.const'; +import { Func } from '../../type/func.type'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; import { OBJECT_ONE, OBJECT_TWO, ObjectOne, ObjectTwo } from './variables/object.const'; import { STRING, STRING_INSTANCE } from './variables/string.const'; import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; import { UNDEFINED } from './variables/undefined.const'; +import { isArray } from '../lib/is-array.func'; +import { notDefined } from './variables/not-defined.const'; import { ARRAY_BIGINT, ARRAY_BOOLEAN, @@ -18,70 +20,63 @@ import { ARRAY_OBJECT_ONE, ARRAY_OBJECT_TWO, ARRAY_STRING, - ARRAY_SYMBOL_STRING, ARRAY_SYMBOL_NUMBER, + ARRAY_SYMBOL_STRING, ARRAY_UNDEFINED } from './variables/array.const'; -import { Class } from './variables/class.const'; -import { Func } from '../../type/func.type'; -import { notDefined } from './variables/not-defined.const'; describe('isArray', () => { // TRUE - it('is DEFINED', () => { - expect(isArray).toBeDefined(); - }); - it('Array', () => expect(isArray(ARRAY_BIGINT)).toBeTruthy()); - it('Array', () => expect(isArray(ARRAY_BOOLEAN)).toBeTruthy()); - it('Array', () => expect(isArray(ARRAY_CLASS)).toBeTruthy()); - it('Array', () => expect(isArray(ARRAY_FUNCTION)).toBeTruthy()); - it('Array', () => expect(isArray(ARRAY_NULL)).toBeTruthy()); - it('Array', () => expect(isArray(ARRAY_NUMBER)).toBeTruthy()); + it('is DEFINED', () => expect(isArray).toBeDefined()); + it('Array', () => expect(isArray(ARRAY_BIGINT)).toBe(TRUE)); + it('Array', () => expect(isArray(ARRAY_BOOLEAN)).toBe(TRUE)); + it('Array', () => expect(isArray(ARRAY_CLASS)).toBe(TRUE)); + it('Array', () => expect(isArray(ARRAY_FUNCTION)).toBe(TRUE)); + it('Array', () => expect(isArray(ARRAY_NULL)).toBe(TRUE)); + it('Array', () => expect(isArray(ARRAY_NUMBER)).toBe(TRUE)); it('Array Array', () => { - expect(isArray(ARRAY_OBJECT_ONE)).toBeTruthy(); - expect(isArray(ARRAY_OBJECT_TWO)).toBeTruthy(); + expect(isArray(ARRAY_OBJECT_ONE)).toBe(TRUE); + expect(isArray(ARRAY_OBJECT_TWO)).toBe(TRUE); }); - it('Array', () => expect(isArray(ARRAY_STRING)).toBeTruthy()); + it('Array', () => expect(isArray(ARRAY_STRING)).toBe(TRUE)); it('Array', () => { - expect(isArray(ARRAY_SYMBOL_STRING)).toBeTruthy(); - expect(isArray(ARRAY_SYMBOL_NUMBER)).toBeTruthy(); + expect(isArray(ARRAY_SYMBOL_STRING)).toBe(TRUE); + expect(isArray(ARRAY_SYMBOL_NUMBER)).toBe(TRUE); }); - it('Array', () => expect(isArray(ARRAY_UNDEFINED)).toBeTruthy()); + it('Array', () => expect(isArray(ARRAY_UNDEFINED)).toBe(TRUE)); // FALSE it(`'bigint'`, () => { - expect(isArray(BIGINT)).toBeFalsy(); - expect(isArray(BIGINT_INSTANCE)).toBeFalsy(); + expect(isArray(BIGINT)).toBe(FALSE); + expect(isArray(BIGINT_INSTANCE)).toBe(FALSE); }); it(`'boolean' | Boolean`, () => { - expect(isArray(FALSE)).toBeFalsy(); - expect(isArray(TRUE)).toBeFalsy(); - expect(isArray(FALSE_INSTANCE)).toBeFalsy(); - expect(isArray(TRUE_INSTANCE)).toBeFalsy(); - }); - it(`'function' | Function`, () => { - expect(isArray(FUNCTION)).toBeFalsy(); + expect(isArray(FALSE)).toBe(FALSE); + expect(isArray(TRUE)).toBe(FALSE); + expect(isArray(FALSE_INSTANCE)).toBe(FALSE); + expect(isArray(TRUE_INSTANCE)).toBe(FALSE); }); + it(`'function' | Function`, () => expect(isArray(FUNCTION)).toBe(FALSE)); it(`'number' | Number`, () => { - expect(isArray(NUMBER)).toBeFalsy(); - expect(isArray(NUMBER_INSTANCE)).toBeFalsy(); - expect(isArray(NUMBER_NEW_INSTANCE)).toBeFalsy(); + expect(isArray(NUMBER)).toBe(FALSE); + expect(isArray(NUMBER_INSTANCE)).toBe(FALSE); + expect(isArray(NUMBER_NEW_INSTANCE)).toBe(FALSE); }); it(`'object' | Object`, () => { - expect(isArray(OBJECT_ONE)).toBeFalsy(); - expect(isArray(OBJECT_TWO)).toBeFalsy(); + expect(isArray(OBJECT_ONE)).toBe(FALSE); + expect(isArray(OBJECT_TWO)).toBe(FALSE); }); it(`'string' | String`, () => { - expect(isArray(STRING)).toBeFalsy(); - expect(isArray(STRING_INSTANCE)).toBeFalsy(); + expect(isArray(STRING)).toBe(FALSE); + expect(isArray(STRING_INSTANCE)).toBe(FALSE); }); it(`'symbol'`, () => { - expect(isArray(SYMBOL_NUMBER)).toBeFalsy(); - expect(isArray(SYMBOL_STRING)).toBeFalsy(); + expect(isArray(SYMBOL_NUMBER)).toBe(FALSE); + expect(isArray(SYMBOL_STRING)).toBe(FALSE); }); it(`'undefined'`, () => { - expect(isArray(notDefined)).toBeFalse(); - expect(isArray(UNDEFINED)).toBeFalse(); + expect(isArray(notDefined)).toBe(FALSE); + expect(isArray(UNDEFINED)).toBe(FALSE); }); }); From 2580220a560971ae703ff89ace425b1aef12089e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 15:05:15 +0200 Subject: [PATCH 125/201] test: style one line --- packages/type/src/is/test/is-boolean.spec.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/type/src/is/test/is-boolean.spec.ts b/packages/type/src/is/test/is-boolean.spec.ts index 461976a3..f35089a5 100644 --- a/packages/type/src/is/test/is-boolean.spec.ts +++ b/packages/type/src/is/test/is-boolean.spec.ts @@ -19,9 +19,7 @@ import { notDefined } from './variables/not-defined.const'; */ describe('isBoolean', () => { // TRUE - it('is DEFINED', () => { - expect(isBoolean).toBeDefined(); - }); + it('is DEFINED', () => expect(isBoolean).toBeDefined()); it(`'boolean' | Boolean`, () => { expect(isBoolean(FALSE)).toBe(TRUE); expect(isBoolean(TRUE)).toBe(TRUE); From dd5546eb1bbdd21a0df2b5927c92a1a9e1f6a083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 17:08:23 +0200 Subject: [PATCH 126/201] refactor(isDefined): add `callback`, update jsdoc --- packages/type/src/is/lib/is-defined.func.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/type/src/is/lib/is-defined.func.ts b/packages/type/src/is/lib/is-defined.func.ts index 75126b56..5cc05dce 100644 --- a/packages/type/src/is/lib/is-defined.func.ts +++ b/packages/type/src/is/lib/is-defined.func.ts @@ -1,13 +1,15 @@ // Function. +import { errorCallback } from '../../lib/error-callback.func'; import { typeOf } from '../../lib/type-of.func'; // Type. import { IsDefined } from '../type/is-defined.type'; +import { ResultCallback } from '../../type/result-callback.type'; /** * Checks if an unknown `value` is NOT an `undefined` type and is NOT equal to `undefined`. - * @param value An unknown `value` to check. - * @returns A `boolean` indicating whether or not the `value` is defined. + * @param value An `unknown` `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `errorCallback`. + * @returns A `boolean` indicating whether or not the `value` is defined, not `undefined`. */ -export const isDefined: IsDefined = (value: unknown): boolean => - typeOf(value) !== 'undefined' && - typeof value !== 'undefined' && - value !== undefined; +export const isDefined: IsDefined = (value: unknown, callback: ResultCallback = errorCallback): boolean => + callback(typeOf(value) !== 'undefined' && typeof value !== 'undefined' && value !== undefined); From bc517257b121476dd9c472d85d716dac15f35a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 17:08:45 +0200 Subject: [PATCH 127/201] refactor(IsDefined): add `callback` --- packages/type/src/is/type/is-defined.type.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/type/src/is/type/is-defined.type.ts b/packages/type/src/is/type/is-defined.type.ts index 1a5fcb73..14732e2b 100644 --- a/packages/type/src/is/type/is-defined.type.ts +++ b/packages/type/src/is/type/is-defined.type.ts @@ -1 +1,2 @@ -export type IsDefined = (value: unknown) => boolean; +import { ResultCallback } from '../../type/result-callback.type'; +export type IsDefined = (value: unknown, callback?: ResultCallback) => boolean; From 31e05be72b3c41f31f36e842fe1e50135f65d36f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 17:12:04 +0200 Subject: [PATCH 128/201] test(isDefined): update - change `toBeTruthy` to `toBe(TRUE)` - change `toBeFalsy` to `toBe(FALSE)` --- packages/type/src/is/test/is-defined.spec.ts | 56 +++++++++----------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/packages/type/src/is/test/is-defined.spec.ts b/packages/type/src/is/test/is-defined.spec.ts index 2c19fab4..c239c668 100644 --- a/packages/type/src/is/test/is-defined.spec.ts +++ b/packages/type/src/is/test/is-defined.spec.ts @@ -20,54 +20,50 @@ import { notDefined } from './variables/not-defined.const'; */ describe('isDefined', () => { // TRUE - it('is DEFINED', () => { - expect(isDefined).toBeDefined(); - }); + it('is DEFINED', () => expect(isDefined).toBeDefined()); it(`'boolean' | Boolean`, () => { - expect(isDefined(FALSE)).toBeTruthy(); - expect(isDefined(TRUE)).toBeTruthy(); - expect(isDefined(FALSE_INSTANCE)).toBeTruthy(); - expect(isDefined(TRUE_INSTANCE)).toBeTruthy(); - expect(isDefined(Boolean(false))).toBeTruthy(); - expect(isDefined(Boolean(true))).toBeTruthy(); + expect(isDefined(FALSE)).toBe(TRUE); + expect(isDefined(TRUE)).toBe(TRUE); + expect(isDefined(FALSE_INSTANCE)).toBe(TRUE); + expect(isDefined(TRUE_INSTANCE)).toBe(TRUE); + expect(isDefined(Boolean(false))).toBe(TRUE); + expect(isDefined(Boolean(true))).toBe(TRUE); }); it(`'bigint'`, () => { - expect(isDefined(BIGINT)).toBeTruthy(); - expect(isDefined(BIGINT_INSTANCE)).toBeTruthy(); + expect(isDefined(BIGINT)).toBe(TRUE); + expect(isDefined(BIGINT_INSTANCE)).toBe(TRUE); }); it(`Class | CLASS`, () => { - expect(isDefined(Class)).toBeTruthy(); - expect(isDefined(CLASS)).toBeTruthy(); - }); - it(`'function' | Function`, () => { - expect(isDefined(FUNCTION)).toBeTruthy(); + expect(isDefined(Class)).toBe(TRUE); + expect(isDefined(CLASS)).toBe(TRUE); }); + it(`'function' | Function`, () => expect(isDefined(FUNCTION)).toBe(TRUE)); it(`null | NULL`, () => { - expect(isDefined(null)).toBeTruthy(); - expect(isDefined(NULL)).toBeTruthy(); + expect(isDefined(null)).toBe(TRUE); + expect(isDefined(NULL)).toBe(TRUE); }); it(`'number' | Number`, () => { - expect(isDefined(NUMBER)).toBeTruthy(); - expect(isDefined(NUMBER_INSTANCE)).toBeTruthy(); - expect(isDefined(NUMBER_NEW_INSTANCE)).toBeTruthy(); + expect(isDefined(NUMBER)).toBe(TRUE); + expect(isDefined(NUMBER_INSTANCE)).toBe(TRUE); + expect(isDefined(NUMBER_NEW_INSTANCE)).toBe(TRUE); }); it(`'object' | Object`, () => { - expect(isDefined(OBJECT_ONE)).toBeTruthy(); - expect(isDefined(OBJECT_TWO)).toBeTruthy(); + expect(isDefined(OBJECT_ONE)).toBe(TRUE); + expect(isDefined(OBJECT_TWO)).toBe(TRUE); }); it(`'string' | String`, () => { - expect(isDefined(STRING)).toBeTruthy(); - expect(isDefined(STRING_INSTANCE)).toBeTruthy(); - expect(isDefined(STRING_NEW_INSTANCE)).toBeTruthy(); + expect(isDefined(STRING)).toBe(TRUE); + expect(isDefined(STRING_INSTANCE)).toBe(TRUE); + expect(isDefined(STRING_NEW_INSTANCE)).toBe(TRUE); }); it(`'symbol'`, () => { - expect(isDefined(SYMBOL_NUMBER)).toBeTruthy(); - expect(isDefined(SYMBOL_STRING)).toBeTruthy(); + expect(isDefined(SYMBOL_NUMBER)).toBe(TRUE); + expect(isDefined(SYMBOL_STRING)).toBe(TRUE); }); // FALSE it(`'undefined'`, () => { - expect(isDefined(notDefined)).toBeFalsy(); - expect(isDefined(UNDEFINED)).toBeFalsy(); + expect(isDefined(notDefined)).toBe(FALSE); + expect(isDefined(UNDEFINED)).toBe(FALSE); }); }); From 8900e99f0c6b72d2003bad76b36c4c96fdc3431d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 17:25:08 +0200 Subject: [PATCH 129/201] refactor(isFunction): add `callback` to type and function, update jsdoc --- packages/type/src/is/lib/is-function.func.ts | 18 ++++++++++++------ packages/type/src/is/type/is-function.type.ts | 3 ++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/type/src/is/lib/is-function.func.ts b/packages/type/src/is/lib/is-function.func.ts index 45e7ad65..19168dd0 100644 --- a/packages/type/src/is/lib/is-function.func.ts +++ b/packages/type/src/is/lib/is-function.func.ts @@ -1,15 +1,21 @@ // Function. +import { errorCallback } from '../../lib/error-callback.func'; import { typeOf } from '../../lib/type-of.func'; // Type. import { Func } from '../../type/func.type'; import { IsFunction } from '../type/is-function.type'; +import { ResultCallback } from '../../type/result-callback.type'; /** - * Checks if any `value` is a `function` type, an instance `Function` and `Object`. + * Checks if any `value` is a `function` type, an instance of `Function` and `Object`. * @param value Any `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `errorCallback`. * @returns A `boolean` indicating whether or not the `value` is a `function`. */ -export const isFunction: IsFunction = (value: any): value is Func => - typeOf(value) === 'function' && - typeof value === 'function' && - value instanceof Function === true && - value instanceof Object === true; +export const isFunction: IsFunction = (value: any, callback: ResultCallback = errorCallback): value is Func => + callback( + typeOf(value) === 'function' && + typeof value === 'function' && + value instanceof Function === true && + value instanceof Object === true + ); diff --git a/packages/type/src/is/type/is-function.type.ts b/packages/type/src/is/type/is-function.type.ts index 432a24f5..4e6db5b2 100644 --- a/packages/type/src/is/type/is-function.type.ts +++ b/packages/type/src/is/type/is-function.type.ts @@ -1,2 +1,3 @@ import { Func } from '../../type/func.type'; -export type IsFunction = (value: any) => value is Func; +import { ResultCallback } from '../../type/result-callback.type'; +export type IsFunction = (value: any, callback?: ResultCallback) => value is Func; From ea5669644dba33fe38594f52803407f7edfab3e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 17:30:18 +0200 Subject: [PATCH 130/201] test(isFunction): update --- packages/type/src/is/test/is-function.spec.ts | 60 ++++++++----------- 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/packages/type/src/is/test/is-function.spec.ts b/packages/type/src/is/test/is-function.spec.ts index 50166f96..6f1816b0 100644 --- a/packages/type/src/is/test/is-function.spec.ts +++ b/packages/type/src/is/test/is-function.spec.ts @@ -15,56 +15,48 @@ import { notDefined } from './variables/not-defined.const'; describe('isFunction', () => { // TRUE - it('is DEFINED', () => { - expect(isFunction).toBeDefined(); - }); - it(`'function' | Function`, () => { - expect(isFunction(FUNCTION)).toBeTruthy(); - }); - it(`Class`, () => { - expect(isFunction(Class)).toBeTruthy(); - }); + it('is DEFINED', () => expect(isFunction).toBeDefined()); + it(`'function' | Function`, () => expect(isFunction(FUNCTION)).toBe(TRUE)); + it(`Class`, () => expect(isFunction(Class)).toBe(TRUE)); // FALSE. it(`'boolean' | Boolean`, () => { - expect(isFunction(FALSE)).toBeFalsy(); - expect(isFunction(TRUE)).toBeFalsy(); - expect(isFunction(FALSE_INSTANCE)).toBeFalsy(); - expect(isFunction(TRUE_INSTANCE)).toBeFalsy(); - expect(isFunction(Boolean(false))).toBeFalsy(); - expect(isFunction(Boolean(true))).toBeFalsy(); + expect(isFunction(FALSE)).toBe(FALSE); + expect(isFunction(TRUE)).toBe(FALSE); + expect(isFunction(FALSE_INSTANCE)).toBe(FALSE); + expect(isFunction(TRUE_INSTANCE)).toBe(FALSE); + expect(isFunction(Boolean(false))).toBe(FALSE); + expect(isFunction(Boolean(true))).toBe(FALSE); }); it(`'bigint'`, () => { - expect(isFunction(BIGINT)).toBeFalsy(); - expect(isFunction(BIGINT_INSTANCE)).toBeFalsy(); - }); - it(`CLASS`, () => { - expect(isFunction(CLASS)).toBeFalsy(); + expect(isFunction(BIGINT)).toBe(FALSE); + expect(isFunction(BIGINT_INSTANCE)).toBe(FALSE); }); + it(`CLASS`, () => expect(isFunction(CLASS)).toBe(FALSE)); it(`null | NULL`, () => { - expect(isFunction(null)).toBeFalsy(); - expect(isFunction(NULL)).toBeFalsy(); + expect(isFunction(null)).toBe(FALSE); + expect(isFunction(NULL)).toBe(FALSE); }); it(`'number' | Number`, () => { - expect(isFunction(NUMBER)).toBeFalsy(); - expect(isFunction(NUMBER_INSTANCE)).toBeFalsy(); - expect(isFunction(NUMBER_NEW_INSTANCE)).toBeFalsy(); + expect(isFunction(NUMBER)).toBe(FALSE); + expect(isFunction(NUMBER_INSTANCE)).toBe(FALSE); + expect(isFunction(NUMBER_NEW_INSTANCE)).toBe(FALSE); }); it(`'object' | Object`, () => { - expect(isFunction(OBJECT_ONE)).toBeFalsy(); - expect(isFunction(OBJECT_TWO)).toBeFalsy(); + expect(isFunction(OBJECT_ONE)).toBe(FALSE); + expect(isFunction(OBJECT_TWO)).toBe(FALSE); }); it(`'string' | String`, () => { - expect(isFunction(STRING)).toBeFalsy(); - expect(isFunction(STRING_INSTANCE)).toBeFalsy(); - expect(isFunction(STRING_NEW_INSTANCE)).toBeFalsy(); + expect(isFunction(STRING)).toBe(FALSE); + expect(isFunction(STRING_INSTANCE)).toBe(FALSE); + expect(isFunction(STRING_NEW_INSTANCE)).toBe(FALSE); }); it(`'symbol'`, () => { - expect(isFunction(SYMBOL_NUMBER)).toBeFalsy(); - expect(isFunction(SYMBOL_STRING)).toBeFalsy(); + expect(isFunction(SYMBOL_NUMBER)).toBe(FALSE); + expect(isFunction(SYMBOL_STRING)).toBe(FALSE); }); it(`'undefined'`, () => { - expect(isFunction(notDefined)).toBeFalsy(); - expect(isFunction(UNDEFINED)).toBeFalsy(); + expect(isFunction(notDefined)).toBe(FALSE); + expect(isFunction(UNDEFINED)).toBe(FALSE); }); }); From ec82843f6708da2b87c4fd1f9b0c7c55e4e4857d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 19:06:35 +0200 Subject: [PATCH 131/201] test(class): add more classes --- .../type/src/is/test/variables/class.const.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/type/src/is/test/variables/class.const.ts b/packages/type/src/is/test/variables/class.const.ts index 0d152fac..70145877 100644 --- a/packages/type/src/is/test/variables/class.const.ts +++ b/packages/type/src/is/test/variables/class.const.ts @@ -42,3 +42,19 @@ export class Class { * instanceof Object === true */ export const CLASS = new Class(); + + +export class Person { + firstName = ''; + surname = ''; + age = 15; +} + +export class PersonCopy { + firstName = ''; + surname = ''; + age = 15; +} + +export const PERSON: Person = new Person(); +export const PERSON_COPY: PersonCopy = new PersonCopy(); From 79b44b8f1f41ab65ddecedf5add9031249ecf3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 19:06:51 +0200 Subject: [PATCH 132/201] refactor(IsInstance): add callback --- packages/type/src/is/type/is-instance.type.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/type/src/is/type/is-instance.type.ts b/packages/type/src/is/type/is-instance.type.ts index 6ad50878..8ea5eb84 100644 --- a/packages/type/src/is/type/is-instance.type.ts +++ b/packages/type/src/is/type/is-instance.type.ts @@ -1,2 +1,3 @@ import { Constructor } from '../../type/constructor.type'; -export type IsInstance = (value: any, instance: Constructor) => value is Obj; +import { ResultCallback } from '../../type/result-callback.type'; +export type IsInstance = (value: any, instance: Constructor, callback?: ResultCallback) => value is Obj; From a309e4142263bbc2add84aeffb9346fc1af53cbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 19:10:06 +0200 Subject: [PATCH 133/201] test: update and add `callback` --- packages/type/src/is/test/is-instance.spec.ts | 61 +++++++++---------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/packages/type/src/is/test/is-instance.spec.ts b/packages/type/src/is/test/is-instance.spec.ts index 90e88edf..a8b5dbad 100644 --- a/packages/type/src/is/test/is-instance.spec.ts +++ b/packages/type/src/is/test/is-instance.spec.ts @@ -3,7 +3,7 @@ import { isInstance } from '../lib/is-instance.func'; // Variables. import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; import { BIGINT, BIGINT_INSTANCE } from './variables/big-int.const'; -import { Class, CLASS } from './variables/class.const'; +import { Class, CLASS, PERSON, Person, PersonCopy, PERSON_COPY } from './variables/class.const'; import { FUNCTION } from './variables/function.const'; import { NULL } from './variables/null.const'; import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; @@ -15,51 +15,50 @@ import { notDefined } from './variables/not-defined.const'; describe('isInstance', () => { // TRUE. - it('is DEFINED', () => { - expect(isInstance).toBeDefined(); - }); - it(`CLASS`, () => { - expect(isInstance(CLASS, Class)).toBeTruthy(); + it('is DEFINED', () => expect(isInstance).toBeDefined()); + it(`CLASS instance of Class`, () => expect(isInstance(CLASS, Class)).toBe(TRUE)); + it(`PERSON instance of Person`, () => expect(isInstance(PERSON, Person)).toBe(TRUE)); + it(`PERSON_COPY instance of PersonCopy`, () => expect(isInstance(PERSON_COPY, PersonCopy)).toBe(TRUE)); + it(`CLASS instance of Class expect result to be true`, () => { + isInstance(CLASS, Class, (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); }); // FALSE. + it(`PERSON_COPY not instance of Person`, () => expect(isInstance(PERSON_COPY, Person)).toBe(FALSE)); it(`'boolean' | Boolean`, () => { - expect(isInstance(FALSE, FALSE)).toBeFalse(); - expect(isInstance(TRUE, TRUE)).toBeFalse(); - expect(isInstance(FALSE_INSTANCE, FALSE_INSTANCE)).toBeFalse(); - expect(isInstance(TRUE_INSTANCE, TRUE_INSTANCE)).toBeFalse(); + expect(isInstance(FALSE, FALSE)).toBe(FALSE); + expect(isInstance(TRUE, TRUE)).toBe(FALSE); + expect(isInstance(FALSE_INSTANCE, FALSE_INSTANCE)).toBe(FALSE); + expect(isInstance(TRUE_INSTANCE, TRUE_INSTANCE)).toBe(FALSE); }); it(`'bigint'`, () => { - expect(isInstance(BIGINT, BIGINT)).toBeFalse(); - expect(isInstance(BIGINT_INSTANCE, BIGINT_INSTANCE)).toBeFalse(); - }); - it(`CLASS`, () => { - expect(isInstance(Class, Class)).toBeFalse(); - }); - it(`'function' | Function`, () => { - expect(isInstance(FUNCTION, Function)).toBeFalse(); - }); - it(`null | NULL`, () => { - expect(isInstance(NULL, NULL)).toBeFalse(); + expect(isInstance(BIGINT, BIGINT)).toBe(FALSE); + expect(isInstance(BIGINT_INSTANCE, BIGINT_INSTANCE)).toBe(FALSE); }); + it(`Class`, () => expect(isInstance(Class, Class)).toBe(FALSE)); + it(`FUNCTION instance of Function`, () => expect(isInstance(FUNCTION, Function)).toBe(FALSE)); + it(`NULL`, () => expect(isInstance(NULL, NULL)).toBe(FALSE)); it(`'number' | Number`, () => { - expect(isInstance(NUMBER, NUMBER)).toBeFalse(); - expect(isInstance(NUMBER_INSTANCE, NUMBER_INSTANCE)).toBeFalse(); - expect(isInstance(NUMBER_NEW_INSTANCE, NUMBER_NEW_INSTANCE)).toBeFalse(); + expect(isInstance(NUMBER, NUMBER)).toBe(FALSE); + expect(isInstance(NUMBER_INSTANCE, NUMBER_INSTANCE)).toBe(FALSE); + expect(isInstance(NUMBER_NEW_INSTANCE, NUMBER_NEW_INSTANCE)).toBe(FALSE); }); // it(`'object' | Object`, () => { - // expect(isInstance(OBJECT_ONE)).toBeFalse(); - // expect(isInstance(OBJECT_TWO, OBJECT_TWO)).toBeFalse(); + // expect(isInstance(OBJECT_ONE)).toBe(FALSE); + // expect(isInstance(OBJECT_TWO, OBJECT_TWO)).toBe(FALSE); // }); it(`'string' | String`, () => { - expect(isInstance(STRING, STRING)).toBeFalse(); - expect(isInstance(STRING_INSTANCE, STRING_INSTANCE)).toBeFalse(); - expect(isInstance(STRING_NEW_INSTANCE, STRING_NEW_INSTANCE)).toBeFalse(); + expect(isInstance(STRING, STRING)).toBe(FALSE); + expect(isInstance(STRING_INSTANCE, STRING_INSTANCE)).toBe(FALSE); + expect(isInstance(STRING_NEW_INSTANCE, STRING_NEW_INSTANCE)).toBe(FALSE); }); // FALSE it(`undefined`, () => { - expect(isInstance(notDefined, notDefined)).toBeFalse(); - expect(isInstance(UNDEFINED, UNDEFINED)).toBeFalse(); + expect(isInstance(notDefined, notDefined)).toBe(FALSE); + expect(isInstance(UNDEFINED, UNDEFINED)).toBe(FALSE); }); }); From bc703fadfdf829f199c23b1c7ca9e27ff4b659ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 19:16:42 +0200 Subject: [PATCH 134/201] refactor(isInstance): add `callback` and update jsdoc --- packages/type/src/is/lib/is-instance.func.ts | 29 +++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/type/src/is/lib/is-instance.func.ts b/packages/type/src/is/lib/is-instance.func.ts index 4a74c796..374268f4 100644 --- a/packages/type/src/is/lib/is-instance.func.ts +++ b/packages/type/src/is/lib/is-instance.func.ts @@ -1,19 +1,28 @@ // Function. +import { errorCallback } from '../../lib/error-callback.func'; +import { isFunction } from './is-function.func'; import { isObject } from './is-object.func'; -import { isString } from './is-string.func'; // Type. import { Constructor } from '../../type/constructor.type'; import { IsInstance } from '../type/is-instance.type'; -import { isFunction } from './is-function.func'; +import { ResultCallback } from '../../type/result-callback.type'; /** * Checks if any `value` is an `object` of a generic `Obj` type equal to an `instance` of `Constructor` type. * @param value Any `value` to compare with the `instance`. - * @param instance The name of the generic `Obj` type to create an `instance` to compare with the `value`. - * @returns A `boolean` indicating whether or not the `value` is an `instance`. + * @param instance A generic `Obj` `Constructor` type to create an `instance` to compare with the `value`. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `errorCallback`. + * @returns A `boolean` indicating whether or not the `value` is an `instance` of a generic `Obj`. */ -export const isInstance: IsInstance = (value: any, instance: Constructor): value is Obj => - isObject(value) ? - isFunction(instance) ? - value instanceof instance === true && isString(instance.prototype.constructor.name) - : false - : false; +export const isInstance: IsInstance = ( + value: any, + instance: Constructor, + callback: ResultCallback = errorCallback + ): value is Obj => + callback( + isObject(value) ? + isFunction(instance) ? + value instanceof instance === true + : false + : false + ); From d9fbc2ad579ee61a24b25b8ad330ae908d661489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 20:02:51 +0200 Subject: [PATCH 135/201] refactor(isKey): add `callback` --- packages/type/src/is/lib/is-key.func.ts | 9 +++++++-- packages/type/src/is/type/is-key.type.ts | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/type/src/is/lib/is-key.func.ts b/packages/type/src/is/lib/is-key.func.ts index 165b6402..eddd9bc8 100644 --- a/packages/type/src/is/lib/is-key.func.ts +++ b/packages/type/src/is/lib/is-key.func.ts @@ -1,13 +1,18 @@ // Function. +import { errorCallback } from '../../lib/error-callback.func'; import { isNumber } from './is-number.func'; import { isString } from './is-string.func'; import { isSymbol } from './is-symbol.func'; // Type. import { IsKey } from '../type/is-key.type'; import { Key } from '../../type/key.type'; +import { ResultCallback } from '../../type/result-callback.type'; /** * Checks if any `value` is one of the `string`, `number`, or `symbol`. * @param value Any `value` to check. - * @returns A `boolean` indicating whether or not the `value` is a `Key` type. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `errorCallback`. + * @returns A `boolean` indicating whether or not the `value` is a `Key`. */ -export const isKey: IsKey = (value: any): value is Key => isString(value) || isNumber(value) || isSymbol(value); +export const isKey: IsKey = (value: any, callback: ResultCallback = errorCallback): value is Key => + callback(isString(value) || isNumber(value) || isSymbol(value)); diff --git a/packages/type/src/is/type/is-key.type.ts b/packages/type/src/is/type/is-key.type.ts index 68d8a627..98fa4ded 100644 --- a/packages/type/src/is/type/is-key.type.ts +++ b/packages/type/src/is/type/is-key.type.ts @@ -1,2 +1,3 @@ import { Key } from '../../type/key.type'; -export type IsKey = (value: any) => value is Key; +import { ResultCallback } from '../../type/result-callback.type'; +export type IsKey = (value: any, callback?: ResultCallback) => value is Key; From bf4d13472bbe48779b75a4b175693068eb69e8d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 20:22:25 +0200 Subject: [PATCH 136/201] test(isKey): add --- packages/type/src/is/test/is-key.spec.ts | 79 ++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 packages/type/src/is/test/is-key.spec.ts diff --git a/packages/type/src/is/test/is-key.spec.ts b/packages/type/src/is/test/is-key.spec.ts new file mode 100644 index 00000000..53c42436 --- /dev/null +++ b/packages/type/src/is/test/is-key.spec.ts @@ -0,0 +1,79 @@ +// Function. +import { isKey } from '../lib/is-key.func'; +// Variables. +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from './variables/big-int.const'; +import { Class, CLASS } from './variables/class.const'; +import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE, FALSE_EXPECTATION, TRUE_EXPECTATION } from './variables/boolean.const'; +import { FUNCTION } from './variables/function.const'; +import { NULL } from './variables/null.const'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; +import { OBJECT_ONE, OBJECT_TWO, ObjectOne, ObjectTwo, OBJECT_ONE_NEW, OBJECT_TWO_NEW } from './variables/object.const'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; +import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; +import { UNDEFINED } from './variables/undefined.const'; + +describe(`isKey`, () => { + // Defined. + it('is DEFINED', () => expect(isKey).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + // ... arrays. + describe(`array`, () => { + // it(`${FUNCTION}`, () => expect(isKey(FUNCTION, 'function')).toBe(FALSE)); + // it(`${Class}`, () => expect(isKey(Class, 'function')).toBe(FALSE)); + }); + // ... function. + describe(`function`, () => { + it(`FUNCTION`, () => expect(isKey(FUNCTION)).toBe(FALSE)); + it(`Class`, () => expect(isKey(Class)).toBe(FALSE)); + }); + // ... objects. + describe('object', () => { + it(`CLASS`, () => expect(isKey(CLASS)).toBe(FALSE)); + it(`OBJECT_ONE`, () => expect(isKey(OBJECT_ONE)).toBe(FALSE)); + it(`OBJECT_TWO`, () => expect(isKey(OBJECT_TWO)).toBe(FALSE)); + it(`new Object(OBJECT_ONE_NEW})`, () => expect(isKey(OBJECT_ONE_NEW)).toBe(FALSE)); + it(`new Object(OBJECT_TWO_NEW})`, () => expect(isKey(OBJECT_TWO_NEW)).toBe(FALSE)); + }); + // ... primitives. + describe(`primitive`, () => { + // bigint + describe(`bigint`, () => { + it(`${BIGINT}`, () => expect(isKey(BIGINT)).toBe(FALSE)); + it(`${BIGINT_EXPECTATION}`, () => expect(isKey(BIGINT_INSTANCE)).toBe(FALSE)); + }); + + // boolean + describe(`boolean`, () => { + it(`${TRUE}`, () => expect(isKey(TRUE)).toBe(FALSE)); + it(`${FALSE}`, () => expect(isKey(FALSE)).toBe(FALSE)); + it(`${FALSE_EXPECTATION}`, () => expect(isKey(TRUE_INSTANCE)).toBe(FALSE)); + it(`${TRUE_EXPECTATION}`, () => expect(isKey(FALSE_INSTANCE)).toBe(FALSE)); + }); + + // null + it(`${NULL}`, () => expect(isKey(NULL)).toBe(FALSE)); + + // number + describe(`number`, () => { + it(`${NUMBER}`, () => expect(isKey(NUMBER)).toBe(TRUE)); + it(`Number(${NUMBER})`, () => expect(isKey(NUMBER_INSTANCE)).toBe(TRUE)); + it(`new Number(${NUMBER})`, () => expect(isKey(NUMBER_NEW_INSTANCE)).toBe(TRUE)); + }); + // string + describe(`string`, () => { + it(`${STRING}`, () => expect(isKey(STRING)).toBe(TRUE)); + it(`String(${STRING})`, () => expect(isKey(STRING_INSTANCE)).toBe(TRUE)); + it(`new String(${STRING})`, () => expect(isKey(STRING_NEW_INSTANCE)).toBe(TRUE)); + }); + // symbol + describe(`symbol`, () => { + it(`Symbol(${NUMBER})`, () => expect(isKey(SYMBOL_NUMBER)).toBe(TRUE)); + it(`Symbol(${STRING})`, () => expect(isKey(SYMBOL_STRING)).toBe(TRUE)); + }); + // undefined + it(`${UNDEFINED}`, () => expect(isKey(UNDEFINED)).toBe(FALSE)); + }); + }); +}); From ab572c6c35a5ab6ed9d7b396099341186320b551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 20:46:22 +0200 Subject: [PATCH 137/201] refactor(isNull): add `callback` --- packages/type/src/is/lib/is-null.func.ts | 10 ++++++---- packages/type/src/is/type/is-null.type.ts | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/type/src/is/lib/is-null.func.ts b/packages/type/src/is/lib/is-null.func.ts index 528dfd06..0f888ce0 100644 --- a/packages/type/src/is/lib/is-null.func.ts +++ b/packages/type/src/is/lib/is-null.func.ts @@ -1,13 +1,15 @@ // Function. +import { errorCallback } from '../../lib/error-callback.func'; import { typeOf } from '../../lib/type-of.func'; // Type. import { IsNull } from '../type/is-null.type'; +import { ResultCallback } from '../../type/result-callback.type'; /** * Checks if any `value` is an `object` type and equal to `null`. * @param value Any `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `errorCallback`. * @returns A `boolean` indicating whether or not the `value` is `null`. */ -export const isNull: IsNull = (value: any): value is null => - typeOf(value) === 'null' && - typeof value === 'object' && - value === null; +export const isNull: IsNull = (value: any, callback: ResultCallback = errorCallback): value is null => + callback(typeOf(value) === 'null' && typeof value === 'object' && value === null); diff --git a/packages/type/src/is/type/is-null.type.ts b/packages/type/src/is/type/is-null.type.ts index ec9502fb..dc464b0b 100644 --- a/packages/type/src/is/type/is-null.type.ts +++ b/packages/type/src/is/type/is-null.type.ts @@ -1 +1,2 @@ -export type IsNull = (value: any) => value is null; +import { ResultCallback } from '../../type/result-callback.type'; +export type IsNull = (value: any, callback?: ResultCallback) => value is null; From e87c4f925f1d3bf9f33eb898810809c74c755416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 20:47:49 +0200 Subject: [PATCH 138/201] test(isNull): use `toBe` method --- packages/type/src/is/test/is-null.spec.ts | 56 +++++++++++------------ 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/packages/type/src/is/test/is-null.spec.ts b/packages/type/src/is/test/is-null.spec.ts index 3314551a..343e61b8 100644 --- a/packages/type/src/is/test/is-null.spec.ts +++ b/packages/type/src/is/test/is-null.spec.ts @@ -16,54 +16,50 @@ import { notDefined } from './variables/not-defined.const'; describe('isNull', () => { // TRUE - it('is DEFINED', () => { - expect(isNull).toBeDefined(); - }); + it('is DEFINED', () => expect(isNull).toBeDefined()); it(`null | NULL`, () => { - expect(isNull(null)).toBeTrue(); - expect(isNull(NULL)).toBeTrue(); + expect(isNull(null)).toBe(TRUE); + expect(isNull(NULL)).toBe(TRUE); }); // FALSE it(`'bigint'`, () => { - expect(isNull(BIGINT)).toBeFalsy(); - expect(isNull(BIGINT_INSTANCE)).toBeFalsy(); + expect(isNull(BIGINT)).toBe(FALSE); + expect(isNull(BIGINT_INSTANCE)).toBe(FALSE); }); it(`'boolean' | Boolean`, () => { - expect(isNull(FALSE)).toBeFalse(); - expect(isNull(TRUE)).toBeFalse(); - expect(isNull(FALSE_INSTANCE)).toBeFalse(); - expect(isNull(TRUE_INSTANCE)).toBeFalse(); - expect(isNull(Boolean(false))).toBeFalse(); - expect(isNull(Boolean(true))).toBeFalse(); + expect(isNull(FALSE)).toBe(FALSE); + expect(isNull(TRUE)).toBe(FALSE); + expect(isNull(FALSE_INSTANCE)).toBe(FALSE); + expect(isNull(TRUE_INSTANCE)).toBe(FALSE); + expect(isNull(Boolean(false))).toBe(FALSE); + expect(isNull(Boolean(true))).toBe(FALSE); }); it(`Class | CLASS`, () => { - expect(isNull(Class)).toBeFalsy(); - expect(isNull(CLASS)).toBeFalsy(); - }); - it(`'function' | Function`, () => { - expect(isNull(FUNCTION)).toBeFalsy(); + expect(isNull(Class)).toBe(FALSE); + expect(isNull(CLASS)).toBe(FALSE); }); + it(`'function' | Function`, () => expect(isNull(FUNCTION)).toBe(FALSE)); it(`'number' | Number`, () => { - expect(isNull(NUMBER)).toBeFalsy(); - expect(isNull(NUMBER_INSTANCE)).toBeFalsy(); - expect(isNull(NUMBER_NEW_INSTANCE)).toBeFalsy(); + expect(isNull(NUMBER)).toBe(FALSE); + expect(isNull(NUMBER_INSTANCE)).toBe(FALSE); + expect(isNull(NUMBER_NEW_INSTANCE)).toBe(FALSE); }); it(`'object' | Object`, () => { - expect(isNull(OBJECT_ONE)).toBeFalsy(); - expect(isNull(OBJECT_TWO)).toBeFalsy(); + expect(isNull(OBJECT_ONE)).toBe(FALSE); + expect(isNull(OBJECT_TWO)).toBe(FALSE); }); it(`'string' | String`, () => { - expect(isNull(STRING)).toBeFalsy(); - expect(isNull(STRING_INSTANCE)).toBeFalsy(); - expect(isNull(STRING_NEW_INSTANCE)).toBeFalsy(); + expect(isNull(STRING)).toBe(FALSE); + expect(isNull(STRING_INSTANCE)).toBe(FALSE); + expect(isNull(STRING_NEW_INSTANCE)).toBe(FALSE); }); it(`'symbol'`, () => { - expect(isNull(SYMBOL_NUMBER)).toBeFalsy(); - expect(isNull(SYMBOL_STRING)).toBeFalsy(); + expect(isNull(SYMBOL_NUMBER)).toBe(FALSE); + expect(isNull(SYMBOL_STRING)).toBe(FALSE); }); it(`'undefined'`, () => { - expect(isNull(notDefined)).toBeFalse(); - expect(isNull(UNDEFINED)).toBeFalse(); + expect(isNull(notDefined)).toBe(FALSE); + expect(isNull(UNDEFINED)).toBe(FALSE); }); }); From 6c394e2f70e80f788de76c97948df8a032d9b292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 20:57:08 +0200 Subject: [PATCH 139/201] chore(isNumber): add `callback` to type and update jsdoc --- packages/type/src/is/lib/is-number.func.ts | 4 +++- packages/type/src/is/type/is-number.type.ts | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/type/src/is/lib/is-number.func.ts b/packages/type/src/is/lib/is-number.func.ts index c3421244..33cd8754 100644 --- a/packages/type/src/is/lib/is-number.func.ts +++ b/packages/type/src/is/lib/is-number.func.ts @@ -8,7 +8,9 @@ import { IsNumber } from '../type/is-number.type'; import { ResultCallback } from '../../type/result-callback.type'; /** * Checks if any `value` is a `number` type not an instance of `Number` and `Object` or `object` type instance of `Number` and `Object`. - * @param value Any value to check. + * @param value Any `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `errorCallback`. * @returns A `boolean` indicating whether or not the `value` is a `number`. */ export const isNumber: IsNumber = (value: any, callback: ResultCallback = errorCallback): value is number => diff --git a/packages/type/src/is/type/is-number.type.ts b/packages/type/src/is/type/is-number.type.ts index 6bd36895..d959f5b8 100644 --- a/packages/type/src/is/type/is-number.type.ts +++ b/packages/type/src/is/type/is-number.type.ts @@ -1 +1,2 @@ -export type IsNumber = (value: any) => value is number; +import { ResultCallback } from '../../type/result-callback.type'; +export type IsNumber = (value: any, callback?: ResultCallback) => value is number; From 9981078bee0c4b94d59d74cbaf65bd80889552c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 20:57:22 +0200 Subject: [PATCH 140/201] test(isNumbeR): use `toBe` method --- packages/type/src/is/test/is-number.spec.ts | 62 ++++++++++----------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/packages/type/src/is/test/is-number.spec.ts b/packages/type/src/is/test/is-number.spec.ts index dca6f3b5..4c8a2287 100644 --- a/packages/type/src/is/test/is-number.spec.ts +++ b/packages/type/src/is/test/is-number.spec.ts @@ -1,17 +1,15 @@ - -import { isNumber } from '../lib/is-number.func'; -import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; import { BIGINT, BIGINT_INSTANCE } from './variables/big-int.const'; +import { CLASS, Class } from './variables/class.const'; +import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; import { FUNCTION } from './variables/function.const'; +import { NULL } from './variables/null.const'; import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; import { OBJECT_ONE, OBJECT_TWO } from './variables/object.const'; import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; import { UNDEFINED } from './variables/undefined.const'; -import { CLASS, Class } from './variables/class.const'; -import { NULL } from './variables/null.const'; +import { isNumber } from '../lib/is-number.func'; import { notDefined } from './variables/not-defined.const'; - /** * Checks * ✓ typeof === 'number' @@ -19,52 +17,48 @@ import { notDefined } from './variables/not-defined.const'; */ describe('isNumber', () => { // TRUE - it('is DEFINED', () => { - expect(isNumber).toBeDefined(); - }); + it('is DEFINED', () => expect(isNumber).toBeDefined()); it(`'number' | Number`, () => { - expect(isNumber(NUMBER)).toBeTruthy(); - expect(isNumber(NUMBER_INSTANCE)).toBeTruthy(); - expect(isNumber(NUMBER_NEW_INSTANCE)).toBeTruthy(); + expect(isNumber(NUMBER)).toBe(TRUE); + expect(isNumber(NUMBER_INSTANCE)).toBe(TRUE); + expect(isNumber(NUMBER_NEW_INSTANCE)).toBe(TRUE); }); // FALSE it(`'bigint'`, () => { - expect(isNumber(BIGINT)).toBeFalsy(); - expect(isNumber(BIGINT_INSTANCE)).toBeFalsy(); + expect(isNumber(BIGINT)).toBe(FALSE); + expect(isNumber(BIGINT_INSTANCE)).toBe(FALSE); }); it(`'boolean' | Boolean`, () => { - expect(isNumber(FALSE)).toBeFalsy(); - expect(isNumber(TRUE)).toBeFalsy(); - expect(isNumber(FALSE_INSTANCE)).toBeFalsy(); - expect(isNumber(TRUE_INSTANCE)).toBeFalsy(); + expect(isNumber(FALSE)).toBe(FALSE); + expect(isNumber(TRUE)).toBe(FALSE); + expect(isNumber(FALSE_INSTANCE)).toBe(FALSE); + expect(isNumber(TRUE_INSTANCE)).toBe(FALSE); }); it(`Class | CLASS`, () => { - expect(isNumber(Class)).toBeFalsy(); - expect(isNumber(CLASS)).toBeFalsy(); - }); - it(`'function' | Function`, () => { - expect(isNumber(FUNCTION)).toBeFalsy(); + expect(isNumber(Class)).toBe(FALSE); + expect(isNumber(CLASS)).toBe(FALSE); }); + it(`'function' | Function`, () => expect(isNumber(FUNCTION)).toBe(FALSE)); it(`null | NULL`, () => { - expect(isNumber(null)).toBeFalsy(); - expect(isNumber(NULL)).toBeFalsy(); + expect(isNumber(null)).toBe(FALSE); + expect(isNumber(NULL)).toBe(FALSE); }); it(`'object' | Object`, () => { - expect(isNumber(OBJECT_ONE)).toBeFalsy(); - expect(isNumber(OBJECT_TWO)).toBeFalsy(); + expect(isNumber(OBJECT_ONE)).toBe(FALSE); + expect(isNumber(OBJECT_TWO)).toBe(FALSE); }); it(`'string' | String`, () => { - expect(isNumber(STRING)).toBeFalsy(); - expect(isNumber(STRING_INSTANCE)).toBeFalsy(); - expect(isNumber(STRING_NEW_INSTANCE)).toBeFalsy(); + expect(isNumber(STRING)).toBe(FALSE); + expect(isNumber(STRING_INSTANCE)).toBe(FALSE); + expect(isNumber(STRING_NEW_INSTANCE)).toBe(FALSE); }); it(`'symbol'`, () => { - expect(isNumber(SYMBOL_NUMBER)).toBeFalsy(); - expect(isNumber(SYMBOL_STRING)).toBeFalsy(); + expect(isNumber(SYMBOL_NUMBER)).toBe(FALSE); + expect(isNumber(SYMBOL_STRING)).toBe(FALSE); }); it(`'undefined'`, () => { - expect(isNumber(notDefined)).toBeFalse(); - expect(isNumber(UNDEFINED)).toBeFalse(); + expect(isNumber(notDefined)).toBe(FALSE); + expect(isNumber(UNDEFINED)).toBe(FALSE); }); }); From 68070869741e8a8d8e594c498ff07afa9ce3a012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 21:45:38 +0200 Subject: [PATCH 141/201] test(isNumber): add comment --- packages/type/src/is/test/is-number.spec.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/type/src/is/test/is-number.spec.ts b/packages/type/src/is/test/is-number.spec.ts index 4c8a2287..0a29d458 100644 --- a/packages/type/src/is/test/is-number.spec.ts +++ b/packages/type/src/is/test/is-number.spec.ts @@ -14,6 +14,9 @@ import { notDefined } from './variables/not-defined.const'; * Checks * ✓ typeof === 'number' * ✓ instanceof Number + * + * ✓ typeof === 'object' + * ✓ instanceof Object */ describe('isNumber', () => { // TRUE From c8bbf9d93ea53bf3fd1360330168de7fe44bc64d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 21:46:04 +0200 Subject: [PATCH 142/201] docs(isNumberObject): update main description --- packages/type/src/is/lib/is-number-object.func.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/is/lib/is-number-object.func.ts b/packages/type/src/is/lib/is-number-object.func.ts index d9874b13..ebbff95d 100644 --- a/packages/type/src/is/lib/is-number-object.func.ts +++ b/packages/type/src/is/lib/is-number-object.func.ts @@ -4,7 +4,7 @@ import { errorCallback } from '../../lib/error-callback.func'; import { IsNumberObject } from '../type/is-number-object.type'; import { ResultCallback } from '../../type/result-callback.type'; /** - * Checks if any `value` is an `object` type an instance of `Number` and `Object`. + * Checks if any `value` is an `object` type and instance of `Number` and `Object`. * @param value Any `value` to check. * @param callback `ResultCallback` function to handle result before returns. * @callback `errorCallback`. From 4e9863df899922ad2775d09cc26ca3eec5d053cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 21:46:16 +0200 Subject: [PATCH 143/201] test(isNumberObject): add --- .../type/src/is/test/is-number-object.spec.ts | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 packages/type/src/is/test/is-number-object.spec.ts diff --git a/packages/type/src/is/test/is-number-object.spec.ts b/packages/type/src/is/test/is-number-object.spec.ts new file mode 100644 index 00000000..3c72c5f4 --- /dev/null +++ b/packages/type/src/is/test/is-number-object.spec.ts @@ -0,0 +1,84 @@ +// Function. +import { isNumberObject } from '../lib/is-number-object.func'; +// Variables. +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from './variables/big-int.const'; +import { Class, CLASS } from './variables/class.const'; +import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE, FALSE_EXPECTATION, TRUE_EXPECTATION } from './variables/boolean.const'; +import { FUNCTION } from './variables/function.const'; +import { NULL } from './variables/null.const'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; +import { OBJECT_ONE, OBJECT_TWO, ObjectOne, ObjectTwo, OBJECT_ONE_NEW, OBJECT_TWO_NEW } from './variables/object.const'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; +import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; +import { UNDEFINED } from './variables/undefined.const'; + +/** + * Checks + * ✓ typeof === 'number' && instanceof Number === false && instanceof Object === false + * ✓ typeof === 'object' && instanceof Number === true && instanceof Object === true + */ +describe(`isNumberObject`, () => { + // Defined. + it('is DEFINED', () => expect(isNumberObject).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + // ... arrays. + describe(`array`, () => { + // it(`${FUNCTION}`, () => expect(isNumberObject(FUNCTION, 'function')).toBe(FALSE)); + // it(`${Class}`, () => expect(isNumberObject(Class, 'function')).toBe(FALSE)); + }); + // ... function. + describe(`function`, () => { + it(`FUNCTION`, () => expect(isNumberObject(FUNCTION)).toBe(FALSE)); + it(`Class`, () => expect(isNumberObject(Class)).toBe(FALSE)); + }); + // ... objects. + describe('object', () => { + it(`CLASS`, () => expect(isNumberObject(CLASS)).toBe(FALSE)); + it(`OBJECT_ONE`, () => expect(isNumberObject(OBJECT_ONE)).toBe(FALSE)); + it(`OBJECT_TWO`, () => expect(isNumberObject(OBJECT_TWO)).toBe(FALSE)); + it(`new Object(OBJECT_ONE_NEW})`, () => expect(isNumberObject(OBJECT_ONE_NEW)).toBe(FALSE)); + it(`new Object(OBJECT_TWO_NEW})`, () => expect(isNumberObject(OBJECT_TWO_NEW)).toBe(FALSE)); + }); + // ... primitives. + describe(`primitive`, () => { + // bigint + describe(`bigint`, () => { + it(`${BIGINT}`, () => expect(isNumberObject(BIGINT)).toBe(FALSE)); + it(`${BIGINT_EXPECTATION}`, () => expect(isNumberObject(BIGINT_INSTANCE)).toBe(FALSE)); + }); + + // boolean + describe(`boolean`, () => { + it(`${TRUE}`, () => expect(isNumberObject(TRUE)).toBe(FALSE)); + it(`${FALSE}`, () => expect(isNumberObject(FALSE)).toBe(FALSE)); + it(`${FALSE_EXPECTATION}`, () => expect(isNumberObject(TRUE_INSTANCE)).toBe(FALSE)); + it(`${TRUE_EXPECTATION}`, () => expect(isNumberObject(FALSE_INSTANCE)).toBe(FALSE)); + }); + + // null + it(`${NULL}`, () => expect(isNumberObject(NULL)).toBe(FALSE)) + + // number + describe(`number`, () => { + it(`${NUMBER}`, () => expect(isNumberObject(NUMBER)).toBe(FALSE)); + it(`Number(${NUMBER})`, () => expect(isNumberObject(NUMBER_INSTANCE)).toBe(FALSE)); + it(`new Number(${NUMBER})`, () => expect(isNumberObject(NUMBER_NEW_INSTANCE)).toBe(TRUE)); + }); + // string + describe(`string`, () => { + it(`${STRING}`, () => expect(isNumberObject(STRING)).toBe(FALSE)); + it(`String(${STRING})`, () => expect(isNumberObject(STRING_INSTANCE)).toBe(FALSE)); + it(`new String(${STRING})`, () => expect(isNumberObject(STRING_NEW_INSTANCE)).toBe(FALSE)); + }); + // symbol + describe(`symbol`, () => { + it(`Symbol(${NUMBER})`, () => expect(isNumberObject(SYMBOL_NUMBER)).toBe(FALSE)); + it(`Symbol(${STRING})`, () => expect(isNumberObject(SYMBOL_STRING)).toBe(FALSE)); + }); + // undefined + it(`${UNDEFINED}`, () => expect(isNumberObject(UNDEFINED)).toBe(FALSE)); + }); + }); +}); From 95edf5bcb777263f025d3013d86e25d1e56e022e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 21:57:24 +0200 Subject: [PATCH 144/201] test: remove unnecessary comment --- packages/type/src/is/test/is-number-object.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/type/src/is/test/is-number-object.spec.ts b/packages/type/src/is/test/is-number-object.spec.ts index 3c72c5f4..b7241210 100644 --- a/packages/type/src/is/test/is-number-object.spec.ts +++ b/packages/type/src/is/test/is-number-object.spec.ts @@ -14,7 +14,6 @@ import { UNDEFINED } from './variables/undefined.const'; /** * Checks - * ✓ typeof === 'number' && instanceof Number === false && instanceof Object === false * ✓ typeof === 'object' && instanceof Number === true && instanceof Object === true */ describe(`isNumberObject`, () => { From ff2327c789669c20b0b0090cab8ebe35e4266454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 21:57:34 +0200 Subject: [PATCH 145/201] test(isNumberType): add --- .../type/src/is/test/is-number-type.spec.ts | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 packages/type/src/is/test/is-number-type.spec.ts diff --git a/packages/type/src/is/test/is-number-type.spec.ts b/packages/type/src/is/test/is-number-type.spec.ts new file mode 100644 index 00000000..3b00f72f --- /dev/null +++ b/packages/type/src/is/test/is-number-type.spec.ts @@ -0,0 +1,85 @@ +// Function. +import { isNumberType } from '../lib/is-number-type.func'; +// Variables. +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from './variables/big-int.const'; +import { Class, CLASS } from './variables/class.const'; +import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE, FALSE_EXPECTATION, TRUE_EXPECTATION } from './variables/boolean.const'; +import { FUNCTION } from './variables/function.const'; +import { NULL } from './variables/null.const'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; +import { OBJECT_ONE, OBJECT_TWO, ObjectOne, ObjectTwo, OBJECT_ONE_NEW, OBJECT_TWO_NEW } from './variables/object.const'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; +import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; +import { UNDEFINED } from './variables/undefined.const'; + +/** + * Checks + * ✓ typeof === 'number' && instanceof Number === false && instanceof Object === false + * ✓ value === true + * ✓ value === false + */ +describe(`isNumberType`, () => { + // Defined. + it('is DEFINED', () => expect(isNumberType).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + // ... arrays. + describe(`array`, () => { + // it(`${FUNCTION}`, () => expect(isNumberType(FUNCTION, 'function')).toBe(FALSE)); + // it(`${Class}`, () => expect(isNumberType(Class, 'function')).toBe(FALSE)); + }); + // ... function. + describe(`function`, () => { + it(`FUNCTION`, () => expect(isNumberType(FUNCTION)).toBe(FALSE)); + it(`Class`, () => expect(isNumberType(Class)).toBe(FALSE)); + }); + // ... objects. + describe('object', () => { + it(`CLASS`, () => expect(isNumberType(CLASS)).toBe(FALSE)); + it(`OBJECT_ONE`, () => expect(isNumberType(OBJECT_ONE)).toBe(FALSE)); + it(`OBJECT_TWO`, () => expect(isNumberType(OBJECT_TWO)).toBe(FALSE)); + it(`new Object(OBJECT_ONE_NEW})`, () => expect(isNumberType(OBJECT_ONE_NEW)).toBe(FALSE)); + it(`new Object(OBJECT_TWO_NEW})`, () => expect(isNumberType(OBJECT_TWO_NEW)).toBe(FALSE)); + }); + // ... primitives. + describe(`primitive`, () => { + // bigint + describe(`bigint`, () => { + it(`${BIGINT}`, () => expect(isNumberType(BIGINT)).toBe(FALSE)); + it(`${BIGINT_EXPECTATION}`, () => expect(isNumberType(BIGINT_INSTANCE)).toBe(FALSE)); + }); + + // boolean + describe(`boolean`, () => { + it(`${TRUE}`, () => expect(isNumberType(TRUE)).toBe(FALSE)); + it(`${FALSE}`, () => expect(isNumberType(FALSE)).toBe(FALSE)); + it(`${FALSE_EXPECTATION}`, () => expect(isNumberType(TRUE_INSTANCE)).toBe(FALSE)); + it(`${TRUE_EXPECTATION}`, () => expect(isNumberType(FALSE_INSTANCE)).toBe(FALSE)); + }); + + // null + it(`${NULL}`, () => expect(isNumberType(NULL)).toBe(FALSE)) + + // number + describe(`number`, () => { + it(`${NUMBER}`, () => expect(isNumberType(NUMBER)).toBe(TRUE)); + it(`Number(${NUMBER})`, () => expect(isNumberType(NUMBER_INSTANCE)).toBe(TRUE)); + it(`new Number(${NUMBER})`, () => expect(isNumberType(NUMBER_NEW_INSTANCE)).toBe(FALSE)); + }); + // string + describe(`string`, () => { + it(`${STRING}`, () => expect(isNumberType(STRING)).toBe(FALSE)); + it(`String(${STRING})`, () => expect(isNumberType(STRING_INSTANCE)).toBe(FALSE)); + it(`new String(${STRING})`, () => expect(isNumberType(STRING_NEW_INSTANCE)).toBe(FALSE)); + }); + // symbol + describe(`symbol`, () => { + it(`Symbol(${NUMBER})`, () => expect(isNumberType(SYMBOL_NUMBER)).toBe(FALSE)); + it(`Symbol(${STRING})`, () => expect(isNumberType(SYMBOL_STRING)).toBe(FALSE)); + }); + // undefined + it(`${UNDEFINED}`, () => expect(isNumberType(UNDEFINED)).toBe(FALSE)); + }); + }); +}); From 134212327b81e422b68a061c87b0cdf823bc2af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 21:58:35 +0200 Subject: [PATCH 146/201] test(is): add all functions --- packages/type/src/is/test/is.spec.ts | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/type/src/is/test/is.spec.ts b/packages/type/src/is/test/is.spec.ts index 0a865d0b..e070eaa0 100644 --- a/packages/type/src/is/test/is.spec.ts +++ b/packages/type/src/is/test/is.spec.ts @@ -1,7 +1,29 @@ import { is } from '../lib/is.object'; -describe('is.', () => { - // TRUE - it('is DEFINED', () => expect(is).toBeDefined()); +describe('`is`', () => { + describe('DEFINED', () => { + it('is', () => expect(is).toBeDefined()); + it('is.array()', () => expect(is.array).toBeDefined()); + it('is.boolean()', () => expect(is.boolean).toBeDefined()); + it('is.booleanObject()', () => expect(is.booleanObject).toBeDefined()); + it('is.booleanType()', () => expect(is.booleanType).toBeDefined()); + it('is.defined()', () => expect(is.defined).toBeDefined()); + it('is.function()', () => expect(is.function).toBeDefined()); + it('is.instance()', () => expect(is.instance).toBeDefined()); + it('is.key()', () => expect(is.key).toBeDefined()); + it('is.null()', () => expect(is.null).toBeDefined()); + it('is.number()', () => expect(is.number).toBeDefined()); + it('is.numberObject()', () => expect(is.numberObject).toBeDefined()); + it('is.numberType()', () => expect(is.numberType).toBeDefined()); + it('is.object()', () => expect(is.object).toBeDefined()); + it('is.objectKey()', () => expect(is.objectKey).toBeDefined()); + it('is.primitive()', () => expect(is.primitive).toBeDefined()); + it('is.string()', () => expect(is.string).toBeDefined()); + it('is.stringObject()', () => expect(is.stringObject).toBeDefined()); + it('is.stringType()', () => expect(is.stringType).toBeDefined()); + it('is.symbol()', () => expect(is.symbol).toBeDefined()); + it('is.type()', () => expect(is.type).toBeDefined()); + it('is.undefined()', () => expect(is.undefined).toBeDefined()); + }); }); From cd904b1f428ebdfbfb163ed14efcff2817249111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 21:59:09 +0200 Subject: [PATCH 147/201] docs(guardObjecKey): fix `key` description --- packages/type/src/guard/lib/guard-object-key.func.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/guard/lib/guard-object-key.func.ts b/packages/type/src/guard/lib/guard-object-key.func.ts index f0a13ce6..ba57034a 100644 --- a/packages/type/src/guard/lib/guard-object-key.func.ts +++ b/packages/type/src/guard/lib/guard-object-key.func.ts @@ -6,7 +6,7 @@ import { GuardObjectKey } from '../type/guard-object-key.type'; /** * Guard the `value` to be an `object` of a generic `Obj` type that contains the `key` property of the `Key` type. * @param value A generic `Obj` type `value` that contains the `key` to guard. - * @param key A `Key` type name of the property that the `object` contains. + * @param key A `Key` type name of the property that the `value` contains. * @returns A `boolean` indicating whether or not the `value` is an `object` of a generic `Obj` containing the `Key`. */ export const guardObjectKey: GuardObjectKey = (value: Obj, key: Key): value is Obj => From dedd5515f9f91048928eaf50c4a5bcaf6188726e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 27 Apr 2021 21:59:21 +0200 Subject: [PATCH 148/201] docs(README.md): update --- README.md | 197 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 153 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index ffc6d5fd..9dc7db1f 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ Type guard > Is to guard type from parameter to not let input unexpected value in the code editor. Guard -> Is a combination of both above to type guard input in the code editor and check the return. +> Is a combination of both above to type guard input in the code editor and check the return. ---- @@ -243,6 +243,20 @@ Default function to handle `callback` parameter. const errorCallback: ResultCallback = (result: boolean): boolean => result; ``` +Custom function to handle `callback` parameter. + +```typescript +const customCallback: ResultCallback = (result: boolean): boolean => { + if (result === false) { + throw new Error('error'); + } + return result; +}; + +const stringResult = isString('Lorem ipsum', customCallback); + +``` + ## Check ### areString @@ -265,7 +279,7 @@ The **return value** is a `boolean` value. ### isArray -Use `isArray()` or `is.array()` to check if **any** `value` is an [`Array`][Array], [`Array`][Array] instance and `object` type. +Use `isArray()` or `is.array()` to check if **any** `value` is an [`Array`][Array], [`Array`][Array] instance, and `object` type. ```typescript const isArray: IsArray = (value: any): value is Array => @@ -296,7 +310,7 @@ isArray(ARRAY_STRING); // true ### isBigInt -Use `isBigInt()` or `is.bigInt()` to check if **any** `value` is a `bigint` type. +Use `isBigInt()` or `is.bigint()` to check if **any** `value` is a `bigint` type. ```typescript const isBigInt: IsBigInt = (value: any): value is bigint => @@ -416,17 +430,16 @@ isBooleanType(BOOLEAN_INSTANCE); // false Use `isDefined()` or `is.defined()` to check if an **unknown** `value` is NOT an `undefined` type and is NOT equal to `undefined`. ```typescript -const isDefined: IsDefined = (value: unknown): boolean => - typeOf(value) !== 'undefined' && - typeof value !== 'undefined' && - value !== undefined; +const isDefined: IsDefined = (value: unknown, callback: ResultCallback = errorCallback): boolean => + callback(typeOf(value) !== 'undefined' && typeof value !== 'undefined' && value !== undefined); ``` | Parameter | Type | Description | | :-------- | :-------: | :---------- | -| value | `unknown` | An unknown `value` to check | +| value | `unknown` | An `unknown` `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | -The **return value** is a `boolean` indicating whether or not the `value` is defined. +The **return value** is a `boolean` indicating whether or not the `value` is defined, not `undefined`. ```typescript // Example usage @@ -441,19 +454,22 @@ isDefined(defined); // false ### isFunction -Use `isFunction()` or `is.function()` to check if **any** `value` is a `function` type, an instance [`Function`][Function] and [`Object`][Object]. +Use `isFunction()` or `is.function()` to check if **any** `value` is a `function` type, an instance of [`Function`][Function] and [`Object`][Object]. ```typescript -const isFunction: IsFunction = (value: any): value is Func => - typeOf(value) === 'function' && - typeof value === 'function' && - value instanceof Function === true && - value instanceof Object === true; +const isFunction: IsFunction = (value: any, callback: ResultCallback = errorCallback): value is Func => + callback( + typeOf(value) === 'function' && + typeof value === 'function' && + value instanceof Function === true && + value instanceof Object === true + ); ``` | Parameter | Type | Description | | :-------- | :---: | :---------- | | value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `function`. @@ -476,20 +492,27 @@ isFunction(() => 5); // true Use `isInstance()` or `is.instance()` to check if **any** value is an `object` of a generic `Obj` type equal to an `instance` of [`Constructor`](#Constructor) type. ```typescript -const isInstance: IsInstance = (value: any, instance: Constructor): value is Obj => - isObject(value) ? - isFunction(instance) ? - value instanceof instance === true && isString(instance.prototype.constructor.name) - : false - : false; +const isInstance: IsInstance = ( + value: any, + instance: Constructor, + callback: ResultCallback = errorCallback + ): value is Obj => + callback( + isObject(value) ? + isFunction(instance) ? + value instanceof instance === true + : false + : false + ); ``` | Parameter | Type | Description | | :-------- | :--------------------------------: | :---------- | | value | `any` | Any `value` to compare with the `instance` | -| instance | [`Constructor`](#Constructor) | The name of the generic `Obj` type to create an `instance` to compare with the `value` | +| instance | [`Constructor`](#Constructor) | A generic `Obj` [`Constructor`](#Constructor) type to create an `instance` to compare with the `value` | +| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | -The **return value** is a `boolean` indicating whether or not the `value` is an `instance`. +The **return value** is a `boolean` indicating whether or not the `value` is an `instance` of a generic `Obj`. ```typescript // Example usage @@ -499,9 +522,9 @@ class Two { y = 'Lorem ipsum'; } const SOME = new Some(); const TWO = new Two(); -isInstance(TWO, SOME); // false -isInstance(SOME, SOME); // true -isInstance(TWO, TWO); // true and type error +isInstance(TWO, Some); // false +isInstance(SOME, Some); // true +isInstance(TWO, Two); // true and type error ``` [Example usage on playground][is-instance] | [How to detect `constructor` instance][detect-instance] @@ -513,15 +536,35 @@ isInstance(TWO, TWO); // true and type error Use `isKey()` or `is.key()` to check if **any** `value` is one of the `string`, `number`, or `symbol`. ```typescript -const isKey: IsKey = (value: any): value is Key => isString(value) || isNumber(value) || isSymbol(value); +const isKey: IsKey = (value: any, callback: ResultCallback = errorCallback): value is Key => + callback(isString(value) || isNumber(value) || isSymbol(value)); ``` | Parameter | Type | Description | | :-------- | :---: |:----------- | | value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a [`Key`](#Key). +```typescript +// Example usage +const STRING = 'surname'; +const STRING_INSTANCE = new String(STRING); +isKey(STRING); // true +isKey(STRING_INSTANCE); // true + +const NUMBER = 27; +const NUMBER_INSTANCE = new Number(NUMBER); +isKey(NUMBER); // true +isKey(NUMBER_INSTANCE); // true + +const SYMBOL_NUMBER: unique symbol = Symbol(NUMBER); +const SYMBOL_STRING: unique symbol = Symbol(STRING); +isKey(SYMBOL_NUMBER); // true +isKey(SYMBOL_STRING); // true +``` + ---- ### isNull @@ -529,21 +572,26 @@ The **return value** is a `boolean` indicating whether or not the `value` is a [ Use `isNull()` or `is.null()` to check if **any** `value` is an `object` type and equal to `null`. ```typescript -const isNull: IsNull = (value: any): value is null => - typeOf(value) === 'null' && - typeof value === 'object' && - value === null; +const isNull: IsNull = (value: any, callback: ResultCallback = errorCallback): value is null => + callback(typeOf(value) === 'null' && typeof value === 'object' && value === null); ``` | Parameter | Type | Description | | :-------- | :---: |------------ | | value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is `null`. ```typescript // Example usage -const NULL = null; +/** + * typeof === 'object' + * instanceof Function === false + * instanceof Number === false + * instanceof Object === false + */ +const NULL: any = null; const NUMBER = 27; isNull(NULL); // true @@ -556,18 +604,17 @@ isNull(NUMBER); // false ### isNumber -Use `isNumber()` or `is.number()` to check if **any** `value` is a `number` type not an instance of `Number` and `Object` or `object` type instance of `Number` and `Object`. +Use `isNumber()` or `is.number()` to check if **any** `value` is a `number` type not an instance of [`Number`][Number] and [`Object`][Object] or `object` type instance of [`Number`][Number] and [`Object`][Object]. ```typescript -const isNumber: IsNumber = (value: any): value is number => - typeOf(value) === 'number' && - isFinite(value) === true && - (isNumberObject(value) || isNumberType(value)); +const isNumber: IsNumber = (value: any, callback: ResultCallback = errorCallback): value is number => + callback(typeOf(value) === 'number' && isFinite(value) === true && (isNumberType(value) || isNumberObject(value))); ``` | Parameter | Type | Description | | :-------- | :---: | :---------- | | value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `number`. @@ -577,7 +624,7 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` ### isNumberObject -Use `isNumberObject()` or `is.numberObject()` to check if **any** `value` is an `object` type an instance of [`Number`][Number] and [`Object`][Object]. +Use `isNumberObject()` or `is.numberObject()` to check if **any** `value` is an `object` type and instance of [`Number`][Number] and [`Object`][Object]. ```typescript const isNumberObject: IsNumberObject = (value: any, callback: ResultCallback = errorCallback): value is number => @@ -587,28 +634,90 @@ const isNumberObject: IsNumberObject = (value: any, callback: ResultCallback = e | Parameter | Type | Description | | :-------- | :---: | :---------- | | value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a [`Number`][Number] instance. +```typescript +// Example usage +/** + * typeof === 'number' + * instanceof Function === false + * instanceof Number === false + * instanceof Object === false + */ +const NUMBER: any = 10304050; + +/** + * typeof === 'number' + * instanceof Function === false + * instanceof Number === false + * instanceof Object === false + */ +const NUMBER_INSTANCE: any = Number(NUMBER); + +/** + * typeof === 'number' + * instanceof Function === false + * instanceof Number === true + * instanceof Object === true + */ +const NUMBER_NEW_INSTANCE: any = new Number(NUMBER); + +isNumberObject(NUMBER); // false +isNumberObject(NUMBER_INSTANCE); // false +isNumberObject(NUMBER_NEW_INSTANCE); // true +``` + ---- ### isNumberType -Use `isNumber()` or `is.number()` to check if **any** `value` is a `number` type not an instance of [`Number`][Number] and [`Object`][Object] or `object` type instance of [`Number`][Number] and [`Object`][Object]. +Use `isNumberType()` or `is.numberType()` to check if **any** `value` is a `number` type not an instance of [`Number`][Number] and [`Object`][Object] or `object` type instance of [`Number`][Number] and [`Object`][Object]. ```typescript -const isNumber: IsNumber = (value: any): value is number => - typeOf(value) === 'number' && - isFinite(value) === true && - (isNumberObject(value) || isNumberType(value)); +const isNumberType: IsNumberType = (value: any, callback: ResultCallback = errorCallback): value is number => + callback(value instanceof Number === false && value instanceof Object === false && typeof value === 'number'); ``` | Parameter | Type | Description | | :-------- | :---: | :---------- | | value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `number`. +```typescript +// Example usage +/** + * typeof === 'number' + * instanceof Function === false + * instanceof Number === false + * instanceof Object === false + */ +const NUMBER: any = 10304050; + +/** + * typeof === 'number' + * instanceof Function === false + * instanceof Number === false + * instanceof Object === false + */ +const NUMBER_INSTANCE: any = Number(NUMBER); + +/** + * typeof === 'number' + * instanceof Function === false + * instanceof Number === true + * instanceof Object === true + */ +const NUMBER_NEW_INSTANCE: any = new Number(NUMBER); + +isNumberType(NUMBER); // true +isNumberType(NUMBER_INSTANCE); // true +isNumberType(NUMBER_NEW_INSTANCE); // false +``` + ---- ### isObject @@ -1048,7 +1157,7 @@ const guardObjectKey: GuardObjectKey = Date: Wed, 28 Apr 2021 11:40:56 +0200 Subject: [PATCH 149/201] test: categorize imports and add semicolon --- packages/type/src/is/test/is-number-object.spec.ts | 2 +- packages/type/src/is/test/is-number-type.spec.ts | 2 +- packages/type/src/is/test/is-number.spec.ts | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/type/src/is/test/is-number-object.spec.ts b/packages/type/src/is/test/is-number-object.spec.ts index b7241210..4042d0ea 100644 --- a/packages/type/src/is/test/is-number-object.spec.ts +++ b/packages/type/src/is/test/is-number-object.spec.ts @@ -57,7 +57,7 @@ describe(`isNumberObject`, () => { }); // null - it(`${NULL}`, () => expect(isNumberObject(NULL)).toBe(FALSE)) + it(`${NULL}`, () => expect(isNumberObject(NULL)).toBe(FALSE)); // number describe(`number`, () => { diff --git a/packages/type/src/is/test/is-number-type.spec.ts b/packages/type/src/is/test/is-number-type.spec.ts index 3b00f72f..40e3969f 100644 --- a/packages/type/src/is/test/is-number-type.spec.ts +++ b/packages/type/src/is/test/is-number-type.spec.ts @@ -59,7 +59,7 @@ describe(`isNumberType`, () => { }); // null - it(`${NULL}`, () => expect(isNumberType(NULL)).toBe(FALSE)) + it(`${NULL}`, () => expect(isNumberType(NULL)).toBe(FALSE)); // number describe(`number`, () => { diff --git a/packages/type/src/is/test/is-number.spec.ts b/packages/type/src/is/test/is-number.spec.ts index 0a29d458..dc325114 100644 --- a/packages/type/src/is/test/is-number.spec.ts +++ b/packages/type/src/is/test/is-number.spec.ts @@ -1,3 +1,6 @@ +// Function. +import { isNumber } from '../lib/is-number.func'; +// Type. import { BIGINT, BIGINT_INSTANCE } from './variables/big-int.const'; import { CLASS, Class } from './variables/class.const'; import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; @@ -8,7 +11,6 @@ import { OBJECT_ONE, OBJECT_TWO } from './variables/object.const'; import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; import { UNDEFINED } from './variables/undefined.const'; -import { isNumber } from '../lib/is-number.func'; import { notDefined } from './variables/not-defined.const'; /** * Checks From f7a864d9e732298e0979607296848f031a8afeed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 11:41:39 +0200 Subject: [PATCH 150/201] docs(isObject): update description and `key` parameter --- packages/type/src/is/lib/is-object.func.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/type/src/is/lib/is-object.func.ts b/packages/type/src/is/lib/is-object.func.ts index 00f7d441..bffe391c 100644 --- a/packages/type/src/is/lib/is-object.func.ts +++ b/packages/type/src/is/lib/is-object.func.ts @@ -5,9 +5,9 @@ import { typeOf } from '../../lib/type-of.func'; import { IsObject } from '../type/is-object.type'; import { Key } from '../../type/key.type'; /** - * Checks if any `value` is a generic `Obj` `object` type and `Object` instance with the possibility of containing `key`. + * Checks if any `value` is an `object` of a generic `Obj` type and `Object` instance with the possibility of containing the `key`. * @param value Any `value` to check. - * @param key Property name to find in `value`. + * @param key Property name to find in the `value`. * @returns A `boolean` indicating whether or not the `value` is an `object`. */ export const isObject: IsObject = (value: any, key?: Key): value is Obj => From 269d8e672294dbf104a8070be02adcfcc5855625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 11:58:41 +0200 Subject: [PATCH 151/201] test: add semicolon, new way if test `isObject` --- packages/type/src/is/test/is-object.spec.ts | 133 +++++++++++--------- packages/type/src/is/test/is-string.spec.ts | 2 +- 2 files changed, 78 insertions(+), 57 deletions(-) diff --git a/packages/type/src/is/test/is-object.spec.ts b/packages/type/src/is/test/is-object.spec.ts index d4780d9b..7f996a61 100644 --- a/packages/type/src/is/test/is-object.spec.ts +++ b/packages/type/src/is/test/is-object.spec.ts @@ -1,73 +1,94 @@ // Function. import { isObject } from '../lib/is-object.func'; // Variables. -import { BIGINT, BIGINT_INSTANCE } from './variables/big-int.const'; -import { CLASS, Class } from './variables/class.const'; -import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from './variables/boolean.const'; +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from './variables/big-int.const'; +import { Class, CLASS } from './variables/class.const'; +import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE, FALSE_EXPECTATION, TRUE_EXPECTATION } from './variables/boolean.const'; import { FUNCTION } from './variables/function.const'; import { NULL } from './variables/null.const'; import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; -import { OBJECT_ONE, OBJECT_TWO, ObjectOne, ObjectTwo } from './variables/object.const'; +import { OBJECT_ONE, OBJECT_TWO, ObjectOne, ObjectTwo, OBJECT_ONE_NEW, OBJECT_TWO_NEW } from './variables/object.const'; import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; import { UNDEFINED } from './variables/undefined.const'; -import { notDefined } from './variables/not-defined.const'; - /** * Checks * ✓ typeof === 'object' * ✓ instanceof Object */ -describe('isObject', () => { - // TRUE - it('is DEFINED', () => { - expect(isObject).toBeDefined(); - }); - it(`CLASS instance of class`, () => { - expect(isObject(CLASS)).toBeTruthy(); - }); - it(`'object' | Object`, () => { - expect(isObject(OBJECT_ONE)).toBeTruthy(); - expect(isObject(OBJECT_TWO)).toBeTruthy(); - }); +describe(`isObject`, () => { + // Defined. + it('is DEFINED', () => expect(isObject).toBeDefined()); - // FALSE - it(`'bigint'`, () => { - expect(isObject(BIGINT)).toBeFalsy(); - expect(isObject(BIGINT_INSTANCE)).toBeFalsy(); - }); - it(`'boolean' | Boolean`, () => { - expect(isObject(FALSE)).toBeFalsy(); - expect(isObject(TRUE)).toBeFalsy(); - expect(isObject(FALSE_INSTANCE)).toBeFalsy(); - expect(isObject(TRUE_INSTANCE)).toBeFalsy(); - }); - it(`Class`, () => { - expect(isObject(Class)).toBeFalsy(); - }); - it(`'function' | Function`, () => { - expect(isObject(FUNCTION)).toBeFalsy(); - }); - it(`null | NULL`, () => { - expect(isObject(null)).toBeFalsy(); - expect(isObject(NULL)).toBeFalsy(); - }); - it(`number and instance of Number`, () => { - expect(isObject(NUMBER)).toBeFalsy(); - expect(isObject(NUMBER_INSTANCE)).toBeFalsy(); - expect(isObject(NUMBER_NEW_INSTANCE)).toBeFalsy(); - }); - it(`string | String`, () => { - expect(isObject(STRING)).toBeFalsy(); - expect(isObject(STRING_INSTANCE)).toBeFalsy(); - expect(isObject(STRING_NEW_INSTANCE)).toBeFalsy(); - }); - it(`'symbol'`, () => { - expect(isObject(SYMBOL_NUMBER)).toBeFalsy(); - expect(isObject(SYMBOL_STRING)).toBeFalsy(); - }); - it(`'undefined'`, () => { - expect(isObject(notDefined)).toBeFalse(); - expect(isObject(UNDEFINED)).toBeFalse(); + // Checks ... + describe(`checks`, () => { + // ... arrays. + describe(`array`, () => { + // it(`${FUNCTION}`, () => expect(isObject(FUNCTION, 'function')).toBe(FALSE)); + // it(`${Class}`, () => expect(isObject(Class, 'function')).toBe(FALSE)); + }); + // ... function. + describe(`function`, () => { + it(`FUNCTION`, () => expect(isObject(FUNCTION)).toBe(FALSE)); + it(`Class`, () => expect(isObject(Class)).toBe(FALSE)); + }); + // ... objects. + describe('object', () => { + it(`CLASS`, () => expect(isObject(CLASS)).toBe(TRUE)); + it(`OBJECT_ONE`, () => expect(isObject(OBJECT_ONE)).toBe(TRUE)); + it(`OBJECT_TWO`, () => expect(isObject(OBJECT_TWO)).toBe(TRUE)); + it(`new Object(OBJECT_ONE_NEW})`, () => expect(isObject(OBJECT_ONE_NEW)).toBe(TRUE)); + it(`new Object(OBJECT_TWO_NEW})`, () => expect(isObject(OBJECT_TWO_NEW)).toBe(TRUE)); + + describe('OBJECT_ONE has the', () => { + it(`'key as string'`, () => expect(isObject(OBJECT_ONE, 'key as string')).toBe(TRUE)); + it(`key as string ${STRING}`, () => expect(isObject(OBJECT_ONE, STRING)).toBe(TRUE)); + it(`key as string instance ${STRING_NEW_INSTANCE}`, () => expect(isObject(OBJECT_ONE, STRING_NEW_INSTANCE)).toBe(TRUE)); + it(`key as number ${1030405027}`, () => expect(isObject(OBJECT_ONE, 1030405027)).toBe(TRUE)); + it(`key as number ${NUMBER}`, () => expect(isObject(OBJECT_ONE, NUMBER)).toBe(TRUE)); + it(`key as number instance ${NUMBER_NEW_INSTANCE}`, () => expect(isObject(OBJECT_ONE, NUMBER_NEW_INSTANCE)).toBe(TRUE)); + it(`key as SYMBOL_NUMBER`, () => expect(isObject(OBJECT_ONE, SYMBOL_NUMBER)).toBe(TRUE)); + it(`key as SYMBOL_STRING`, () => expect(isObject(OBJECT_ONE, SYMBOL_STRING)).toBe(TRUE)); + }); + }); + // ... primitives. + describe(`primitive`, () => { + // bigint + describe(`bigint`, () => { + it(`${BIGINT}`, () => expect(isObject(BIGINT)).toBe(FALSE)); + it(`${BIGINT_EXPECTATION}`, () => expect(isObject(BIGINT_INSTANCE)).toBe(FALSE)); + }); + + // boolean + describe(`boolean`, () => { + it(`${TRUE}`, () => expect(isObject(TRUE)).toBe(FALSE)); + it(`${FALSE}`, () => expect(isObject(FALSE)).toBe(FALSE)); + it(`${FALSE_EXPECTATION}`, () => expect(isObject(TRUE_INSTANCE)).toBe(FALSE)); + it(`${TRUE_EXPECTATION}`, () => expect(isObject(FALSE_INSTANCE)).toBe(FALSE)); + }); + + // null + it(`${NULL}`, () => expect(isObject(NULL)).toBe(FALSE)); + + // number + describe(`number`, () => { + it(`${NUMBER}`, () => expect(isObject(NUMBER)).toBe(FALSE)); + it(`Number(${NUMBER})`, () => expect(isObject(NUMBER_INSTANCE)).toBe(FALSE)); + it(`new Number(${NUMBER})`, () => expect(isObject(NUMBER_NEW_INSTANCE)).toBe(FALSE)); + }); + // string + describe(`string`, () => { + it(`${STRING}`, () => expect(isObject(STRING)).toBe(FALSE)); + it(`String(${STRING})`, () => expect(isObject(STRING_INSTANCE)).toBe(FALSE)); + it(`new String(${STRING})`, () => expect(isObject(STRING_NEW_INSTANCE)).toBe(FALSE)); + }); + // symbol + describe(`symbol`, () => { + it(`Symbol(${NUMBER})`, () => expect(isObject(SYMBOL_NUMBER)).toBe(FALSE)); + it(`Symbol(${STRING})`, () => expect(isObject(SYMBOL_STRING)).toBe(FALSE)); + }); + // undefined + it(`${UNDEFINED}`, () => expect(isObject(UNDEFINED)).toBe(FALSE)); + }); }); }); diff --git a/packages/type/src/is/test/is-string.spec.ts b/packages/type/src/is/test/is-string.spec.ts index 37b67709..ea5d3201 100644 --- a/packages/type/src/is/test/is-string.spec.ts +++ b/packages/type/src/is/test/is-string.spec.ts @@ -58,7 +58,7 @@ describe(`isString`, () => { }); // null - it(`${NULL}`, () => expect(isString(NULL)).toBe(FALSE)) + it(`${NULL}`, () => expect(isString(NULL)).toBe(FALSE)); // number describe(`number`, () => { From 0557983681f7e99ed38fe5d6e5eb46e890d379de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 12:08:42 +0200 Subject: [PATCH 152/201] refactor(isObjectKey): update jsdocs, add `callback` --- .../type/src/is/lib/is-object-key.func.ts | 30 ++++++++++++------- .../type/src/is/type/is-object-key.type.ts | 3 +- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/packages/type/src/is/lib/is-object-key.func.ts b/packages/type/src/is/lib/is-object-key.func.ts index 05a28a25..b04554e7 100644 --- a/packages/type/src/is/lib/is-object-key.func.ts +++ b/packages/type/src/is/lib/is-object-key.func.ts @@ -5,17 +5,27 @@ import { isObject } from './is-object.func'; // Type. import { IsObjectKey } from '../type/is-object-key.type'; import { Key } from '../../type/key.type'; +import { ResultCallback } from '../../type/result-callback.type'; +import { errorCallback } from '../../lib/error-callback.func'; /** - * Checks if any `value` is an `object` with its own specified keys of the `Key` type. + * Checks if any `value` is an `object` with its own specified `key` of the `Key` type. * @param value Any `value` to check if it contains a specified `key`. * @param key A `Key` type or an array of `Key` type to check the `value`. - * @returns A `boolean` indicating whether or not the `value` has its own specified keys. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `errorCallback`. + * @returns A `boolean` indicating whether or not the `value` is an `object` with its own specified keys. */ -export const isObjectKey: IsObjectKey = (value: any, key: Key | Key[]): value is Type => - isObject(value) ? - isArray(key) ? - key.every(k => isKey(k) ? ({}).hasOwnProperty.call(value, k) === true : false) - : isKey(key) ? - ({}).hasOwnProperty.call(value, key) - : false - : false; +export const isObjectKey: IsObjectKey = ( + value: any, + key: Key | Key[], + callback: ResultCallback = errorCallback +): value is Type => + callback( + isObject(value) ? + isArray(key) ? + key.every(k => isKey(k) ? ({}).hasOwnProperty.call(value, k) === true : false) + : isKey(key) ? + ({}).hasOwnProperty.call(value, key) + : false + : false + ); diff --git a/packages/type/src/is/type/is-object-key.type.ts b/packages/type/src/is/type/is-object-key.type.ts index dc5e6763..413db995 100644 --- a/packages/type/src/is/type/is-object-key.type.ts +++ b/packages/type/src/is/type/is-object-key.type.ts @@ -1,2 +1,3 @@ import { Key } from '../../type/key.type'; -export type IsObjectKey = (value: any, key: Key | Key[]) => value is Type; +import { ResultCallback } from '../../type/result-callback.type'; +export type IsObjectKey = (value: any, key: Key | Key[], callback?: ResultCallback) => value is Type; From b7d2121f5c540bfe79125cfa54774cce8f8e33a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 14:26:38 +0200 Subject: [PATCH 153/201] refactor(isBigInt): add `callback` --- packages/type/src/is/lib/is-big-int.func.ts | 9 ++++++--- packages/type/src/is/type/is-big-int.type.ts | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/type/src/is/lib/is-big-int.func.ts b/packages/type/src/is/lib/is-big-int.func.ts index 1d2e5b6a..f16f2c3f 100644 --- a/packages/type/src/is/lib/is-big-int.func.ts +++ b/packages/type/src/is/lib/is-big-int.func.ts @@ -1,12 +1,15 @@ // Function. +import { errorCallback } from '../../lib/error-callback.func'; import { typeOf } from '../../lib/type-of.func'; // Type. import { IsBigInt } from '../type/is-big-int.type'; +import { ResultCallback } from '../../type/result-callback.type'; /** * Checks if any `value` is a `bigint` type. * @param value Any `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `errorCallback`. * @returns A `boolean` indicating whether or not the `value` is a `bigint`. */ -export const isBigInt: IsBigInt = (value: any): value is bigint => - typeOf(value) === 'bigint' && - typeof value === 'bigint'; +export const isBigInt: IsBigInt = (value: any, callback: ResultCallback = errorCallback): value is bigint => + callback(typeOf(value) === 'bigint' && typeof value === 'bigint'); diff --git a/packages/type/src/is/type/is-big-int.type.ts b/packages/type/src/is/type/is-big-int.type.ts index 7242741a..8bf35b21 100644 --- a/packages/type/src/is/type/is-big-int.type.ts +++ b/packages/type/src/is/type/is-big-int.type.ts @@ -1 +1,2 @@ -export type IsBigInt = (value: any) => value is bigint; +import { ResultCallback } from '../../type/result-callback.type'; +export type IsBigInt = (value: any, callback?: ResultCallback) => value is bigint; From 0fdb10e30db55daf5b0ea031c18eb1c7f30ec379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 14:38:38 +0200 Subject: [PATCH 154/201] test: parameter`callback` --- packages/type/src/is/test/is-big-int.spec.ts | 8 ++++++++ packages/type/src/is/test/is-boolean.spec.ts | 8 ++++++++ packages/type/src/is/test/is-defined.spec.ts | 8 ++++++++ packages/type/src/is/test/is-function.spec.ts | 4 ++++ packages/type/src/is/test/is-key.spec.ts | 6 ++++++ packages/type/src/is/test/is-null.spec.ts | 4 ++++ packages/type/src/is/test/is-number-object.spec.ts | 6 ++++++ packages/type/src/is/test/is-number-type.spec.ts | 6 ++++++ packages/type/src/is/test/is-object-key.spec.ts | 6 ++++++ packages/type/src/is/test/is-object.spec.ts | 7 +++++++ packages/type/src/is/test/is-string.spec.ts | 7 +++++++ 11 files changed, 70 insertions(+) diff --git a/packages/type/src/is/test/is-big-int.spec.ts b/packages/type/src/is/test/is-big-int.spec.ts index 7413e226..a5319488 100644 --- a/packages/type/src/is/test/is-big-int.spec.ts +++ b/packages/type/src/is/test/is-big-int.spec.ts @@ -22,6 +22,10 @@ describe('isBigInt', () => { it(`'bigint'`, () => { expect(isBigInt(BIGINT)).toBe(TRUE); expect(isBigInt(BIGINT_INSTANCE)).toBe(TRUE); + isBigInt(BIGINT_INSTANCE, (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); }); // FALSE @@ -30,6 +34,10 @@ describe('isBigInt', () => { expect(isBigInt(TRUE)).toBe(FALSE); expect(isBigInt(FALSE_INSTANCE)).toBe(FALSE); expect(isBigInt(TRUE_INSTANCE)).toBe(FALSE); + isBigInt(FALSE, (result: boolean) => { + expect(result).toBe(FALSE); + return result; + }); }); it(`Class | CLASS`, () => { expect(isBigInt(Class)).toBe(FALSE); diff --git a/packages/type/src/is/test/is-boolean.spec.ts b/packages/type/src/is/test/is-boolean.spec.ts index f35089a5..2d556260 100644 --- a/packages/type/src/is/test/is-boolean.spec.ts +++ b/packages/type/src/is/test/is-boolean.spec.ts @@ -27,12 +27,20 @@ describe('isBoolean', () => { expect(isBoolean(TRUE_INSTANCE)).toBe(TRUE); expect(isBoolean(Boolean(false))).toBe(TRUE); expect(isBoolean(Boolean(true))).toBe(TRUE); + isBoolean(FALSE, (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); }); // FALSE it(`'bigint'`, () => { expect(isBoolean(BIGINT)).toBe(FALSE); expect(isBoolean(BIGINT_INSTANCE)).toBe(FALSE); + isBoolean(BIGINT, (result: boolean) => { + expect(result).toBe(FALSE); + return result; + }); }); it(`Class | CLASS`, () => { expect(isBoolean(Class)).toBe(FALSE); diff --git a/packages/type/src/is/test/is-defined.spec.ts b/packages/type/src/is/test/is-defined.spec.ts index c239c668..6ff0a2e4 100644 --- a/packages/type/src/is/test/is-defined.spec.ts +++ b/packages/type/src/is/test/is-defined.spec.ts @@ -28,6 +28,10 @@ describe('isDefined', () => { expect(isDefined(TRUE_INSTANCE)).toBe(TRUE); expect(isDefined(Boolean(false))).toBe(TRUE); expect(isDefined(Boolean(true))).toBe(TRUE); + isDefined(FALSE, (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); }); it(`'bigint'`, () => { expect(isDefined(BIGINT)).toBe(TRUE); @@ -65,5 +69,9 @@ describe('isDefined', () => { it(`'undefined'`, () => { expect(isDefined(notDefined)).toBe(FALSE); expect(isDefined(UNDEFINED)).toBe(FALSE); + isDefined(UNDEFINED, (result: boolean) => { + expect(result).toBe(FALSE); + return result; + }); }); }); diff --git a/packages/type/src/is/test/is-function.spec.ts b/packages/type/src/is/test/is-function.spec.ts index 6f1816b0..03866e05 100644 --- a/packages/type/src/is/test/is-function.spec.ts +++ b/packages/type/src/is/test/is-function.spec.ts @@ -27,6 +27,10 @@ describe('isFunction', () => { expect(isFunction(TRUE_INSTANCE)).toBe(FALSE); expect(isFunction(Boolean(false))).toBe(FALSE); expect(isFunction(Boolean(true))).toBe(FALSE); + isFunction(TRUE, (result: boolean) => { + expect(result).toBe(FALSE); + return result; + }); }); it(`'bigint'`, () => { expect(isFunction(BIGINT)).toBe(FALSE); diff --git a/packages/type/src/is/test/is-key.spec.ts b/packages/type/src/is/test/is-key.spec.ts index 53c42436..9e376ff1 100644 --- a/packages/type/src/is/test/is-key.spec.ts +++ b/packages/type/src/is/test/is-key.spec.ts @@ -18,6 +18,12 @@ describe(`isKey`, () => { // Checks ... describe(`checks`, () => { + it('callback', () => { + isKey('test', (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); + }); // ... arrays. describe(`array`, () => { // it(`${FUNCTION}`, () => expect(isKey(FUNCTION, 'function')).toBe(FALSE)); diff --git a/packages/type/src/is/test/is-null.spec.ts b/packages/type/src/is/test/is-null.spec.ts index 343e61b8..36c7ccfd 100644 --- a/packages/type/src/is/test/is-null.spec.ts +++ b/packages/type/src/is/test/is-null.spec.ts @@ -20,6 +20,10 @@ describe('isNull', () => { it(`null | NULL`, () => { expect(isNull(null)).toBe(TRUE); expect(isNull(NULL)).toBe(TRUE); + isNull(NULL, (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); }); // FALSE diff --git a/packages/type/src/is/test/is-number-object.spec.ts b/packages/type/src/is/test/is-number-object.spec.ts index 4042d0ea..91317881 100644 --- a/packages/type/src/is/test/is-number-object.spec.ts +++ b/packages/type/src/is/test/is-number-object.spec.ts @@ -22,6 +22,12 @@ describe(`isNumberObject`, () => { // Checks ... describe(`checks`, () => { + it('callback', () => { + isNumberObject(NUMBER_NEW_INSTANCE, (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); + }); // ... arrays. describe(`array`, () => { // it(`${FUNCTION}`, () => expect(isNumberObject(FUNCTION, 'function')).toBe(FALSE)); diff --git a/packages/type/src/is/test/is-number-type.spec.ts b/packages/type/src/is/test/is-number-type.spec.ts index 40e3969f..1bfb57c4 100644 --- a/packages/type/src/is/test/is-number-type.spec.ts +++ b/packages/type/src/is/test/is-number-type.spec.ts @@ -24,6 +24,12 @@ describe(`isNumberType`, () => { // Checks ... describe(`checks`, () => { + it('callback', () => { + isNumberType(NUMBER, (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); + }); // ... arrays. describe(`array`, () => { // it(`${FUNCTION}`, () => expect(isNumberType(FUNCTION, 'function')).toBe(FALSE)); diff --git a/packages/type/src/is/test/is-object-key.spec.ts b/packages/type/src/is/test/is-object-key.spec.ts index b19e5197..6c38b0b0 100644 --- a/packages/type/src/is/test/is-object-key.spec.ts +++ b/packages/type/src/is/test/is-object-key.spec.ts @@ -18,6 +18,12 @@ describe(`isObjectKey`, () => { // Checks ... describe(`checks`, () => { + it('callback', () => { + isObjectKey(CLASS, ['firstName', 'surname'], (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); + }); // ... instance. describe(`instance`, () => { describe(`CLASS`, () => { diff --git a/packages/type/src/is/test/is-object.spec.ts b/packages/type/src/is/test/is-object.spec.ts index 7f996a61..a2a80b02 100644 --- a/packages/type/src/is/test/is-object.spec.ts +++ b/packages/type/src/is/test/is-object.spec.ts @@ -22,6 +22,13 @@ describe(`isObject`, () => { // Checks ... describe(`checks`, () => { + it('callback', () => { + // isObject(OBJECT_ONE, (result: boolean) => { + // expect(result).toBe(TRUE); + // return result; + // }); + }); + // ... arrays. describe(`array`, () => { // it(`${FUNCTION}`, () => expect(isObject(FUNCTION, 'function')).toBe(FALSE)); diff --git a/packages/type/src/is/test/is-string.spec.ts b/packages/type/src/is/test/is-string.spec.ts index ea5d3201..00728cc8 100644 --- a/packages/type/src/is/test/is-string.spec.ts +++ b/packages/type/src/is/test/is-string.spec.ts @@ -23,6 +23,13 @@ describe(`isString`, () => { // Checks ... describe(`checks`, () => { + it('callback', () => { + isString(STRING, (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); + }); + // ... arrays. describe(`array`, () => { // it(`${FUNCTION}`, () => expect(isString(FUNCTION, 'function')).toBe(FALSE)); From cdbc5a601b2f3b4957d69e61786e87034bdcc03d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 14:50:42 +0200 Subject: [PATCH 155/201] refactor(isSymbol): add parameter `callback --- packages/type/src/is/lib/is-symbol.func.ts | 9 ++++++--- packages/type/src/is/type/is-symbol.type.ts | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/type/src/is/lib/is-symbol.func.ts b/packages/type/src/is/lib/is-symbol.func.ts index 0503cc8c..486baef1 100644 --- a/packages/type/src/is/lib/is-symbol.func.ts +++ b/packages/type/src/is/lib/is-symbol.func.ts @@ -1,12 +1,15 @@ // Function. +import { errorCallback } from '../../lib/error-callback.func'; import { typeOf } from '../../lib/type-of.func'; // Type. import { IsSymbol } from '../type/is-symbol.type'; +import { ResultCallback } from '../../type/result-callback.type'; /** * Checks if any `value` is a `symbol` type. * @param value Any `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `errorCallback`. * @returns A `boolean` indicating whether or not the `value` is a `symbol`. */ -export const isSymbol: IsSymbol = (value: any): value is symbol => - typeOf(value) === 'symbol' && - typeof value === 'symbol'; +export const isSymbol: IsSymbol = (value: any, callback: ResultCallback = errorCallback): value is symbol => + callback(typeOf(value) === 'symbol' && typeof value === 'symbol'); diff --git a/packages/type/src/is/type/is-symbol.type.ts b/packages/type/src/is/type/is-symbol.type.ts index ad5209ff..a3466e95 100644 --- a/packages/type/src/is/type/is-symbol.type.ts +++ b/packages/type/src/is/type/is-symbol.type.ts @@ -1 +1,2 @@ -export type IsSymbol = (value: any) => value is symbol; +import { ResultCallback } from '../../type/result-callback.type'; +export type IsSymbol = (value: any, callback?: ResultCallback) => value is symbol; From f0cb95ec9ba7e2006f5016922cff7aae6ba15515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 14:51:13 +0200 Subject: [PATCH 156/201] test: update - `isNumber` - `isSymbol` - `isType` --- packages/type/src/is/test/is-number.spec.ts | 4 + packages/type/src/is/test/is-symbol.spec.ts | 88 +++++++++++++++++++-- packages/type/src/is/test/is-type.spec.ts | 7 ++ 3 files changed, 93 insertions(+), 6 deletions(-) diff --git a/packages/type/src/is/test/is-number.spec.ts b/packages/type/src/is/test/is-number.spec.ts index dc325114..7eb650a6 100644 --- a/packages/type/src/is/test/is-number.spec.ts +++ b/packages/type/src/is/test/is-number.spec.ts @@ -27,6 +27,10 @@ describe('isNumber', () => { expect(isNumber(NUMBER)).toBe(TRUE); expect(isNumber(NUMBER_INSTANCE)).toBe(TRUE); expect(isNumber(NUMBER_NEW_INSTANCE)).toBe(TRUE); + isNumber(NUMBER_NEW_INSTANCE, (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); }); // FALSE diff --git a/packages/type/src/is/test/is-symbol.spec.ts b/packages/type/src/is/test/is-symbol.spec.ts index f9fb33b6..a039e457 100644 --- a/packages/type/src/is/test/is-symbol.spec.ts +++ b/packages/type/src/is/test/is-symbol.spec.ts @@ -1,14 +1,90 @@ +// Function. +import { isSymbol } from '../lib/is-symbol.func'; +// Variables. +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from './variables/big-int.const'; +import { Class, CLASS } from './variables/class.const'; +import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE, FALSE_EXPECTATION, TRUE_EXPECTATION } from './variables/boolean.const'; +import { FUNCTION } from './variables/function.const'; +import { NULL } from './variables/null.const'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; +import { OBJECT_ONE, OBJECT_TWO, ObjectOne, ObjectTwo, OBJECT_ONE_NEW, OBJECT_TWO_NEW } from './variables/object.const'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; +import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; +import { UNDEFINED } from './variables/undefined.const'; + /** * Checks * ✓ typeof === 'symbol' */ +describe(`isSymbol`, () => { + // Defined. + it('is DEFINED', () => expect(isSymbol).toBeDefined()); -import { isSymbol } from '../lib/is-symbol.func'; + // Checks ... + describe(`checks`, () => { + it('callback', () => { + isSymbol(SYMBOL_NUMBER, (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); + }); + + // ... arrays. + describe(`array`, () => { + // it(`${FUNCTION}`, () => expect(isSymbol(FUNCTION, 'function')).toBe(FALSE)); + // it(`${Class}`, () => expect(isSymbol(Class, 'function')).toBe(FALSE)); + }); + // ... function. + describe(`function`, () => { + it(`FUNCTION`, () => expect(isSymbol(FUNCTION)).toBe(FALSE)); + it(`Class`, () => expect(isSymbol(Class)).toBe(FALSE)); + }); + // ... objects. + describe('object', () => { + it(`CLASS`, () => expect(isSymbol(CLASS)).toBe(FALSE)); + it(`OBJECT_ONE`, () => expect(isSymbol(OBJECT_ONE)).toBe(FALSE)); + it(`OBJECT_TWO`, () => expect(isSymbol(OBJECT_TWO)).toBe(FALSE)); + it(`new Object(OBJECT_ONE_NEW})`, () => expect(isSymbol(OBJECT_ONE_NEW)).toBe(FALSE)); + it(`new Object(OBJECT_TWO_NEW})`, () => expect(isSymbol(OBJECT_TWO_NEW)).toBe(FALSE)); + }); + // ... primitives. + describe(`primitive`, () => { + // bigint + describe(`bigint`, () => { + it(`${BIGINT}`, () => expect(isSymbol(BIGINT)).toBe(FALSE)); + it(`${BIGINT_EXPECTATION}`, () => expect(isSymbol(BIGINT_INSTANCE)).toBe(FALSE)); + }); + + // boolean + describe(`boolean`, () => { + it(`${TRUE}`, () => expect(isSymbol(TRUE)).toBe(FALSE)); + it(`${FALSE}`, () => expect(isSymbol(FALSE)).toBe(FALSE)); + it(`${FALSE_EXPECTATION}`, () => expect(isSymbol(TRUE_INSTANCE)).toBe(FALSE)); + it(`${TRUE_EXPECTATION}`, () => expect(isSymbol(FALSE_INSTANCE)).toBe(FALSE)); + }); -describe('isSymbol', () => { - // TRUE - it('is DEFINED', () => { - expect(isSymbol).toBeDefined(); - }); + // null + it(`${NULL}`, () => expect(isSymbol(NULL)).toBe(FALSE)); + // number + describe(`number`, () => { + it(`${NUMBER}`, () => expect(isSymbol(NUMBER)).toBe(FALSE)); + it(`Number(${NUMBER})`, () => expect(isSymbol(NUMBER_INSTANCE)).toBe(FALSE)); + it(`new Number(${NUMBER})`, () => expect(isSymbol(NUMBER_NEW_INSTANCE)).toBe(FALSE)); + }); + // string + describe(`string`, () => { + it(`${STRING}`, () => expect(isSymbol(STRING)).toBe(TRUE)); + it(`String(${STRING})`, () => expect(isSymbol(STRING_INSTANCE)).toBe(TRUE)); + it(`new String(${STRING})`, () => expect(isSymbol(STRING_NEW_INSTANCE)).toBe(TRUE)); + }); + // symbol + describe(`symbol`, () => { + it(`Symbol(${NUMBER})`, () => expect(isSymbol(SYMBOL_NUMBER)).toBe(TRUE)); + it(`Symbol(${STRING})`, () => expect(isSymbol(SYMBOL_STRING)).toBe(TRUE)); + }); + // undefined + it(`${UNDEFINED}`, () => expect(isSymbol(UNDEFINED)).toBe(FALSE)); + }); + }); }); diff --git a/packages/type/src/is/test/is-type.spec.ts b/packages/type/src/is/test/is-type.spec.ts index eaf903ff..4cad2294 100644 --- a/packages/type/src/is/test/is-type.spec.ts +++ b/packages/type/src/is/test/is-type.spec.ts @@ -18,6 +18,13 @@ describe(`isType`, () => { // Checks ... describe(`checks`, () => { + it('callback', () => { + // isType('test', (result: boolean) => { + // expect(result).toBe(TRUE); + // return result; + // }); + }); + // ... instance. describe(`instance`, () => it(`Class`, () => expect(isType(CLASS, Class)).toBe(TRUE))); From 993acc873ff3d7bd445125430b23d1020dc182fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 15:06:30 +0200 Subject: [PATCH 157/201] test(isSymbol): fix check string --- packages/type/src/is/test/is-symbol.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/type/src/is/test/is-symbol.spec.ts b/packages/type/src/is/test/is-symbol.spec.ts index a039e457..7b231910 100644 --- a/packages/type/src/is/test/is-symbol.spec.ts +++ b/packages/type/src/is/test/is-symbol.spec.ts @@ -74,9 +74,9 @@ describe(`isSymbol`, () => { }); // string describe(`string`, () => { - it(`${STRING}`, () => expect(isSymbol(STRING)).toBe(TRUE)); - it(`String(${STRING})`, () => expect(isSymbol(STRING_INSTANCE)).toBe(TRUE)); - it(`new String(${STRING})`, () => expect(isSymbol(STRING_NEW_INSTANCE)).toBe(TRUE)); + it(`${STRING}`, () => expect(isSymbol(STRING)).toBe(FALSE)); + it(`String(${STRING})`, () => expect(isSymbol(STRING_INSTANCE)).toBe(FALSE)); + it(`new String(${STRING})`, () => expect(isSymbol(STRING_NEW_INSTANCE)).toBe(FALSE)); }); // symbol describe(`symbol`, () => { From d046d0e205aa8e2e3260f8070fe8bdf0953b1e2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 15:08:48 +0200 Subject: [PATCH 158/201] refactor: change `errorCallback` to `resultCallback` --- packages/type/src/is/lib/is-big-int.func.ts | 6 +++--- packages/type/src/is/lib/is-boolean-object.func.ts | 6 +++--- packages/type/src/is/lib/is-boolean-type.func.ts | 6 +++--- packages/type/src/is/lib/is-boolean.func.ts | 6 +++--- packages/type/src/is/lib/is-defined.func.ts | 6 +++--- packages/type/src/is/lib/is-function.func.ts | 6 +++--- packages/type/src/is/lib/is-instance.func.ts | 6 +++--- packages/type/src/is/lib/is-key.func.ts | 6 +++--- packages/type/src/is/lib/is-null.func.ts | 6 +++--- packages/type/src/is/lib/is-number-object.func.ts | 6 +++--- packages/type/src/is/lib/is-number-type.func.ts | 6 +++--- packages/type/src/is/lib/is-number.func.ts | 6 +++--- packages/type/src/is/lib/is-object-key.func.ts | 6 +++--- packages/type/src/is/lib/is-string-object.func.ts | 6 +++--- packages/type/src/is/lib/is-string-type.func.ts | 6 +++--- packages/type/src/is/lib/is-string.func.ts | 7 ++++--- packages/type/src/is/lib/is-symbol.func.ts | 6 +++--- packages/type/src/is/lib/is-undefined.func.ts | 10 ++++++---- packages/type/src/is/type/is-primitive.type.ts | 6 +++--- packages/type/src/is/type/is-undefined.type.ts | 3 ++- packages/type/src/lib/error-callback.func.ts | 2 -- packages/type/src/lib/result-callback.func.ts | 2 ++ 22 files changed, 65 insertions(+), 61 deletions(-) delete mode 100644 packages/type/src/lib/error-callback.func.ts create mode 100644 packages/type/src/lib/result-callback.func.ts diff --git a/packages/type/src/is/lib/is-big-int.func.ts b/packages/type/src/is/lib/is-big-int.func.ts index f16f2c3f..39e2649c 100644 --- a/packages/type/src/is/lib/is-big-int.func.ts +++ b/packages/type/src/is/lib/is-big-int.func.ts @@ -1,5 +1,5 @@ // Function. -import { errorCallback } from '../../lib/error-callback.func'; +import { resultCallback } from '../../lib/result-callback.func'; import { typeOf } from '../../lib/type-of.func'; // Type. import { IsBigInt } from '../type/is-big-int.type'; @@ -8,8 +8,8 @@ import { ResultCallback } from '../../type/result-callback.type'; * Checks if any `value` is a `bigint` type. * @param value Any `value` to check. * @param callback `ResultCallback` function to handle result before returns. - * @callback `errorCallback`. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is a `bigint`. */ -export const isBigInt: IsBigInt = (value: any, callback: ResultCallback = errorCallback): value is bigint => +export const isBigInt: IsBigInt = (value: any, callback: ResultCallback = resultCallback): value is bigint => callback(typeOf(value) === 'bigint' && typeof value === 'bigint'); diff --git a/packages/type/src/is/lib/is-boolean-object.func.ts b/packages/type/src/is/lib/is-boolean-object.func.ts index e4151916..9d7766d8 100644 --- a/packages/type/src/is/lib/is-boolean-object.func.ts +++ b/packages/type/src/is/lib/is-boolean-object.func.ts @@ -1,5 +1,5 @@ // Function. -import { errorCallback } from '../../lib/error-callback.func'; +import { resultCallback } from '../../lib/result-callback.func'; // Type. import { IsBooleanObject } from '../type/is-boolean-object.type'; import { ResultCallback } from '../../type/result-callback.type'; @@ -8,8 +8,8 @@ import { ResultCallback } from '../../type/result-callback.type'; * @function `isBooleanObject` * @param value Any `value` to check. * @param callback `ResultCallback` function to handle result before returns. - * @callback `errorCallback`. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is a `Boolean` instance. */ -export const isBooleanObject: IsBooleanObject = (value: any, callback: ResultCallback = errorCallback): value is boolean => +export const isBooleanObject: IsBooleanObject = (value: any, callback: ResultCallback = resultCallback): value is boolean => callback(typeof value === 'object' && value instanceof Boolean === true && value instanceof Object === true); diff --git a/packages/type/src/is/lib/is-boolean-type.func.ts b/packages/type/src/is/lib/is-boolean-type.func.ts index d2cb0069..9d5e8135 100644 --- a/packages/type/src/is/lib/is-boolean-type.func.ts +++ b/packages/type/src/is/lib/is-boolean-type.func.ts @@ -1,5 +1,5 @@ // Function. -import { errorCallback } from '../../lib/error-callback.func'; +import { resultCallback } from '../../lib/result-callback.func'; // Type. import { IsBooleanType } from '../type/is-boolean-type.type'; import { ResultCallback } from '../../type/result-callback.type'; @@ -8,10 +8,10 @@ import { ResultCallback } from '../../type/result-callback.type'; * @function `isBooleanType` * @param value Any `value` to check. * @param callback `ResultCallback` function to handle result before returns. - * @callback `errorCallback`. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is a `boolean` type. */ -export const isBooleanType: IsBooleanType = (value: any, callback: ResultCallback = errorCallback): value is boolean => +export const isBooleanType: IsBooleanType = (value: any, callback: ResultCallback = resultCallback): value is boolean => callback( value instanceof Boolean === false && value instanceof Object === false && diff --git a/packages/type/src/is/lib/is-boolean.func.ts b/packages/type/src/is/lib/is-boolean.func.ts index 517680ce..2205cfd3 100644 --- a/packages/type/src/is/lib/is-boolean.func.ts +++ b/packages/type/src/is/lib/is-boolean.func.ts @@ -1,7 +1,7 @@ // Function. -import { errorCallback } from '../../lib/error-callback.func'; import { isBooleanObject } from './is-boolean-object.func'; import { isBooleanType } from './is-boolean-type.func'; +import { resultCallback } from '../../lib/result-callback.func'; import { typeOf } from '../../lib/type-of.func'; // Type. import { IsBoolean } from '../type/is-boolean.type'; @@ -10,8 +10,8 @@ import { ResultCallback } from '../../type/result-callback.type'; * Checks if any `value` is a `boolean` type not instance of `Boolean` and `Object` or `object` type instance of `Boolean` and `Object`. * @param value Any `value` to check. * @param callback `ResultCallback` function to handle result before returns. - * @callback `errorCallback`. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is a `boolean`. */ -export const isBoolean: IsBoolean = (value: any, callback: ResultCallback = errorCallback): value is boolean => +export const isBoolean: IsBoolean = (value: any, callback: ResultCallback = resultCallback): value is boolean => callback(typeOf(value) === 'boolean' && (isBooleanType(value) || isBooleanObject(value))); diff --git a/packages/type/src/is/lib/is-defined.func.ts b/packages/type/src/is/lib/is-defined.func.ts index 5cc05dce..75048ce8 100644 --- a/packages/type/src/is/lib/is-defined.func.ts +++ b/packages/type/src/is/lib/is-defined.func.ts @@ -1,5 +1,5 @@ // Function. -import { errorCallback } from '../../lib/error-callback.func'; +import { resultCallback } from '../../lib/result-callback.func'; import { typeOf } from '../../lib/type-of.func'; // Type. import { IsDefined } from '../type/is-defined.type'; @@ -8,8 +8,8 @@ import { ResultCallback } from '../../type/result-callback.type'; * Checks if an unknown `value` is NOT an `undefined` type and is NOT equal to `undefined`. * @param value An `unknown` `value` to check. * @param callback `ResultCallback` function to handle result before returns. - * @callback `errorCallback`. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is defined, not `undefined`. */ -export const isDefined: IsDefined = (value: unknown, callback: ResultCallback = errorCallback): boolean => +export const isDefined: IsDefined = (value: unknown, callback: ResultCallback = resultCallback): boolean => callback(typeOf(value) !== 'undefined' && typeof value !== 'undefined' && value !== undefined); diff --git a/packages/type/src/is/lib/is-function.func.ts b/packages/type/src/is/lib/is-function.func.ts index 19168dd0..3cf26994 100644 --- a/packages/type/src/is/lib/is-function.func.ts +++ b/packages/type/src/is/lib/is-function.func.ts @@ -1,5 +1,5 @@ // Function. -import { errorCallback } from '../../lib/error-callback.func'; +import { resultCallback } from '../../lib/result-callback.func'; import { typeOf } from '../../lib/type-of.func'; // Type. import { Func } from '../../type/func.type'; @@ -9,10 +9,10 @@ import { ResultCallback } from '../../type/result-callback.type'; * Checks if any `value` is a `function` type, an instance of `Function` and `Object`. * @param value Any `value` to check. * @param callback `ResultCallback` function to handle result before returns. - * @callback `errorCallback`. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is a `function`. */ -export const isFunction: IsFunction = (value: any, callback: ResultCallback = errorCallback): value is Func => +export const isFunction: IsFunction = (value: any, callback: ResultCallback = resultCallback): value is Func => callback( typeOf(value) === 'function' && typeof value === 'function' && diff --git a/packages/type/src/is/lib/is-instance.func.ts b/packages/type/src/is/lib/is-instance.func.ts index 374268f4..66dd8122 100644 --- a/packages/type/src/is/lib/is-instance.func.ts +++ b/packages/type/src/is/lib/is-instance.func.ts @@ -1,7 +1,7 @@ // Function. -import { errorCallback } from '../../lib/error-callback.func'; import { isFunction } from './is-function.func'; import { isObject } from './is-object.func'; +import { resultCallback } from '../../lib/result-callback.func'; // Type. import { Constructor } from '../../type/constructor.type'; import { IsInstance } from '../type/is-instance.type'; @@ -11,13 +11,13 @@ import { ResultCallback } from '../../type/result-callback.type'; * @param value Any `value` to compare with the `instance`. * @param instance A generic `Obj` `Constructor` type to create an `instance` to compare with the `value`. * @param callback `ResultCallback` function to handle result before returns. - * @callback `errorCallback`. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is an `instance` of a generic `Obj`. */ export const isInstance: IsInstance = ( value: any, instance: Constructor, - callback: ResultCallback = errorCallback + callback: ResultCallback = resultCallback ): value is Obj => callback( isObject(value) ? diff --git a/packages/type/src/is/lib/is-key.func.ts b/packages/type/src/is/lib/is-key.func.ts index eddd9bc8..f906eeed 100644 --- a/packages/type/src/is/lib/is-key.func.ts +++ b/packages/type/src/is/lib/is-key.func.ts @@ -1,8 +1,8 @@ // Function. -import { errorCallback } from '../../lib/error-callback.func'; import { isNumber } from './is-number.func'; import { isString } from './is-string.func'; import { isSymbol } from './is-symbol.func'; +import { resultCallback } from '../../lib/result-callback.func'; // Type. import { IsKey } from '../type/is-key.type'; import { Key } from '../../type/key.type'; @@ -11,8 +11,8 @@ import { ResultCallback } from '../../type/result-callback.type'; * Checks if any `value` is one of the `string`, `number`, or `symbol`. * @param value Any `value` to check. * @param callback `ResultCallback` function to handle result before returns. - * @callback `errorCallback`. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is a `Key`. */ -export const isKey: IsKey = (value: any, callback: ResultCallback = errorCallback): value is Key => +export const isKey: IsKey = (value: any, callback: ResultCallback = resultCallback): value is Key => callback(isString(value) || isNumber(value) || isSymbol(value)); diff --git a/packages/type/src/is/lib/is-null.func.ts b/packages/type/src/is/lib/is-null.func.ts index 0f888ce0..1b69045b 100644 --- a/packages/type/src/is/lib/is-null.func.ts +++ b/packages/type/src/is/lib/is-null.func.ts @@ -1,5 +1,5 @@ // Function. -import { errorCallback } from '../../lib/error-callback.func'; +import { resultCallback } from '../../lib/result-callback.func'; import { typeOf } from '../../lib/type-of.func'; // Type. import { IsNull } from '../type/is-null.type'; @@ -8,8 +8,8 @@ import { ResultCallback } from '../../type/result-callback.type'; * Checks if any `value` is an `object` type and equal to `null`. * @param value Any `value` to check. * @param callback `ResultCallback` function to handle result before returns. - * @callback `errorCallback`. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is `null`. */ -export const isNull: IsNull = (value: any, callback: ResultCallback = errorCallback): value is null => +export const isNull: IsNull = (value: any, callback: ResultCallback = resultCallback): value is null => callback(typeOf(value) === 'null' && typeof value === 'object' && value === null); diff --git a/packages/type/src/is/lib/is-number-object.func.ts b/packages/type/src/is/lib/is-number-object.func.ts index ebbff95d..f6563648 100644 --- a/packages/type/src/is/lib/is-number-object.func.ts +++ b/packages/type/src/is/lib/is-number-object.func.ts @@ -1,5 +1,5 @@ // Function. -import { errorCallback } from '../../lib/error-callback.func'; +import { resultCallback } from '../../lib/result-callback.func'; // Type. import { IsNumberObject } from '../type/is-number-object.type'; import { ResultCallback } from '../../type/result-callback.type'; @@ -7,8 +7,8 @@ import { ResultCallback } from '../../type/result-callback.type'; * Checks if any `value` is an `object` type and instance of `Number` and `Object`. * @param value Any `value` to check. * @param callback `ResultCallback` function to handle result before returns. - * @callback `errorCallback`. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is a `Number` instance. */ -export const isNumberObject: IsNumberObject = (value: any, callback: ResultCallback = errorCallback): value is number => +export const isNumberObject: IsNumberObject = (value: any, callback: ResultCallback = resultCallback): value is number => callback(typeof value === 'object' && value instanceof Number === true && value instanceof Object === true); diff --git a/packages/type/src/is/lib/is-number-type.func.ts b/packages/type/src/is/lib/is-number-type.func.ts index cf9584dd..073df8c6 100644 --- a/packages/type/src/is/lib/is-number-type.func.ts +++ b/packages/type/src/is/lib/is-number-type.func.ts @@ -1,5 +1,5 @@ // Function. -import { errorCallback } from '../../lib/error-callback.func'; +import { resultCallback } from '../../lib/result-callback.func'; // Type. import { IsNumberType } from '../type/is-number-type.type'; import { ResultCallback } from '../../type/result-callback.type'; @@ -7,8 +7,8 @@ import { ResultCallback } from '../../type/result-callback.type'; * Checks if any `value` is a `boolean` type not an instance of `Boolean` and `Object`, and equal to `true` or `false`. * @param value Any `value` to check. * @param callback `ResultCallback` function to handle result before returns. - * @callback `errorCallback`. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is a `number` type. */ -export const isNumberType: IsNumberType = (value: any, callback: ResultCallback = errorCallback): value is number => +export const isNumberType: IsNumberType = (value: any, callback: ResultCallback = resultCallback): value is number => callback(value instanceof Number === false && value instanceof Object === false && typeof value === 'number'); diff --git a/packages/type/src/is/lib/is-number.func.ts b/packages/type/src/is/lib/is-number.func.ts index 33cd8754..636078c5 100644 --- a/packages/type/src/is/lib/is-number.func.ts +++ b/packages/type/src/is/lib/is-number.func.ts @@ -1,7 +1,7 @@ // Function. -import { errorCallback } from '../../lib/error-callback.func'; import { isNumberObject } from './is-number-object.func'; import { isNumberType } from './is-number-type.func'; +import { resultCallback } from '../../lib/result-callback.func'; import { typeOf } from '../../lib/type-of.func'; // Type. import { IsNumber } from '../type/is-number.type'; @@ -10,8 +10,8 @@ import { ResultCallback } from '../../type/result-callback.type'; * Checks if any `value` is a `number` type not an instance of `Number` and `Object` or `object` type instance of `Number` and `Object`. * @param value Any `value` to check. * @param callback `ResultCallback` function to handle result before returns. - * @callback `errorCallback`. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is a `number`. */ -export const isNumber: IsNumber = (value: any, callback: ResultCallback = errorCallback): value is number => +export const isNumber: IsNumber = (value: any, callback: ResultCallback = resultCallback): value is number => callback(typeOf(value) === 'number' && isFinite(value) === true && (isNumberType(value) || isNumberObject(value))); diff --git a/packages/type/src/is/lib/is-object-key.func.ts b/packages/type/src/is/lib/is-object-key.func.ts index b04554e7..d0967de0 100644 --- a/packages/type/src/is/lib/is-object-key.func.ts +++ b/packages/type/src/is/lib/is-object-key.func.ts @@ -6,19 +6,19 @@ import { isObject } from './is-object.func'; import { IsObjectKey } from '../type/is-object-key.type'; import { Key } from '../../type/key.type'; import { ResultCallback } from '../../type/result-callback.type'; -import { errorCallback } from '../../lib/error-callback.func'; +import { resultCallback } from '../../lib/result-callback.func'; /** * Checks if any `value` is an `object` with its own specified `key` of the `Key` type. * @param value Any `value` to check if it contains a specified `key`. * @param key A `Key` type or an array of `Key` type to check the `value`. * @param callback `ResultCallback` function to handle result before returns. - * @callback `errorCallback`. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is an `object` with its own specified keys. */ export const isObjectKey: IsObjectKey = ( value: any, key: Key | Key[], - callback: ResultCallback = errorCallback + callback: ResultCallback = resultCallback ): value is Type => callback( isObject(value) ? diff --git a/packages/type/src/is/lib/is-string-object.func.ts b/packages/type/src/is/lib/is-string-object.func.ts index 0a8db9de..21519df3 100644 --- a/packages/type/src/is/lib/is-string-object.func.ts +++ b/packages/type/src/is/lib/is-string-object.func.ts @@ -1,5 +1,5 @@ // Function. -import { errorCallback } from '../../lib/error-callback.func'; +import { resultCallback } from '../../lib/result-callback.func'; // Type. import { IsStringObject } from '../type/is-string-object.type'; import { ResultCallback } from '../../type/result-callback.type'; @@ -7,8 +7,8 @@ import { ResultCallback } from '../../type/result-callback.type'; * Checks if any `value` is an `object` type instance of `String` and `Object`. * @param value Any `value` to check. * @param callback `ResultCallback` function to handle result before returns. - * @callback `errorCallback`. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is a `String` instance. */ -export const isStringObject: IsStringObject = (value: any, callback: ResultCallback = errorCallback): value is string => +export const isStringObject: IsStringObject = (value: any, callback: ResultCallback = resultCallback): value is string => callback(value instanceof Object === true && value instanceof String === true && typeof value === 'object'); diff --git a/packages/type/src/is/lib/is-string-type.func.ts b/packages/type/src/is/lib/is-string-type.func.ts index a3ebfe78..d6237968 100644 --- a/packages/type/src/is/lib/is-string-type.func.ts +++ b/packages/type/src/is/lib/is-string-type.func.ts @@ -1,5 +1,5 @@ // Function. -import { errorCallback } from '../../lib/error-callback.func'; +import { resultCallback } from '../../lib/result-callback.func'; // Type. import { IsStringType } from '../type/is-string-type.type'; import { ResultCallback } from '../../type/result-callback.type'; @@ -7,8 +7,8 @@ import { ResultCallback } from '../../type/result-callback.type'; * Checks if any `value` is a `string` type not instance of `String` and `Object`. * @param value Any `value` to check. * @param callback `ResultCallback` function to handle result before returns. - * @callback `errorCallback`. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the value is a `string`. */ -export const isStringType: IsStringType = (value: any, callback: ResultCallback = errorCallback): value is string => +export const isStringType: IsStringType = (value: any, callback: ResultCallback = resultCallback): value is string => callback(value instanceof Object === false && value instanceof String === false && typeof value === 'string'); diff --git a/packages/type/src/is/lib/is-string.func.ts b/packages/type/src/is/lib/is-string.func.ts index 2a7689d7..70f193d4 100644 --- a/packages/type/src/is/lib/is-string.func.ts +++ b/packages/type/src/is/lib/is-string.func.ts @@ -1,4 +1,4 @@ -import { errorCallback } from '../../lib/error-callback.func'; +import { resultCallback } from '../../lib/result-callback.func'; import { isStringObject } from './is-string-object.func'; import { isStringType } from './is-string-type.func'; import { typeOf } from '../../lib/type-of.func'; @@ -8,8 +8,9 @@ import { ResultCallback } from '../../type/result-callback.type'; /** * Checks if any `value` is a `string` type, not instance of `Object` and `String` or `object` type and instance of `String` and `Object`. * @param value Any `value` to check. - * @param callback `ResultCallback` function to handle result before return. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is a `string`. */ -export const isString: IsString = (value: any, callback: ResultCallback = errorCallback): value is string => +export const isString: IsString = (value: any, callback: ResultCallback = resultCallback): value is string => callback(typeOf(value) === 'string' && (isStringObject(value) || isStringType(value))); diff --git a/packages/type/src/is/lib/is-symbol.func.ts b/packages/type/src/is/lib/is-symbol.func.ts index 486baef1..17431da8 100644 --- a/packages/type/src/is/lib/is-symbol.func.ts +++ b/packages/type/src/is/lib/is-symbol.func.ts @@ -1,5 +1,5 @@ // Function. -import { errorCallback } from '../../lib/error-callback.func'; +import { resultCallback } from '../../lib/result-callback.func'; import { typeOf } from '../../lib/type-of.func'; // Type. import { IsSymbol } from '../type/is-symbol.type'; @@ -8,8 +8,8 @@ import { ResultCallback } from '../../type/result-callback.type'; * Checks if any `value` is a `symbol` type. * @param value Any `value` to check. * @param callback `ResultCallback` function to handle result before returns. - * @callback `errorCallback`. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is a `symbol`. */ -export const isSymbol: IsSymbol = (value: any, callback: ResultCallback = errorCallback): value is symbol => +export const isSymbol: IsSymbol = (value: any, callback: ResultCallback = resultCallback): value is symbol => callback(typeOf(value) === 'symbol' && typeof value === 'symbol'); diff --git a/packages/type/src/is/lib/is-undefined.func.ts b/packages/type/src/is/lib/is-undefined.func.ts index 2339aa2b..81921742 100644 --- a/packages/type/src/is/lib/is-undefined.func.ts +++ b/packages/type/src/is/lib/is-undefined.func.ts @@ -1,13 +1,15 @@ // Function. +import { resultCallback } from '../../lib/result-callback.func'; import { typeOf } from '../../lib/type-of.func'; // Type. import { IsUndefined } from '../type/is-undefined.type'; +import { ResultCallback } from '../../type/result-callback.type'; /** * Checks if any `value` is an `undefined` type and equal to `undefined`. * @param value Any `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is `undefined`. */ -export const isUndefined: IsUndefined = (value: any): value is undefined => - typeOf(value) === 'undefined' && - typeof value === 'undefined' && - value === undefined; +export const isUndefined: IsUndefined = (value: any, callback: ResultCallback = resultCallback): value is undefined => + callback(typeOf(value) === 'undefined' && typeof value === 'undefined' && value === undefined); diff --git a/packages/type/src/is/type/is-primitive.type.ts b/packages/type/src/is/type/is-primitive.type.ts index ad805fc4..f0aa4033 100644 --- a/packages/type/src/is/type/is-primitive.type.ts +++ b/packages/type/src/is/type/is-primitive.type.ts @@ -1,4 +1,4 @@ -import { Primitives } from '../../type/primitives.type'; import { Primitive } from '../../type/primitive.type'; -export type IsPrimitive = (value: any, type: Primitives) => value is T; - +import { Primitives } from '../../type/primitives.type'; +import { ResultCallback } from '../../type/result-callback.type'; +export type IsPrimitive = (value: any, type: Primitives, callback?: ResultCallback) => value is T; diff --git a/packages/type/src/is/type/is-undefined.type.ts b/packages/type/src/is/type/is-undefined.type.ts index cd0babd5..e78d5a70 100644 --- a/packages/type/src/is/type/is-undefined.type.ts +++ b/packages/type/src/is/type/is-undefined.type.ts @@ -1 +1,2 @@ -export type IsUndefined = (value: any) => value is undefined; +import { ResultCallback } from '../../type/result-callback.type'; +export type IsUndefined = (value: any, callback?: ResultCallback) => value is undefined; diff --git a/packages/type/src/lib/error-callback.func.ts b/packages/type/src/lib/error-callback.func.ts deleted file mode 100644 index 1ae95e1a..00000000 --- a/packages/type/src/lib/error-callback.func.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { ResultCallback } from '../type/result-callback.type'; -export const errorCallback: ResultCallback = (result: boolean): boolean => result; diff --git a/packages/type/src/lib/result-callback.func.ts b/packages/type/src/lib/result-callback.func.ts new file mode 100644 index 00000000..b917ba76 --- /dev/null +++ b/packages/type/src/lib/result-callback.func.ts @@ -0,0 +1,2 @@ +import { ResultCallback } from '../type/result-callback.type'; +export const resultCallback: ResultCallback = (result: boolean): boolean => result; From e798eb170aeda5506c0e58aad2731e3e5c611b02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 15:12:45 +0200 Subject: [PATCH 159/201] style(isObjectKey): move `resultCallback` up --- packages/type/src/is/lib/is-object-key.func.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/is/lib/is-object-key.func.ts b/packages/type/src/is/lib/is-object-key.func.ts index d0967de0..208baf3e 100644 --- a/packages/type/src/is/lib/is-object-key.func.ts +++ b/packages/type/src/is/lib/is-object-key.func.ts @@ -2,11 +2,11 @@ import { isArray } from './is-array.func'; import { isKey } from './is-key.func'; import { isObject } from './is-object.func'; +import { resultCallback } from '../../lib/result-callback.func'; // Type. import { IsObjectKey } from '../type/is-object-key.type'; import { Key } from '../../type/key.type'; import { ResultCallback } from '../../type/result-callback.type'; -import { resultCallback } from '../../lib/result-callback.func'; /** * Checks if any `value` is an `object` with its own specified `key` of the `Key` type. * @param value Any `value` to check if it contains a specified `key`. From a32c0f50ea734707eb7e6c94ec6c8e97730f5d08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 15:41:12 +0200 Subject: [PATCH 160/201] style(isString): reorder function imports, add comment --- packages/type/src/is/lib/is-string.func.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/type/src/is/lib/is-string.func.ts b/packages/type/src/is/lib/is-string.func.ts index 70f193d4..11454ca6 100644 --- a/packages/type/src/is/lib/is-string.func.ts +++ b/packages/type/src/is/lib/is-string.func.ts @@ -1,6 +1,7 @@ -import { resultCallback } from '../../lib/result-callback.func'; +// Function. import { isStringObject } from './is-string-object.func'; import { isStringType } from './is-string-type.func'; +import { resultCallback } from '../../lib/result-callback.func'; import { typeOf } from '../../lib/type-of.func'; // Type. import { IsString } from '../type/is-string.type'; From 6c845160f016b32afe5c62762f2c1596e0b1ebcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 15:43:00 +0200 Subject: [PATCH 161/201] feat(isPrimitive): add `callback` feature --- packages/type/src/is/lib/is-primitive.func.ts | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/type/src/is/lib/is-primitive.func.ts b/packages/type/src/is/lib/is-primitive.func.ts index 4bba61bf..13a81f2c 100644 --- a/packages/type/src/is/lib/is-primitive.func.ts +++ b/packages/type/src/is/lib/is-primitive.func.ts @@ -6,26 +6,34 @@ import { isNumber } from './is-number.func'; import { isString } from './is-string.func'; import { isSymbol } from './is-symbol.func'; import { isUndefined } from './is-undefined.func'; +import { resultCallback } from '../../lib/result-callback.func'; // Type. import { IsPrimitive } from '../type/is-primitive.type'; import { Primitive } from '../../type/primitive.type'; import { Primitives } from '../../type/primitives.type'; +import { ResultCallback } from '../../type/result-callback.type'; /** * Checks if any `value` is the `Primitive` type from a `type` of the `Primitives` type. * @param value Any `value` to check if it's a `Primitive` from the `type`. - * @param type A `string` name of the `type` from the `Primitives` to check the `value`. + * @param type A `string` type from the `Primitives` to check the `value`. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is a `type` from the `Primitives`. */ -export const isPrimitive: IsPrimitive = (value: any, type: Primitives): value is T => { +export const isPrimitive: IsPrimitive = ( + value: any, + type: Primitives, + callback: ResultCallback = resultCallback +): value is T => { if (isString(type)) { switch (type) { - case 'bigint': return isBigInt(value); - case 'boolean': return isBoolean(value); - case 'number': return isNumber(value); - case 'null': return isNull(value); - case 'string': return isString(value); - case 'symbol': return isSymbol(value); - case 'undefined': return isUndefined(value); + case 'bigint': return isBigInt(value, callback); + case 'boolean': return isBoolean(value, callback); + case 'number': return isNumber(value, callback); + case 'null': return isNull(value, callback); + case 'string': return isString(value, callback); + case 'symbol': return isSymbol(value, callback); + case 'undefined': return isUndefined(value, callback); } } return false; From 2635f8349dc7a544af94aad01dd144da0461410e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 15:50:41 +0200 Subject: [PATCH 162/201] test: add `isPrimitive` spec and comment unnecessary `callback` check --- packages/type/src/is/test/is-object.spec.ts | 4 +- .../type/src/is/test/is-primitive.spec.ts | 89 +++++++++++++++++++ packages/type/src/is/test/is-type.spec.ts | 4 +- 3 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 packages/type/src/is/test/is-primitive.spec.ts diff --git a/packages/type/src/is/test/is-object.spec.ts b/packages/type/src/is/test/is-object.spec.ts index a2a80b02..99ddb5f9 100644 --- a/packages/type/src/is/test/is-object.spec.ts +++ b/packages/type/src/is/test/is-object.spec.ts @@ -22,12 +22,12 @@ describe(`isObject`, () => { // Checks ... describe(`checks`, () => { - it('callback', () => { + // it('callback', () => { // isObject(OBJECT_ONE, (result: boolean) => { // expect(result).toBe(TRUE); // return result; // }); - }); + // }); // ... arrays. describe(`array`, () => { diff --git a/packages/type/src/is/test/is-primitive.spec.ts b/packages/type/src/is/test/is-primitive.spec.ts new file mode 100644 index 00000000..ee001540 --- /dev/null +++ b/packages/type/src/is/test/is-primitive.spec.ts @@ -0,0 +1,89 @@ +// Function. +import { isPrimitive } from '../lib/is-primitive.func'; +// Variables. +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from './variables/big-int.const'; +import { Class, CLASS } from './variables/class.const'; +import { FALSE, TRUE, TRUE_INSTANCE, FALSE_INSTANCE, FALSE_EXPECTATION, TRUE_EXPECTATION } from './variables/boolean.const'; +import { FUNCTION } from './variables/function.const'; +import { NULL } from './variables/null.const'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; +import { OBJECT_ONE, OBJECT_TWO, OBJECT_ONE_NEW, OBJECT_TWO_NEW, ObjectTwo, ObjectOne } from './variables/object.const'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; +import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; +import { UNDEFINED } from './variables/undefined.const'; + +describe(`isPrimitive`, () => { + // Defined. + it('is DEFINED', () => expect(isPrimitive).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + // it('callback', () => { + // isPrimitive('test', (result: boolean) => { + // expect(result).toBe(TRUE); + // return result; + // }); + // }); + + // ... instance. + // describe(`instance`, () => it(`Class`, () => expect(isPrimitive(CLASS, Class)).toBe(TRUE))); + + // ... function. + // describe(`function`, () => { + // it(`${FUNCTION}`, () => expect(isPrimitive(FUNCTION, 'function')).toBe(TRUE)); + // it(`${CLASS}`, () => expect(isPrimitive(Class, 'function')).toBe(TRUE)); + // }); + + // ... objects. + // describe('object', () => { + // it(`CLASS`, () => expect(isPrimitive(CLASS, 'object')).toBe(TRUE)); + // it(`OBJECT_ONE`, () => expect(isPrimitive(OBJECT_ONE, 'object')).toBe(TRUE)); + // it(`OBJECT_ONE_NEW`, () => expect(isPrimitive(OBJECT_TWO, 'object')).toBe(TRUE)); + // it(`new Object(OBJECT_ONE_NEW)`, () => expect(isPrimitive(OBJECT_ONE_NEW, 'object')).toBe(TRUE)); + // it(`new Object(OBJECT_TWO_NEW)`, () => expect(isPrimitive(OBJECT_TWO_NEW, 'object')).toBe(TRUE)); + // }); + + // ... primitives. + describe(`primitive`, () => { + // bigint + describe(`bigint`, () => { + it(`${BIGINT}`, () => expect(isPrimitive(BIGINT, 'bigint')).toBe(TRUE)); + it(`${BIGINT_EXPECTATION}`, () => expect(isPrimitive(BIGINT_INSTANCE, 'bigint')).toBe(TRUE)); + }); + + // boolean + describe(`boolean`, () => { + it(`${TRUE}`, () => expect(isPrimitive(TRUE, 'boolean')).toBe(TRUE)); + it(`${FALSE}`, () => expect(isPrimitive(FALSE, 'boolean')).toBe(TRUE)); + it(`${FALSE_EXPECTATION}`, () => expect(isPrimitive(TRUE_INSTANCE, 'boolean')).toBe(TRUE)); + it(`${TRUE_EXPECTATION}`, () => expect(isPrimitive(FALSE_INSTANCE, 'boolean')).toBe(TRUE)); + }); + + // null + it(`${NULL}`, () => expect(isPrimitive(NULL, 'null')).toBe(TRUE)); + + // number + describe(`number`, () => { + it(`${NUMBER}`, () => expect(isPrimitive(NUMBER, 'number')).toBe(TRUE)); + it(`Number(${NUMBER})`, () => expect(isPrimitive(NUMBER_INSTANCE, 'number')).toBe(TRUE)); + it(`new Number(${NUMBER})`, () => expect(isPrimitive(NUMBER_NEW_INSTANCE, 'number')).toBe(TRUE)); + }); + + // string + describe(`string`, () => { + it(`${STRING}`, () => expect(isPrimitive(STRING, 'string')).toBe(TRUE)); + it(`String(${STRING})`, () => expect(isPrimitive(STRING_INSTANCE, 'string')).toBe(TRUE)); + it(`new String(${STRING})`, () => expect(isPrimitive(STRING_NEW_INSTANCE, 'string')).toBe(TRUE)); + }); + + // symbol + describe(`symbol`, () => { + it(`Symbol(${NUMBER})`, () => expect(isPrimitive(SYMBOL_NUMBER, 'symbol')).toBe(TRUE)); + it(`Symbol(${STRING})`, () => expect(isPrimitive(SYMBOL_STRING, 'symbol')).toBe(TRUE)); + }); + + // undefined + it(`${UNDEFINED}`, () => expect(isPrimitive(UNDEFINED, 'undefined')).toBe(TRUE)); + }); + }); +}); diff --git a/packages/type/src/is/test/is-type.spec.ts b/packages/type/src/is/test/is-type.spec.ts index 4cad2294..c515a012 100644 --- a/packages/type/src/is/test/is-type.spec.ts +++ b/packages/type/src/is/test/is-type.spec.ts @@ -18,12 +18,12 @@ describe(`isType`, () => { // Checks ... describe(`checks`, () => { - it('callback', () => { + // it('callback', () => { // isType('test', (result: boolean) => { // expect(result).toBe(TRUE); // return result; // }); - }); + // }); // ... instance. describe(`instance`, () => it(`Class`, () => expect(isType(CLASS, Class)).toBe(TRUE))); From 19bcb5865150e5ac87ec0649dcfab67e3b8e179b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 15:58:14 +0200 Subject: [PATCH 163/201] test(isUndefined): add --- .../type/src/is/test/is-undefined.spec.ts | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 packages/type/src/is/test/is-undefined.spec.ts diff --git a/packages/type/src/is/test/is-undefined.spec.ts b/packages/type/src/is/test/is-undefined.spec.ts new file mode 100644 index 00000000..5c74285a --- /dev/null +++ b/packages/type/src/is/test/is-undefined.spec.ts @@ -0,0 +1,92 @@ +// Function. +import { isUndefined } from '../lib/is-undefined.func'; +// Variables. +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from './variables/big-int.const'; +import { Class, CLASS } from './variables/class.const'; +import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE, FALSE_EXPECTATION, TRUE_EXPECTATION } from './variables/boolean.const'; +import { FUNCTION } from './variables/function.const'; +import { NULL } from './variables/null.const'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; +import { OBJECT_ONE, OBJECT_TWO, ObjectOne, ObjectTwo, OBJECT_ONE_NEW, OBJECT_TWO_NEW } from './variables/object.const'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; +import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; +import { UNDEFINED } from './variables/undefined.const'; + +/** + * Checks + * ✓ typeOf() = 'undefined + * ✓ typeof === 'undefined' + * ✓ value === undefined + */ +describe(`isUndefined`, () => { + // Defined. + it('is DEFINED', () => expect(isUndefined).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + it('callback', () => { + isUndefined(STRING, (result: boolean) => { + expect(result).toBe(FALSE); + return result; + }); + }); + + // ... arrays. + describe(`array`, () => { + // it(`${FUNCTION}`, () => expect(isUndefined(FUNCTION, 'function')).toBe(FALSE)); + // it(`${Class}`, () => expect(isUndefined(Class, 'function')).toBe(FALSE)); + }); + // ... function. + describe(`function`, () => { + it(`FUNCTION`, () => expect(isUndefined(FUNCTION)).toBe(FALSE)); + it(`Class`, () => expect(isUndefined(Class)).toBe(FALSE)); + }); + // ... objects. + describe('object', () => { + it(`CLASS`, () => expect(isUndefined(CLASS)).toBe(FALSE)); + it(`OBJECT_ONE`, () => expect(isUndefined(OBJECT_ONE)).toBe(FALSE)); + it(`OBJECT_TWO`, () => expect(isUndefined(OBJECT_TWO)).toBe(FALSE)); + it(`new Object(OBJECT_ONE_NEW})`, () => expect(isUndefined(OBJECT_ONE_NEW)).toBe(FALSE)); + it(`new Object(OBJECT_TWO_NEW})`, () => expect(isUndefined(OBJECT_TWO_NEW)).toBe(FALSE)); + }); + // ... primitives. + describe(`primitive`, () => { + // bigint + describe(`bigint`, () => { + it(`${BIGINT}`, () => expect(isUndefined(BIGINT)).toBe(FALSE)); + it(`${BIGINT_EXPECTATION}`, () => expect(isUndefined(BIGINT_INSTANCE)).toBe(FALSE)); + }); + + // boolean + describe(`boolean`, () => { + it(`${TRUE}`, () => expect(isUndefined(TRUE)).toBe(FALSE)); + it(`${FALSE}`, () => expect(isUndefined(FALSE)).toBe(FALSE)); + it(`${FALSE_EXPECTATION}`, () => expect(isUndefined(TRUE_INSTANCE)).toBe(FALSE)); + it(`${TRUE_EXPECTATION}`, () => expect(isUndefined(FALSE_INSTANCE)).toBe(FALSE)); + }); + + // null + it(`${NULL}`, () => expect(isUndefined(NULL)).toBe(FALSE)); + + // number + describe(`number`, () => { + it(`${NUMBER}`, () => expect(isUndefined(NUMBER)).toBe(FALSE)); + it(`Number(${NUMBER})`, () => expect(isUndefined(NUMBER_INSTANCE)).toBe(FALSE)); + it(`new Number(${NUMBER})`, () => expect(isUndefined(NUMBER_NEW_INSTANCE)).toBe(FALSE)); + }); + // string + describe(`string`, () => { + it(`${STRING}`, () => expect(isUndefined(STRING)).toBe(FALSE)); + it(`String(${STRING})`, () => expect(isUndefined(STRING_INSTANCE)).toBe(FALSE)); + it(`new String(${STRING})`, () => expect(isUndefined(STRING_NEW_INSTANCE)).toBe(FALSE)); + }); + // symbol + describe(`symbol`, () => { + it(`Symbol(${NUMBER})`, () => expect(isUndefined(SYMBOL_NUMBER)).toBe(FALSE)); + it(`Symbol(${STRING})`, () => expect(isUndefined(SYMBOL_STRING)).toBe(FALSE)); + }); + // undefined + it(`${UNDEFINED}`, () => expect(isUndefined(UNDEFINED)).toBe(TRUE)); + }); + }); +}); From cb9007518a77513551e72581ff116da28a1937a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 16:10:55 +0200 Subject: [PATCH 164/201] docs(README.md): update --- README.md | 383 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 237 insertions(+), 146 deletions(-) diff --git a/README.md b/README.md index 9dc7db1f..a8f0d4ad 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Common types, type guards and type checkers. [![GitHub license](https://img.shields.io/github/license/angular-package/type)](https://github.com/angular-package/type/blob/main/LICENSE) ```typescript -// Guard functions. +// Guard prefix functions. import { guardArray, guardFunction, @@ -35,29 +35,37 @@ import { ``` ```typescript -// Check is functions. +// Check is prefix functions. import { isArray, isBigInt, isBoolean, + isBooleanObject, + isBooleanType, isDefined, isFunction, isInstance, + isKey, isNull, isNumber, + isNumberObject, + isNumberType, isObject, + isObjectKey, isPrimitive, isString, + isStringObject, + isStringType, isSymbol, isType, isUndefined } from '@angular-package/type'; -// Check are functions. +// Check are prefix functions. import { areString } from '@angular-package/type'; ``` ```typescript -// Check is NOT functions. +// Check isNot prefix functions. import { isNotBoolean, isNotDefined, @@ -70,8 +78,8 @@ import { ``` ```typescript -// Guard and is object. -import { are, guard, is } from '@angular-package/type'; +// Object. +import { are, guard, is, isNot } from '@angular-package/type'; ``` ```typescript @@ -129,13 +137,11 @@ Guard ---- * [Installation](#installation) -* [Object](#object) - * [`are`](#are) - * [`guard`](#guard) - * [`is`](#is) +* [resultCallback](#resultCallback) * [Check](#check) - * [are](#areString) - * [is](#isArray) + * [are](#are) + * [is](#is) + * [isNot](#isNot) * [Guard](#guard) * [Common types](#common-types) * [Git](#git) @@ -153,7 +159,29 @@ Install `@angular-package/type` package with command: npm i --save @angular-package/type ``` -## Object +## resultCallback + +Default function to handle `callback` parameter. + +```typescript +const resultCallback: ResultCallback = (result: boolean): boolean => result; +``` + +Custom function to handle `callback` parameter. + +```typescript +const customCallback: ResultCallback = (result: boolean): boolean => { + if (result === false) { + throw new Error('error'); + } + return result; +}; + +const stringResult = isString('Lorem ipsum', customCallback); + +``` + +## Check ### are @@ -165,27 +193,24 @@ const are: Are = { }; ``` -### guard +### areString -Object `guard` with all **guard** functions. + Use `areString()` or `are.string()` to check if all of **any** arguments are a `string` type. ```typescript -const guardIs: GuardIs = { - array: guardArray, - function: guardFunction, - number: guardNumber, - objectKey: guardObjectKey, - object: guardObject, - primitive: guardPrimitive, - string: guardString, - type: guardType -}; -const guard: Guard = { - is: guardIs -}; - +const areString = (...args: any): boolean => check('string', ...args); ``` +| Parameter | Type | Description | +|-----------| :---: |-------------| +| ...args | `any` | Any arguments to check they're all a `string` type | + +The **return value** is a `boolean` value. + +[Example usage on playground][are-string] + +---- + ### is Object `is` with all **check is** functions and **check is not** in `not` property. @@ -219,64 +244,6 @@ const is: Is = { }; ``` -## isNot - -Object `isNot` with all **check is not** functions. - -```typescript -const isNot: IsNot = { - boolean: isNotBoolean, - defined: isNotDefined, - function: isNotFunction, - null: isNotNull, - number: isNotNumber, - string: isNotString, - undefined: isNotUndefined -}; -``` - -## errorCallback - -Default function to handle `callback` parameter. - -```typescript -const errorCallback: ResultCallback = (result: boolean): boolean => result; -``` - -Custom function to handle `callback` parameter. - -```typescript -const customCallback: ResultCallback = (result: boolean): boolean => { - if (result === false) { - throw new Error('error'); - } - return result; -}; - -const stringResult = isString('Lorem ipsum', customCallback); - -``` - -## Check - -### areString - - Use `areString()` or `are.string()` to check if all of **any** arguments are a `string` type. - -```typescript -const areString = (...args: any): boolean => check('string', ...args); -``` - -| Parameter | Type | Description | -|-----------| :---: |-------------| -| ...args | `any` | Any arguments to check they're all a `string` type | - -The **return value** is a `boolean` value. - -[Example usage on playground][are-string] - ----- - ### isArray Use `isArray()` or `is.array()` to check if **any** `value` is an [`Array`][Array], [`Array`][Array] instance, and `object` type. @@ -313,14 +280,14 @@ isArray(ARRAY_STRING); // true Use `isBigInt()` or `is.bigint()` to check if **any** `value` is a `bigint` type. ```typescript -const isBigInt: IsBigInt = (value: any): value is bigint => - typeOf(value) === 'bigint' && - typeof value === 'bigint'; +const isBigInt: IsBigInt = (value: any, callback: ResultCallback = resultCallback): value is bigint => + callback(typeOf(value) === 'bigint' && typeof value === 'bigint'); ``` | Parameter | Type | Description | | :-------- | :---: | :---------- | | value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `bigint`. @@ -342,14 +309,14 @@ isBigInt(BIGINT); // true Use `isBoolean()` or `is.boolean()` to check if **any** `value` is a `boolean` type not instance of [`Boolean`][Boolean] and [`Object`][Object] or `object` type instance of [`Boolean`][Boolean] and [`Object`][Object]. ```typescript -const isBoolean: IsBoolean = (value: any, callback: ResultCallback = errorCallback): value is boolean => +const isBoolean: IsBoolean = (value: any, callback: ResultCallback = resultCallback): value is boolean => callback(typeOf(value) === 'boolean' && (isBooleanType(value) || isBooleanObject(value))); ``` | Parameter | Type | Description | | :---------| :---: | :---------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `boolean`. @@ -371,14 +338,14 @@ isBoolean(BOOLEAN_INSTANCE); // true Use `isBooleanObject()` or `is.booleanObject()` to check if **any** `value` is an `object` type and instance of [`Boolean`][Boolean] and [`Object`][Object]. ```typescript -const isBooleanObject: IsBooleanObject = (value: any, callback: ResultCallback = errorCallback): value is boolean => +const isBooleanObject: IsBooleanObject = (value: any, callback: ResultCallback = resultCallback): value is boolean => callback(typeof value === 'object' && value instanceof Boolean === true && value instanceof Object === true); ``` | Parameter | Type | Description | | :---------| :---: | :---------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a [`Boolean`][Boolean] instance. @@ -398,7 +365,7 @@ isBooleanObject(BOOLEAN_INSTANCE); // true Use `isBooleanType()` or `is.booleanType()` to check if **any** `value` is a `boolean` type not an instance of [`Boolean`][Boolean] and [`Object`][Object], and equal to `true` or `false`. ```typescript -const isBooleanType: IsBooleanType = (value: any, callback: ResultCallback = errorCallback): value is boolean => +const isBooleanType: IsBooleanType = (value: any, callback: ResultCallback = resultCallback): value is boolean => callback( value instanceof Boolean === false && value instanceof Object === false && @@ -410,7 +377,7 @@ const isBooleanType: IsBooleanType = (value: any, callback: ResultCallback = err | Parameter | Type | Description | | :---------| :---: | :---------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `boolean` type. @@ -430,14 +397,14 @@ isBooleanType(BOOLEAN_INSTANCE); // false Use `isDefined()` or `is.defined()` to check if an **unknown** `value` is NOT an `undefined` type and is NOT equal to `undefined`. ```typescript -const isDefined: IsDefined = (value: unknown, callback: ResultCallback = errorCallback): boolean => +const isDefined: IsDefined = (value: unknown, callback: ResultCallback = resultCallback): boolean => callback(typeOf(value) !== 'undefined' && typeof value !== 'undefined' && value !== undefined); ``` | Parameter | Type | Description | | :-------- | :-------: | :---------- | | value | `unknown` | An `unknown` `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is defined, not `undefined`. @@ -457,7 +424,7 @@ isDefined(defined); // false Use `isFunction()` or `is.function()` to check if **any** `value` is a `function` type, an instance of [`Function`][Function] and [`Object`][Object]. ```typescript -const isFunction: IsFunction = (value: any, callback: ResultCallback = errorCallback): value is Func => +const isFunction: IsFunction = (value: any, callback: ResultCallback = resultCallback): value is Func => callback( typeOf(value) === 'function' && typeof value === 'function' && @@ -469,7 +436,7 @@ const isFunction: IsFunction = (value: any, callback: ResultCallback = errorCall | Parameter | Type | Description | | :-------- | :---: | :---------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `function`. @@ -495,7 +462,7 @@ Use `isInstance()` or `is.instance()` to check if **any** value is an `object` o const isInstance: IsInstance = ( value: any, instance: Constructor, - callback: ResultCallback = errorCallback + callback: ResultCallback = resultCallback ): value is Obj => callback( isObject(value) ? @@ -510,7 +477,7 @@ const isInstance: IsInstance = ( | :-------- | :--------------------------------: | :---------- | | value | `any` | Any `value` to compare with the `instance` | | instance | [`Constructor`](#Constructor) | A generic `Obj` [`Constructor`](#Constructor) type to create an `instance` to compare with the `value` | -| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is an `instance` of a generic `Obj`. @@ -536,14 +503,14 @@ isInstance(TWO, Two); // true and type error Use `isKey()` or `is.key()` to check if **any** `value` is one of the `string`, `number`, or `symbol`. ```typescript -const isKey: IsKey = (value: any, callback: ResultCallback = errorCallback): value is Key => +const isKey: IsKey = (value: any, callback: ResultCallback = resultCallback): value is Key => callback(isString(value) || isNumber(value) || isSymbol(value)); ``` | Parameter | Type | Description | | :-------- | :---: |:----------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a [`Key`](#Key). @@ -572,14 +539,14 @@ isKey(SYMBOL_STRING); // true Use `isNull()` or `is.null()` to check if **any** `value` is an `object` type and equal to `null`. ```typescript -const isNull: IsNull = (value: any, callback: ResultCallback = errorCallback): value is null => +const isNull: IsNull = (value: any, callback: ResultCallback = resultCallback): value is null => callback(typeOf(value) === 'null' && typeof value === 'object' && value === null); ``` | Parameter | Type | Description | | :-------- | :---: |------------ | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is `null`. @@ -607,14 +574,14 @@ isNull(NUMBER); // false Use `isNumber()` or `is.number()` to check if **any** `value` is a `number` type not an instance of [`Number`][Number] and [`Object`][Object] or `object` type instance of [`Number`][Number] and [`Object`][Object]. ```typescript -const isNumber: IsNumber = (value: any, callback: ResultCallback = errorCallback): value is number => +const isNumber: IsNumber = (value: any, callback: ResultCallback = resultCallback): value is number => callback(typeOf(value) === 'number' && isFinite(value) === true && (isNumberType(value) || isNumberObject(value))); ``` | Parameter | Type | Description | | :-------- | :---: | :---------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `number`. @@ -627,14 +594,14 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` Use `isNumberObject()` or `is.numberObject()` to check if **any** `value` is an `object` type and instance of [`Number`][Number] and [`Object`][Object]. ```typescript -const isNumberObject: IsNumberObject = (value: any, callback: ResultCallback = errorCallback): value is number => +const isNumberObject: IsNumberObject = (value: any, callback: ResultCallback = resultCallback): value is number => callback(typeof value === 'object' && value instanceof Number === true && value instanceof Object === true); ``` | Parameter | Type | Description | | :-------- | :---: | :---------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a [`Number`][Number] instance. @@ -676,14 +643,14 @@ isNumberObject(NUMBER_NEW_INSTANCE); // true Use `isNumberType()` or `is.numberType()` to check if **any** `value` is a `number` type not an instance of [`Number`][Number] and [`Object`][Object] or `object` type instance of [`Number`][Number] and [`Object`][Object]. ```typescript -const isNumberType: IsNumberType = (value: any, callback: ResultCallback = errorCallback): value is number => +const isNumberType: IsNumberType = (value: any, callback: ResultCallback = resultCallback): value is number => callback(value instanceof Number === false && value instanceof Object === false && typeof value === 'number'); ``` | Parameter | Type | Description | | :-------- | :---: | :---------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `number`. @@ -722,7 +689,7 @@ isNumberType(NUMBER_NEW_INSTANCE); // false ### isObject -Use `isObject()` or `is.object()` to check if **any** `value` is a generic `Obj` `object` type and [`Object`][Object] instance with the possibility of containing the `key`. +Use `isObject()` or `is.object()` to check if **any** `value` is an `object` of a generic `Obj` type and [`Object`][Object] instance with the possibility of containing the `key`. ```typescript const isObject: IsObject = (value: any, key?: Key): value is Obj => @@ -736,12 +703,88 @@ const isObject: IsObject = (value: any, key?: Key): value is Obj = | Parameter | Type | Description | | :-------- | :-----------: | :---------- | | value | `any` | Any `value` to check | -| key? | [`Key`](#Key) | Property name to find in `value` | +| key? | [`Key`](#Key) | Property name to find in the `value` | The **return value** is a `boolean` indicating whether or not the `value` is an `object`. [Example usage on playground][is-object] | [How to detect an `object` type][detect-object] +```typescript +// Example usage +const SYMBOL_NUMBER: unique symbol = Symbol(NUMBER); +const SYMBOL_STRING: unique symbol = Symbol(STRING); + +/** + * typeof === 'number' + * instanceof Function === false + * instanceof Number === false + * instanceof Object === false + */ +const NUMBER: any = 10304050; + +/** + * typeof === 'number' + * instanceof Function === false + * instanceof Number === false + * instanceof Object === false + */ +const NUMBER_INSTANCE: any = Number(NUMBER); + +/** + * typeof === 'number' + * instanceof Function === false + * instanceof Number === true + * instanceof Object === true + */ +const NUMBER_NEW_INSTANCE: any = new Number(NUMBER); + +/** + * typeof === 'string' + * instanceof Function === false + * instanceof Object === false + * instanceof String === false + */ +const STRING: any = '!@#$%^&*()abcdefghijklmnoprstuwyz'; + +/** + * typeof === 'string' + * instanceof Function === false + * instanceof Object === false + * instanceof String === false + */ +const STRING_INSTANCE: any = String(STRING); + +/** + * typeof === 'string' + * instanceof Function === false + * instanceof Object === true + * instanceof String === true + */ +const STRING_NEW_INSTANCE: any = new String(STRING); + +const OBJECT_ONE: ObjectOne = { + 'key as string': true, + 1030405027: 'key is number', + 5: 'key is also number', + [NUMBER]: 'key is number', + [STRING]: 'key is string', + [SYMBOL_NUMBER]: 'key is symbol number', + [SYMBOL_STRING]: 6, + x: 3000 +}; + +isObject(OBJECT_ONE); // true +isObject(OBJECT_ONE, 'key as string'); // true +isObject(OBJECT_ONE, STRING); // true +isObject(OBJECT_ONE, STRING_NEW_INSTANCE); // true +isObject(OBJECT_ONE, 1030405027); // true +isObject(OBJECT_ONE, NUMBER); // true +isObject(OBJECT_ONE, NUMBER_NEW_INSTANCE); // true +isObject(OBJECT_ONE, SYMBOL_NUMBER); // true +isObject(OBJECT_ONE, SYMBOL_STRING); // true + +``` + ---- ### isObjectKey @@ -749,22 +792,29 @@ The **return value** is a `boolean` indicating whether or not the `value` is an Use `isObject()` or `is.object()` to check if **any** `value` is an `object` with its own specified keys of the [`Key`](#Key). ```typescript -const isObjectKey: IsObjectKey = (value: any, key: Key | Key[]): value is Type => - isObject(value) ? - isArray(key) ? - key.every(k => isKey(k) ? ({}).hasOwnProperty.call(value, k) === true : false) - : isKey(key) ? - ({}).hasOwnProperty.call(value, key) - : false - : false; +const isObjectKey: IsObjectKey = ( + value: any, + key: Key | Key[], + callback: ResultCallback = resultCallback +): value is Type => + callback( + isObject(value) ? + isArray(key) ? + key.every(k => isKey(k) ? ({}).hasOwnProperty.call(value, k) === true : false) + : isKey(key) ? + ({}).hasOwnProperty.call(value, key) + : false + : false + ); ``` | Parameter | Type | Description | | :-------- | :------------------------------: | :---------- | | value | `any` | Any `value` to check if it contains a specified `key` | -| key | [`Key`](#key) \| [`Key`](#Key)[] | A [`Key`](#Key) type or an array of [`Key`](#Key) type to check the `value` | +| key | [`Key`](#key) \| [`Key`](#Key)[] | A [`Key`](#Key) type or an array of [`Key`](#Key) type to check in the `value` | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | -The **return value** is a `boolean` indicating whether or not the `value` has its own specified keys. +The **return value** is a `boolean` indicating whether or not the `value` is an `object` with its own specified keys. ---- @@ -773,16 +823,20 @@ The **return value** is a `boolean` indicating whether or not the `value` has it Use `isPrimitive()` or `is.primitive()` to check if **any** `value` is the [`Primitive`](#Primitive) type from a `type` of the [`Primitives`](#Primitives) type. ```typescript -const isPrimitive: IsPrimitive = (value: any, type: Primitives): value is T => { +const isPrimitive: IsPrimitive = ( + value: any, + type: Primitives, + callback: ResultCallback = resultCallback +): value is T => { if (isString(type)) { switch (type) { - case 'bigint': return isBigInt(value); - case 'boolean': return isBoolean(value); - case 'number': return isNumber(value); - case 'null': return isNull(value); - case 'string': return isString(value); - case 'symbol': return isSymbol(value); - case 'undefined': return isUndefined(value); + case 'bigint': return isBigInt(value, callback); + case 'boolean': return isBoolean(value, callback); + case 'number': return isNumber(value, callback); + case 'null': return isNull(value, callback); + case 'string': return isString(value, callback); + case 'symbol': return isSymbol(value, callback); + case 'undefined': return isUndefined(value, callback); } } return false; @@ -792,7 +846,8 @@ const isPrimitive: IsPrimitive = (value: any, type: Primiti | Parameter | Type | Description | | :-------- | :-------------------------: | :---------- | | value | `any` | Any `value` to check if it's a `Primitive` from the `type` | -| type | [`Primitives`](#Primitives) | A `string` name of the type from the [`Primitives`](#Primitives) to check the `value` | +| type | [`Primitives`](#Primitives) | A `string` type from the [`Primitives`](#Primitives) to check the `value` | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `type` from the [`Primitives`](#Primitives). @@ -802,10 +857,10 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` ### isString -Use `isString()` or `is.string()` to check if **any** `value` is a `string` type, not instance of `Object` and `String` or `object` type and instance of `String` and `Object`. +Use `isString()` or `is.string()` to check if **any** `value` is a `string` type, not instance of [`Object`][Object] and [`String`][String] or `object` type and instance of [`String`][String] and [`Object`][Object]. ```typescript -const isString: IsString = (value: any, callback: ResultCallback = errorCallback): value is string => +const isString: IsString = (value: any, callback: ResultCallback = resultCallback): value is string => callback(typeOf(value) === 'string' && (isStringObject(value) || isStringType(value))); ``` @@ -823,14 +878,14 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` Use `isStringObject()` or `is.stringObject()` to check if **any** `value` is an `object` type and instance of [`String`][String] and [`Object`][Object]. ```typescript -const isStringObject: IsStringObject = (value: any, callback: ResultCallback = errorCallback): value is string => +const isStringObject: IsStringObject = (value: any, callback: ResultCallback = resultCallback): value is string => callback(value instanceof Object === true && value instanceof String === true && typeof value === 'object'); ``` | Parameter | Type | Description | | :-------- | :---------------------------------: | :---------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a [`String`][String] instance. @@ -841,14 +896,14 @@ The **return value** is a `boolean` indicating whether or not the `value` is a [ Use `isStringObject()` or `is.stringObject()` to check if **any** `value` is a `string` type and **not** instance of [`String`][String] and [`Object`][Object]. ```typescript -const isStringType: IsStringType = (value: any, callback: ResultCallback = errorCallback): value is string => +const isStringType: IsStringType = (value: any, callback: ResultCallback = resultCallback): value is string => callback(value instanceof Object === false && value instanceof String === false && typeof value === 'string'); ``` | Parameter | Type | Description | | :-------- | :---------------------------------: | :---------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`errorCallback`](#errorCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `string`. @@ -859,14 +914,14 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` Use `isSymbol()` or `is.symbol()` to check if **any** `value` is a `symbol` type. ```typescript -const isSymbol: IsSymbol = (value: any): value is symbol => - typeOf(value) === 'symbol' && - typeof value === 'symbol'; +const isSymbol: IsSymbol = (value: any, callback: ResultCallback = resultCallback): value is symbol => + callback(typeOf(value) === 'symbol' && typeof value === 'symbol'); ``` | Parameter | Type | Description | | :-------- | :---: | :---------- | | value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `symbol`. @@ -918,15 +973,14 @@ The **return value** is a `boolean` indicating whether or not the `value` is the Use `isUndefined()` or `is.undefined()` to check if **any** `value` is an `undefined` type and equal to `undefined`. ```typescript -const isUndefined: IsUndefined = (value: any): value is undefined => - typeOf(value) === 'undefined' && - typeof value === 'undefined' && - value === undefined; +const isUndefined: IsUndefined = (value: any, callback: ResultCallback = resultCallback): value is undefined => + callback(typeOf(value) === 'undefined' && typeof value === 'undefined' && value === undefined); ``` | Parameter | Type | Description | | :-------- | :---: | :---------- | | value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is `undefined`. @@ -934,6 +988,22 @@ The **return value** is a `boolean` indicating whether or not the `value` is `un ---- +### isNot + +Object `isNot` with all **check is not** functions. + +```typescript +const isNot: IsNot = { + boolean: isNotBoolean, + defined: isNotDefined, + function: isNotFunction, + null: isNotNull, + number: isNotNumber, + string: isNotString, + undefined: isNotUndefined +}; +``` + ### isNotBoolean Use `isNotBoolean()` or `is.not.boolean()` to check if an **unknown** `value` is NOT a `boolean` type, NOT equal to `true` or `false` and NOT an instance of a `Boolean`. @@ -1057,6 +1127,27 @@ const isNotUndefined: IsNotUndefined = (value: unknown): boolean => ## Guard +### guard + +Object `guard` with all **guard** functions. + +```typescript +const guardIs: GuardIs = { + array: guardArray, + function: guardFunction, + number: guardNumber, + objectKey: guardObjectKey, + object: guardObject, + primitive: guardPrimitive, + string: guardString, + type: guardType +}; +const guard: Guard = { + is: guardIs +}; + +``` + ### guardArray Use `guardArray()` or `guard.is.array()` to guard the `value` to be an [`Array`][Array] of a generic `Type`. From 561f4d903c2c31c9a1da5b952afcf7ab7d88cabf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 16:11:23 +0200 Subject: [PATCH 165/201] refactor(api): add features --- packages/type/src/public-api.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/type/src/public-api.ts b/packages/type/src/public-api.ts index cf993bb3..acb4fbc5 100644 --- a/packages/type/src/public-api.ts +++ b/packages/type/src/public-api.ts @@ -31,14 +31,22 @@ export { isArray, isBigInt, isBoolean, + isBooleanObject, + isBooleanType, isDefined, isFunction, isInstance, + isKey, isNull, isNumber, + isNumberObject, + isNumberType, isObject, + isObjectKey, isPrimitive, isString, + isStringObject, + isStringType, isSymbol, isType, isUndefined From 2744bcd945b0c1039a7558bcaf001c7805d5f451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 16:13:33 +0200 Subject: [PATCH 166/201] refactor(api): export all types --- packages/type/src/public-api.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/public-api.ts b/packages/type/src/public-api.ts index acb4fbc5..5fa72627 100644 --- a/packages/type/src/public-api.ts +++ b/packages/type/src/public-api.ts @@ -64,4 +64,4 @@ export { } from './is/not'; // Types. -export { Constructor, CycleHook, Func, Primitive, Primitives, Types } from './type'; +export { Constructor, CycleHook, Func, Key, Primitive, Primitives, ResultCallback, Type, Types } from './type'; From 307ee24aa3b50fa8b139ff10006805baad3fa64b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 16:13:40 +0200 Subject: [PATCH 167/201] docs(REAME.md): update --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a8f0d4ad..1925142b 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Common types, type guards and type checkers. [![GitHub license](https://img.shields.io/github/license/angular-package/type)](https://github.com/angular-package/type/blob/main/LICENSE) ```typescript -// Guard prefix functions. +// `guard` prefix functions. import { guardArray, guardFunction, @@ -35,7 +35,7 @@ import { ``` ```typescript -// Check is prefix functions. +// Check `is` prefix functions. import { isArray, isBigInt, @@ -60,12 +60,12 @@ import { isType, isUndefined } from '@angular-package/type'; -// Check are prefix functions. +// Check `are` prefix functions. import { areString } from '@angular-package/type'; ``` ```typescript -// Check isNot prefix functions. +// Check `isNot` prefix functions. import { isNotBoolean, isNotDefined, @@ -84,7 +84,7 @@ import { are, guard, is, isNot } from '@angular-package/type'; ```typescript // Types. -import { Constructor, CycleHook, Func, Primitive, Primitives, Types } from '@angular-package/type'; +import { Constructor, CycleHook, Func, Key, Primitive, Primitives, ResultCallback, Type, Types } from '@angular-package/type'; ``` ## Features From 0604d043770e41d7269620e5fc41b505c18f4a67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 17:23:32 +0200 Subject: [PATCH 168/201] test: add `isStringObject`, `isStringType` --- .../type/src/is/test/is-string-object.spec.ts | 90 +++++++++++++++++++ .../type/src/is/test/is-string-type.spec.ts | 90 +++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 packages/type/src/is/test/is-string-object.spec.ts create mode 100644 packages/type/src/is/test/is-string-type.spec.ts diff --git a/packages/type/src/is/test/is-string-object.spec.ts b/packages/type/src/is/test/is-string-object.spec.ts new file mode 100644 index 00000000..365f2a1d --- /dev/null +++ b/packages/type/src/is/test/is-string-object.spec.ts @@ -0,0 +1,90 @@ +// Function. +import { isStringObject } from '../lib/is-string-object.func'; +// Variables. +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from './variables/big-int.const'; +import { Class, CLASS } from './variables/class.const'; +import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE, FALSE_EXPECTATION, TRUE_EXPECTATION } from './variables/boolean.const'; +import { FUNCTION } from './variables/function.const'; +import { NULL } from './variables/null.const'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; +import { OBJECT_ONE, OBJECT_TWO, ObjectOne, ObjectTwo, OBJECT_ONE_NEW, OBJECT_TWO_NEW } from './variables/object.const'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; +import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; +import { UNDEFINED } from './variables/undefined.const'; + +/** + * Checks + * ✓ typeof === 'object' && instanceof String === true && instanceof Object === true + */ +describe(`isStringObject`, () => { + // Defined. + it('is DEFINED', () => expect(isStringObject).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + it('callback', () => { + isStringObject(STRING_NEW_INSTANCE, (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); + }); + + // ... arrays. + describe(`array`, () => { + // it(`${FUNCTION}`, () => expect(isStringObject(FUNCTION, 'function')).toBe(FALSE)); + // it(`${Class}`, () => expect(isStringObject(Class, 'function')).toBe(FALSE)); + }); + // ... function. + describe(`function`, () => { + it(`FUNCTION`, () => expect(isStringObject(FUNCTION)).toBe(FALSE)); + it(`Class`, () => expect(isStringObject(Class)).toBe(FALSE)); + }); + // ... objects. + describe('object', () => { + it(`CLASS`, () => expect(isStringObject(CLASS)).toBe(FALSE)); + it(`OBJECT_ONE`, () => expect(isStringObject(OBJECT_ONE)).toBe(FALSE)); + it(`OBJECT_TWO`, () => expect(isStringObject(OBJECT_TWO)).toBe(FALSE)); + it(`new Object(OBJECT_ONE_NEW})`, () => expect(isStringObject(OBJECT_ONE_NEW)).toBe(FALSE)); + it(`new Object(OBJECT_TWO_NEW})`, () => expect(isStringObject(OBJECT_TWO_NEW)).toBe(FALSE)); + }); + // ... primitives. + describe(`primitive`, () => { + // bigint + describe(`bigint`, () => { + it(`${BIGINT}`, () => expect(isStringObject(BIGINT)).toBe(FALSE)); + it(`${BIGINT_EXPECTATION}`, () => expect(isStringObject(BIGINT_INSTANCE)).toBe(FALSE)); + }); + + // boolean + describe(`boolean`, () => { + it(`${TRUE}`, () => expect(isStringObject(TRUE)).toBe(FALSE)); + it(`${FALSE}`, () => expect(isStringObject(FALSE)).toBe(FALSE)); + it(`${FALSE_EXPECTATION}`, () => expect(isStringObject(TRUE_INSTANCE)).toBe(FALSE)); + it(`${TRUE_EXPECTATION}`, () => expect(isStringObject(FALSE_INSTANCE)).toBe(FALSE)); + }); + + // null + it(`${NULL}`, () => expect(isStringObject(NULL)).toBe(FALSE)); + + // number + describe(`number`, () => { + it(`${NUMBER}`, () => expect(isStringObject(NUMBER)).toBe(FALSE)); + it(`Number(${NUMBER})`, () => expect(isStringObject(NUMBER_INSTANCE)).toBe(FALSE)); + it(`new Number(${NUMBER})`, () => expect(isStringObject(NUMBER_NEW_INSTANCE)).toBe(FALSE)); + }); + // string + describe(`string`, () => { + it(`${STRING}`, () => expect(isStringObject(STRING)).toBe(FALSE)); + it(`String(${STRING})`, () => expect(isStringObject(STRING_INSTANCE)).toBe(FALSE)); + it(`new String(${STRING})`, () => expect(isStringObject(STRING_NEW_INSTANCE)).toBe(TRUE)); + }); + // symbol + describe(`symbol`, () => { + it(`Symbol(${NUMBER})`, () => expect(isStringObject(SYMBOL_NUMBER)).toBe(FALSE)); + it(`Symbol(${STRING})`, () => expect(isStringObject(SYMBOL_STRING)).toBe(FALSE)); + }); + // undefined + it(`${UNDEFINED}`, () => expect(isStringObject(UNDEFINED)).toBe(FALSE)); + }); + }); +}); diff --git a/packages/type/src/is/test/is-string-type.spec.ts b/packages/type/src/is/test/is-string-type.spec.ts new file mode 100644 index 00000000..c8675482 --- /dev/null +++ b/packages/type/src/is/test/is-string-type.spec.ts @@ -0,0 +1,90 @@ +// Function. +import { isStringType } from '../lib/is-string-type.func'; +// Variables. +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from './variables/big-int.const'; +import { Class, CLASS } from './variables/class.const'; +import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE, FALSE_EXPECTATION, TRUE_EXPECTATION } from './variables/boolean.const'; +import { FUNCTION } from './variables/function.const'; +import { NULL } from './variables/null.const'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; +import { OBJECT_ONE, OBJECT_TWO, ObjectOne, ObjectTwo, OBJECT_ONE_NEW, OBJECT_TWO_NEW } from './variables/object.const'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; +import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; +import { UNDEFINED } from './variables/undefined.const'; + +/** + * Checks + * ✓ typeof === 'string' && instanceof String === false && instanceof Object === false + */ +describe(`isStringType`, () => { + // Defined. + it('is DEFINED', () => expect(isStringType).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + it('callback', () => { + isStringType(STRING, (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); + }); + + // ... arrays. + describe(`array`, () => { + // it(`${FUNCTION}`, () => expect(isStringType(FUNCTION, 'function')).toBe(FALSE)); + // it(`${Class}`, () => expect(isStringType(Class, 'function')).toBe(FALSE)); + }); + // ... function. + describe(`function`, () => { + it(`FUNCTION`, () => expect(isStringType(FUNCTION)).toBe(FALSE)); + it(`Class`, () => expect(isStringType(Class)).toBe(FALSE)); + }); + // ... objects. + describe('object', () => { + it(`CLASS`, () => expect(isStringType(CLASS)).toBe(FALSE)); + it(`OBJECT_ONE`, () => expect(isStringType(OBJECT_ONE)).toBe(FALSE)); + it(`OBJECT_TWO`, () => expect(isStringType(OBJECT_TWO)).toBe(FALSE)); + it(`new Object(OBJECT_ONE_NEW})`, () => expect(isStringType(OBJECT_ONE_NEW)).toBe(FALSE)); + it(`new Object(OBJECT_TWO_NEW})`, () => expect(isStringType(OBJECT_TWO_NEW)).toBe(FALSE)); + }); + // ... primitives. + describe(`primitive`, () => { + // bigint + describe(`bigint`, () => { + it(`${BIGINT}`, () => expect(isStringType(BIGINT)).toBe(FALSE)); + it(`${BIGINT_EXPECTATION}`, () => expect(isStringType(BIGINT_INSTANCE)).toBe(FALSE)); + }); + + // boolean + describe(`boolean`, () => { + it(`${TRUE}`, () => expect(isStringType(TRUE)).toBe(FALSE)); + it(`${FALSE}`, () => expect(isStringType(FALSE)).toBe(FALSE)); + it(`${FALSE_EXPECTATION}`, () => expect(isStringType(TRUE_INSTANCE)).toBe(FALSE)); + it(`${TRUE_EXPECTATION}`, () => expect(isStringType(FALSE_INSTANCE)).toBe(FALSE)); + }); + + // null + it(`${NULL}`, () => expect(isStringType(NULL)).toBe(FALSE)); + + // number + describe(`number`, () => { + it(`${NUMBER}`, () => expect(isStringType(NUMBER)).toBe(FALSE)); + it(`Number(${NUMBER})`, () => expect(isStringType(NUMBER_INSTANCE)).toBe(FALSE)); + it(`new Number(${NUMBER})`, () => expect(isStringType(NUMBER_NEW_INSTANCE)).toBe(FALSE)); + }); + // string + describe(`string`, () => { + it(`${STRING}`, () => expect(isStringType(STRING)).toBe(TRUE)); + it(`String(${STRING})`, () => expect(isStringType(STRING_INSTANCE)).toBe(TRUE)); + it(`new String(${STRING})`, () => expect(isStringType(STRING_NEW_INSTANCE)).toBe(FALSE)); + }); + // symbol + describe(`symbol`, () => { + it(`Symbol(${NUMBER})`, () => expect(isStringType(SYMBOL_NUMBER)).toBe(FALSE)); + it(`Symbol(${STRING})`, () => expect(isStringType(SYMBOL_STRING)).toBe(FALSE)); + }); + // undefined + it(`${UNDEFINED}`, () => expect(isStringType(UNDEFINED)).toBe(FALSE)); + }); + }); +}); From e83db1b3ffb2baf550d2a495adff6e78497f3d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 17:31:29 +0200 Subject: [PATCH 169/201] feat(isType): add `callback` feature and test for it --- packages/type/src/is/lib/is-type.func.ts | 14 +++++++++----- packages/type/src/is/test/is-type.spec.ts | 16 ++++++++++------ packages/type/src/is/type/is-type.type.ts | 3 ++- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/type/src/is/lib/is-type.func.ts b/packages/type/src/is/lib/is-type.func.ts index 67e7cf4a..13488945 100644 --- a/packages/type/src/is/lib/is-type.func.ts +++ b/packages/type/src/is/lib/is-type.func.ts @@ -1,21 +1,25 @@ // Function. import { isFunction } from './is-function.func'; import { isInstance } from './is-instance.func'; +import { isNotNull } from '../not/lib/is-not-null.func'; import { isObject } from './is-object.func'; import { isPrimitive } from './is-primitive.func'; import { isString } from './is-string.func'; +import { resultCallback } from '../../lib/result-callback.func'; // Type. import { IsType } from '../type/is-type.type'; +import { ResultCallback } from '../../type/result-callback.type'; import { Type } from '../../type/type.type'; import { Types } from '../../type/types.type'; -import { isNotNull } from '../not/lib/is-not-null.func'; /** * Checks if any `value` is the `Type` from a `type` of the `Types` type. * @param value Any `value` to check if its type is from the `type`. * @param type A `string` or generic `Constructor` type from the `Types` to check the `value`. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is the `Type` from a `type` of the `Types`. */ -export const isType: IsType = (value: any, type: Types): value is T => { +export const isType: IsType = (value: any, type: Types, callback: ResultCallback = resultCallback): value is T => { if (isString(type)) { switch (type) { // Primitives. @@ -25,14 +29,14 @@ export const isType: IsType = (value: any, type: Types): valu case 'null' : case 'string': case 'symbol': - case 'undefined': return isPrimitive(value, type); + case 'undefined': return isPrimitive(value, type, callback); // Function. - case 'function': return isFunction(value); + case 'function': return isFunction(value, callback); // Object. case 'object': return isObject(value); } } else if (isNotNull(type)) { - return isInstance(value, type); + return isInstance(value, type, callback); } return false; }; diff --git a/packages/type/src/is/test/is-type.spec.ts b/packages/type/src/is/test/is-type.spec.ts index c515a012..ccebd1c3 100644 --- a/packages/type/src/is/test/is-type.spec.ts +++ b/packages/type/src/is/test/is-type.spec.ts @@ -18,12 +18,16 @@ describe(`isType`, () => { // Checks ... describe(`checks`, () => { - // it('callback', () => { - // isType('test', (result: boolean) => { - // expect(result).toBe(TRUE); - // return result; - // }); - // }); + it('callback', () => { + isType(STRING, 'string', (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); + isType(NUMBER, 'number', (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); + }); // ... instance. describe(`instance`, () => it(`Class`, () => expect(isType(CLASS, Class)).toBe(TRUE))); diff --git a/packages/type/src/is/type/is-type.type.ts b/packages/type/src/is/type/is-type.type.ts index f4de98b1..b62b760d 100644 --- a/packages/type/src/is/type/is-type.type.ts +++ b/packages/type/src/is/type/is-type.type.ts @@ -1,3 +1,4 @@ +import { ResultCallback } from '../../type/result-callback.type'; import { Type } from '../../type/type.type'; import { Types } from '../../type/types.type'; -export type IsType = (value: any, type: Types) => value is T; +export type IsType = (value: any, type: Types, callback?: ResultCallback) => value is T; From 098cab62abc3cf5fe533f187562e17038ba6b7f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 17:36:44 +0200 Subject: [PATCH 170/201] feat(isArray): add `ResultCallback` feature --- packages/type/src/is/lib/is-array.func.ts | 16 +++++++++++----- packages/type/src/is/type/is-array.type.ts | 3 ++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/type/src/is/lib/is-array.func.ts b/packages/type/src/is/lib/is-array.func.ts index 96e572de..b777bda0 100644 --- a/packages/type/src/is/lib/is-array.func.ts +++ b/packages/type/src/is/lib/is-array.func.ts @@ -1,14 +1,20 @@ // Function. +import { resultCallback } from '../../lib/result-callback.func'; import { typeOf } from '../../lib/type-of.func'; // Type. import { IsArray } from '../type/is-array.type'; +import { ResultCallback } from '../../type/result-callback.type'; /** * Checks if any `value` is an `Array`, `Array` instance, and `object` type. * @param value Any `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is an `Array`. */ -export const isArray: IsArray = (value: any): value is Array => - typeOf(value) === 'array' && - Array.isArray(value) === true && - value instanceof Array === true && - typeof value === 'object'; +export const isArray: IsArray = (value: any, callback: ResultCallback = resultCallback): value is Array => + callback( + typeOf(value) === 'array' && + Array.isArray(value) === true && + value instanceof Array === true && + typeof value === 'object' + ); diff --git a/packages/type/src/is/type/is-array.type.ts b/packages/type/src/is/type/is-array.type.ts index fd118f1a..375e273a 100644 --- a/packages/type/src/is/type/is-array.type.ts +++ b/packages/type/src/is/type/is-array.type.ts @@ -1 +1,2 @@ -export type IsArray = (value: any) => value is Array; +import { ResultCallback } from '../../type/result-callback.type'; +export type IsArray = (value: any, callback?: ResultCallback) => value is Array; From 605470d8e348ff9667c6515e3b5fc07737793ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 19:29:11 +0200 Subject: [PATCH 171/201] test: add all `isNot` --- .../src/is/not/test/is-not-function.spec.ts | 91 +++++++++++++++++++ .../type/src/is/not/test/is-not-null.spec.ts | 90 ++++++++++++++++++ .../src/is/not/test/is-not-number.spec.ts | 91 +++++++++++++++++++ .../src/is/not/test/is-not-string.spec.ts | 91 +++++++++++++++++++ .../src/is/not/test/is-not-undefined.spec.ts | 91 +++++++++++++++++++ packages/type/src/is/not/test/is-not.spec.ts | 28 ++++++ 6 files changed, 482 insertions(+) create mode 100644 packages/type/src/is/not/test/is-not-function.spec.ts create mode 100644 packages/type/src/is/not/test/is-not-null.spec.ts create mode 100644 packages/type/src/is/not/test/is-not-number.spec.ts create mode 100644 packages/type/src/is/not/test/is-not-string.spec.ts create mode 100644 packages/type/src/is/not/test/is-not-undefined.spec.ts create mode 100644 packages/type/src/is/not/test/is-not.spec.ts diff --git a/packages/type/src/is/not/test/is-not-function.spec.ts b/packages/type/src/is/not/test/is-not-function.spec.ts new file mode 100644 index 00000000..da454d8f --- /dev/null +++ b/packages/type/src/is/not/test/is-not-function.spec.ts @@ -0,0 +1,91 @@ +// Function. +import { isNotFunction } from '../lib/is-not-function.func'; +// Variables. +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from '../../test/variables/big-int.const'; +import { Class, CLASS } from '../../test/variables/class.const'; +import { FUNCTION } from '../../test/variables/function.const'; +import { NULL } from '../../test/variables/null.const'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from '../../test/variables/number.const'; +import { OBJECT_ONE, OBJECT_TWO, OBJECT_ONE_NEW, OBJECT_TWO_NEW } from '../../test/variables/object.const'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from '../../test/variables/string.const'; +import { SYMBOL_NUMBER, SYMBOL_STRING } from '../../test/variables/symbol.const'; +import { TRUE, TRUE_EXPECTATION, FALSE, TRUE_INSTANCE, FALSE_EXPECTATION, FALSE_INSTANCE } from '../../test/variables/boolean.const'; +import { UNDEFINED } from '../../test/variables/undefined.const'; +/** + * Checks + * ✓ typeOf() = 'function + * ✓ typeof !== 'function' + * ✓ instanceof Function === false + */ +describe(`isNotFunction`, () => { + // Defined. + it('is DEFINED', () => expect(isNotFunction).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + it('callback', () => { + isNotFunction(STRING, (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); + }); + + // ... arrays. + describe(`array`, () => { + // it(`${FUNCTION}`, () => expect(isNotFunction(FUNCTION, 'function')).toBe(TRUE)); + // it(`${Class}`, () => expect(isNotFunction(Class, 'function')).toBe(TRUE)); + }); + // ... function. + describe(`function`, () => { + it(`FUNCTION`, () => expect(isNotFunction(FUNCTION)).toBe(FALSE)); + it(`Class`, () => expect(isNotFunction(Class)).toBe(FALSE)); + }); + // ... objects. + describe('object', () => { + it(`CLASS`, () => expect(isNotFunction(CLASS)).toBe(TRUE)); + it(`OBJECT_ONE`, () => expect(isNotFunction(OBJECT_ONE)).toBe(TRUE)); + it(`OBJECT_TWO`, () => expect(isNotFunction(OBJECT_TWO)).toBe(TRUE)); + it(`new Object(OBJECT_ONE_NEW})`, () => expect(isNotFunction(OBJECT_ONE_NEW)).toBe(TRUE)); + it(`new Object(OBJECT_TWO_NEW})`, () => expect(isNotFunction(OBJECT_TWO_NEW)).toBe(TRUE)); + }); + // ... primitives. + describe(`primitive`, () => { + // bigint + describe(`bigint`, () => { + it(`${BIGINT}`, () => expect(isNotFunction(BIGINT)).toBe(TRUE)); + it(`${BIGINT_EXPECTATION}`, () => expect(isNotFunction(BIGINT_INSTANCE)).toBe(TRUE)); + }); + + // boolean + describe(`boolean`, () => { + it(`${TRUE}`, () => expect(isNotFunction(TRUE)).toBe(TRUE)); + it(`${FALSE}`, () => expect(isNotFunction(FALSE)).toBe(TRUE)); + it(`${TRUE_EXPECTATION}`, () => expect(isNotFunction(TRUE_INSTANCE)).toBe(TRUE)); + it(`${FALSE_EXPECTATION}`, () => expect(isNotFunction(FALSE_INSTANCE)).toBe(TRUE)); + }); + + // null + it(`${NULL}`, () => expect(isNotFunction(NULL)).toBe(TRUE)); + + // number + describe(`number`, () => { + it(`${NUMBER}`, () => expect(isNotFunction(NUMBER)).toBe(TRUE)); + it(`Number(${NUMBER})`, () => expect(isNotFunction(NUMBER_INSTANCE)).toBe(TRUE)); + it(`new Number(${NUMBER})`, () => expect(isNotFunction(NUMBER_NEW_INSTANCE)).toBe(TRUE)); + }); + // string + describe(`string`, () => { + it(`${STRING}`, () => expect(isNotFunction(STRING)).toBe(TRUE)); + it(`String(${STRING})`, () => expect(isNotFunction(STRING_INSTANCE)).toBe(TRUE)); + it(`new String(${STRING})`, () => expect(isNotFunction(STRING_NEW_INSTANCE)).toBe(TRUE)); + }); + // symbol + describe(`symbol`, () => { + it(`Symbol(${NUMBER})`, () => expect(isNotFunction(SYMBOL_NUMBER)).toBe(TRUE)); + it(`Symbol(${STRING})`, () => expect(isNotFunction(SYMBOL_STRING)).toBe(TRUE)); + }); + // undefined + it(`${UNDEFINED}`, () => expect(isNotFunction(UNDEFINED)).toBe(TRUE)); + }); + }); +}); diff --git a/packages/type/src/is/not/test/is-not-null.spec.ts b/packages/type/src/is/not/test/is-not-null.spec.ts new file mode 100644 index 00000000..0770a75c --- /dev/null +++ b/packages/type/src/is/not/test/is-not-null.spec.ts @@ -0,0 +1,90 @@ +// Function. +import { isNotNull } from '../lib/is-not-null.func'; +// Variables. +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from '../../test/variables/big-int.const'; +import { Class, CLASS } from '../../test/variables/class.const'; +import { FUNCTION } from '../../test/variables/function.const'; +import { NULL } from '../../test/variables/null.const'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from '../../test/variables/number.const'; +import { OBJECT_ONE, OBJECT_TWO, OBJECT_ONE_NEW, OBJECT_TWO_NEW } from '../../test/variables/object.const'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from '../../test/variables/string.const'; +import { SYMBOL_NUMBER, SYMBOL_STRING } from '../../test/variables/symbol.const'; +import { TRUE, TRUE_EXPECTATION, FALSE, TRUE_INSTANCE, FALSE_EXPECTATION, FALSE_INSTANCE } from '../../test/variables/boolean.const'; +import { UNDEFINED } from '../../test/variables/undefined.const'; +/** + * Checks + * ✓ typeOf() = 'null + * ✓ value !== null + */ +describe(`isNotNull`, () => { + // Defined. + it('is DEFINED', () => expect(isNotNull).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + it('callback', () => { + isNotNull(STRING, (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); + }); + + // ... arrays. + describe(`array`, () => { + // it(`${FUNCTION}`, () => expect(isNotNull(FUNCTION, 'function')).toBe(TRUE)); + // it(`${Class}`, () => expect(isNotNull(Class, 'function')).toBe(TRUE)); + }); + // ... function. + describe(`function`, () => { + it(`FUNCTION`, () => expect(isNotNull(FUNCTION)).toBe(TRUE)); + it(`Class`, () => expect(isNotNull(Class)).toBe(TRUE)); + }); + // ... objects. + describe('object', () => { + it(`CLASS`, () => expect(isNotNull(CLASS)).toBe(TRUE)); + it(`OBJECT_ONE`, () => expect(isNotNull(OBJECT_ONE)).toBe(TRUE)); + it(`OBJECT_TWO`, () => expect(isNotNull(OBJECT_TWO)).toBe(TRUE)); + it(`new Object(OBJECT_ONE_NEW})`, () => expect(isNotNull(OBJECT_ONE_NEW)).toBe(TRUE)); + it(`new Object(OBJECT_TWO_NEW})`, () => expect(isNotNull(OBJECT_TWO_NEW)).toBe(TRUE)); + }); + // ... primitives. + describe(`primitive`, () => { + // bigint + describe(`bigint`, () => { + it(`${BIGINT}`, () => expect(isNotNull(BIGINT)).toBe(TRUE)); + it(`${BIGINT_EXPECTATION}`, () => expect(isNotNull(BIGINT_INSTANCE)).toBe(TRUE)); + }); + + // boolean + describe(`boolean`, () => { + it(`${TRUE}`, () => expect(isNotNull(TRUE)).toBe(TRUE)); + it(`${FALSE}`, () => expect(isNotNull(FALSE)).toBe(TRUE)); + it(`${TRUE_EXPECTATION}`, () => expect(isNotNull(TRUE_INSTANCE)).toBe(TRUE)); + it(`${FALSE_EXPECTATION}`, () => expect(isNotNull(FALSE_INSTANCE)).toBe(TRUE)); + }); + + // null + it(`${NULL}`, () => expect(isNotNull(NULL)).toBe(FALSE)); + + // number + describe(`number`, () => { + it(`${NUMBER}`, () => expect(isNotNull(NUMBER)).toBe(TRUE)); + it(`Number(${NUMBER})`, () => expect(isNotNull(NUMBER_INSTANCE)).toBe(TRUE)); + it(`new Number(${NUMBER})`, () => expect(isNotNull(NUMBER_NEW_INSTANCE)).toBe(TRUE)); + }); + // string + describe(`string`, () => { + it(`${STRING}`, () => expect(isNotNull(STRING)).toBe(TRUE)); + it(`String(${STRING})`, () => expect(isNotNull(STRING_INSTANCE)).toBe(TRUE)); + it(`new String(${STRING})`, () => expect(isNotNull(STRING_NEW_INSTANCE)).toBe(TRUE)); + }); + // symbol + describe(`symbol`, () => { + it(`Symbol(${NUMBER})`, () => expect(isNotNull(SYMBOL_NUMBER)).toBe(TRUE)); + it(`Symbol(${STRING})`, () => expect(isNotNull(SYMBOL_STRING)).toBe(TRUE)); + }); + // undefined + it(`${UNDEFINED}`, () => expect(isNotNull(UNDEFINED)).toBe(TRUE)); + }); + }); +}); diff --git a/packages/type/src/is/not/test/is-not-number.spec.ts b/packages/type/src/is/not/test/is-not-number.spec.ts new file mode 100644 index 00000000..754e9b89 --- /dev/null +++ b/packages/type/src/is/not/test/is-not-number.spec.ts @@ -0,0 +1,91 @@ +// Function. +import { isNotNumber } from '../lib/is-not-number.func'; +// Variables. +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from '../../test/variables/big-int.const'; +import { Class, CLASS } from '../../test/variables/class.const'; +import { FUNCTION } from '../../test/variables/function.const'; +import { NULL } from '../../test/variables/null.const'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from '../../test/variables/number.const'; +import { OBJECT_ONE, OBJECT_TWO, OBJECT_ONE_NEW, OBJECT_TWO_NEW } from '../../test/variables/object.const'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from '../../test/variables/string.const'; +import { SYMBOL_NUMBER, SYMBOL_STRING } from '../../test/variables/symbol.const'; +import { TRUE, TRUE_EXPECTATION, FALSE, TRUE_INSTANCE, FALSE_INSTANCE, FALSE_EXPECTATION } from '../../test/variables/boolean.const'; +import { UNDEFINED } from '../../test/variables/undefined.const'; +/** + * Checks + * ✓ typeOf() = 'number + * ✓ typeof !== 'number' + * ✓ instanceof Number === false + */ +describe(`isNotNumber`, () => { + // Defined. + it('is DEFINED', () => expect(isNotNumber).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + it('callback', () => { + isNotNumber(STRING, (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); + }); + + // ... arrays. + describe(`array`, () => { + // it(`${FUNCTION}`, () => expect(isNotNumber(FUNCTION, 'function')).toBe(TRUE)); + // it(`${Class}`, () => expect(isNotNumber(Class, 'function')).toBe(TRUE)); + }); + // ... function. + describe(`function`, () => { + it(`FUNCTION`, () => expect(isNotNumber(FUNCTION)).toBe(TRUE)); + it(`Class`, () => expect(isNotNumber(Class)).toBe(TRUE)); + }); + // ... objects. + describe('object', () => { + it(`CLASS`, () => expect(isNotNumber(CLASS)).toBe(TRUE)); + it(`OBJECT_ONE`, () => expect(isNotNumber(OBJECT_ONE)).toBe(TRUE)); + it(`OBJECT_TWO`, () => expect(isNotNumber(OBJECT_TWO)).toBe(TRUE)); + it(`new Object(OBJECT_ONE_NEW})`, () => expect(isNotNumber(OBJECT_ONE_NEW)).toBe(TRUE)); + it(`new Object(OBJECT_TWO_NEW})`, () => expect(isNotNumber(OBJECT_TWO_NEW)).toBe(TRUE)); + }); + // ... primitives. + describe(`primitive`, () => { + // bigint + describe(`bigint`, () => { + it(`${BIGINT}`, () => expect(isNotNumber(BIGINT)).toBe(TRUE)); + it(`${BIGINT_EXPECTATION}`, () => expect(isNotNumber(BIGINT_INSTANCE)).toBe(TRUE)); + }); + + // boolean + describe(`boolean`, () => { + it(`${TRUE}`, () => expect(isNotNumber(TRUE)).toBe(TRUE)); + it(`${FALSE}`, () => expect(isNotNumber(FALSE)).toBe(TRUE)); + it(`${TRUE_EXPECTATION}`, () => expect(isNotNumber(TRUE_INSTANCE)).toBe(TRUE)); + it(`${FALSE_EXPECTATION}`, () => expect(isNotNumber(FALSE_INSTANCE)).toBe(TRUE)); + }); + + // null + it(`${NULL}`, () => expect(isNotNumber(NULL)).toBe(TRUE)); + + // number + describe(`number`, () => { + it(`${NUMBER}`, () => expect(isNotNumber(NUMBER)).toBe(FALSE)); + it(`Number(${NUMBER})`, () => expect(isNotNumber(NUMBER_INSTANCE)).toBe(FALSE)); + it(`new Number(${NUMBER})`, () => expect(isNotNumber(NUMBER_NEW_INSTANCE)).toBe(FALSE)); + }); + // string + describe(`string`, () => { + it(`${STRING}`, () => expect(isNotNumber(STRING)).toBe(TRUE)); + it(`String(${STRING})`, () => expect(isNotNumber(STRING_INSTANCE)).toBe(TRUE)); + it(`new String(${STRING})`, () => expect(isNotNumber(STRING_NEW_INSTANCE)).toBe(TRUE)); + }); + // symbol + describe(`symbol`, () => { + it(`Symbol(${NUMBER})`, () => expect(isNotNumber(SYMBOL_NUMBER)).toBe(TRUE)); + it(`Symbol(${STRING})`, () => expect(isNotNumber(SYMBOL_STRING)).toBe(TRUE)); + }); + // undefined + it(`${UNDEFINED}`, () => expect(isNotNumber(UNDEFINED)).toBe(TRUE)); + }); + }); +}); diff --git a/packages/type/src/is/not/test/is-not-string.spec.ts b/packages/type/src/is/not/test/is-not-string.spec.ts new file mode 100644 index 00000000..fadfb2d6 --- /dev/null +++ b/packages/type/src/is/not/test/is-not-string.spec.ts @@ -0,0 +1,91 @@ +// Function. +import { isNotString } from '../lib/is-not-string.func'; +// Variables. +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from '../../test/variables/big-int.const'; +import { Class, CLASS } from '../../test/variables/class.const'; +import { FUNCTION } from '../../test/variables/function.const'; +import { NULL } from '../../test/variables/null.const'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from '../../test/variables/number.const'; +import { OBJECT_ONE, OBJECT_TWO, OBJECT_ONE_NEW, OBJECT_TWO_NEW } from '../../test/variables/object.const'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from '../../test/variables/string.const'; +import { SYMBOL_NUMBER, SYMBOL_STRING } from '../../test/variables/symbol.const'; +import { TRUE, TRUE_EXPECTATION, FALSE, TRUE_INSTANCE, FALSE_EXPECTATION, FALSE_INSTANCE } from '../../test/variables/boolean.const'; +import { UNDEFINED } from '../../test/variables/undefined.const'; +/** + * Checks + * ✓ typeOf() = 'string + * ✓ typeof !== 'string' + * ✓ instanceof String === false + */ +describe(`isNotString`, () => { + // Defined. + it('is DEFINED', () => expect(isNotString).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + it('callback', () => { + isNotString(STRING, (result: boolean) => { + expect(result).toBe(FALSE); + return result; + }); + }); + + // ... arrays. + describe(`array`, () => { + // it(`${FUNCTION}`, () => expect(isNotString(FUNCTION, 'function')).toBe(TRUE)); + // it(`${Class}`, () => expect(isNotString(Class, 'function')).toBe(TRUE)); + }); + // ... function. + describe(`function`, () => { + it(`FUNCTION`, () => expect(isNotString(FUNCTION)).toBe(TRUE)); + it(`Class`, () => expect(isNotString(Class)).toBe(TRUE)); + }); + // ... objects. + describe('object', () => { + it(`CLASS`, () => expect(isNotString(CLASS)).toBe(TRUE)); + it(`OBJECT_ONE`, () => expect(isNotString(OBJECT_ONE)).toBe(TRUE)); + it(`OBJECT_TWO`, () => expect(isNotString(OBJECT_TWO)).toBe(TRUE)); + it(`new Object(OBJECT_ONE_NEW})`, () => expect(isNotString(OBJECT_ONE_NEW)).toBe(TRUE)); + it(`new Object(OBJECT_TWO_NEW})`, () => expect(isNotString(OBJECT_TWO_NEW)).toBe(TRUE)); + }); + // ... primitives. + describe(`primitive`, () => { + // bigint + describe(`bigint`, () => { + it(`${BIGINT}`, () => expect(isNotString(BIGINT)).toBe(TRUE)); + it(`${BIGINT_EXPECTATION}`, () => expect(isNotString(BIGINT_INSTANCE)).toBe(TRUE)); + }); + + // boolean + describe(`boolean`, () => { + it(`${TRUE}`, () => expect(isNotString(TRUE)).toBe(TRUE)); + it(`${FALSE}`, () => expect(isNotString(FALSE)).toBe(TRUE)); + it(`${TRUE_EXPECTATION}`, () => expect(isNotString(TRUE_INSTANCE)).toBe(TRUE)); + it(`${FALSE_EXPECTATION}`, () => expect(isNotString(FALSE_INSTANCE)).toBe(TRUE)); + }); + + // null + it(`${NULL}`, () => expect(isNotString(NULL)).toBe(TRUE)); + + // number + describe(`number`, () => { + it(`${NUMBER}`, () => expect(isNotString(NUMBER)).toBe(TRUE)); + it(`Number(${NUMBER})`, () => expect(isNotString(NUMBER_INSTANCE)).toBe(TRUE)); + it(`new Number(${NUMBER})`, () => expect(isNotString(NUMBER_NEW_INSTANCE)).toBe(TRUE)); + }); + // string + describe(`string`, () => { + it(`${STRING}`, () => expect(isNotString(STRING)).toBe(FALSE)); + it(`String(${STRING})`, () => expect(isNotString(STRING_INSTANCE)).toBe(FALSE)); + it(`new String(${STRING})`, () => expect(isNotString(STRING_NEW_INSTANCE)).toBe(FALSE)); + }); + // symbol + describe(`symbol`, () => { + it(`Symbol(${NUMBER})`, () => expect(isNotString(SYMBOL_NUMBER)).toBe(TRUE)); + it(`Symbol(${STRING})`, () => expect(isNotString(SYMBOL_STRING)).toBe(TRUE)); + }); + // undefined + it(`${UNDEFINED}`, () => expect(isNotString(UNDEFINED)).toBe(TRUE)); + }); + }); +}); diff --git a/packages/type/src/is/not/test/is-not-undefined.spec.ts b/packages/type/src/is/not/test/is-not-undefined.spec.ts new file mode 100644 index 00000000..d9753290 --- /dev/null +++ b/packages/type/src/is/not/test/is-not-undefined.spec.ts @@ -0,0 +1,91 @@ +// Function. +import { isNotUndefined } from '../lib/is-not-undefined.func'; +// Variables. +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from '../../test/variables/big-int.const'; +import { Class, CLASS } from '../../test/variables/class.const'; +import { FUNCTION } from '../../test/variables/function.const'; +import { NULL } from '../../test/variables/null.const'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from '../../test/variables/number.const'; +import { OBJECT_ONE, OBJECT_TWO, OBJECT_ONE_NEW, OBJECT_TWO_NEW } from '../../test/variables/object.const'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from '../../test/variables/string.const'; +import { SYMBOL_NUMBER, SYMBOL_STRING } from '../../test/variables/symbol.const'; +import { TRUE, TRUE_EXPECTATION, FALSE, TRUE_INSTANCE } from '../../test/variables/boolean.const'; +import { UNDEFINED } from '../../test/variables/undefined.const'; +/** + * Checks + * ✓ typeOf() = 'undefined + * ✓ typeof === 'undefined' + * ✓ value === undefined + */ +describe(`isNotUndefined`, () => { + // Defined. + it('is DEFINED', () => expect(isNotUndefined).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + it('callback', () => { + isNotUndefined(STRING, (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); + }); + + // ... arrays. + describe(`array`, () => { + // it(`${FUNCTION}`, () => expect(isNotUndefined(FUNCTION, 'function')).toBe(TRUE)); + // it(`${Class}`, () => expect(isNotUndefined(Class, 'function')).toBe(TRUE)); + }); + // ... function. + describe(`function`, () => { + it(`FUNCTION`, () => expect(isNotUndefined(FUNCTION)).toBe(TRUE)); + it(`Class`, () => expect(isNotUndefined(Class)).toBe(TRUE)); + }); + // ... objects. + describe('object', () => { + it(`CLASS`, () => expect(isNotUndefined(CLASS)).toBe(TRUE)); + it(`OBJECT_ONE`, () => expect(isNotUndefined(OBJECT_ONE)).toBe(TRUE)); + it(`OBJECT_TWO`, () => expect(isNotUndefined(OBJECT_TWO)).toBe(TRUE)); + it(`new Object(OBJECT_ONE_NEW})`, () => expect(isNotUndefined(OBJECT_ONE_NEW)).toBe(TRUE)); + it(`new Object(OBJECT_TWO_NEW})`, () => expect(isNotUndefined(OBJECT_TWO_NEW)).toBe(TRUE)); + }); + // ... primitives. + describe(`primitive`, () => { + // bigint + describe(`bigint`, () => { + it(`${BIGINT}`, () => expect(isNotUndefined(BIGINT)).toBe(TRUE)); + it(`${BIGINT_EXPECTATION}`, () => expect(isNotUndefined(BIGINT_INSTANCE)).toBe(TRUE)); + }); + + // boolean + describe(`boolean`, () => { + it(`${TRUE}`, () => expect(isNotUndefined(TRUE)).toBe(TRUE)); + it(`${FALSE}`, () => expect(isNotUndefined(FALSE)).toBe(TRUE)); + it(`${TRUE_EXPECTATION}`, () => expect(isNotUndefined(TRUE_INSTANCE)).toBe(TRUE)); + it(`${TRUE_EXPECTATION}`, () => expect(isNotUndefined(TRUE_INSTANCE)).toBe(TRUE)); + }); + + // null + it(`${NULL}`, () => expect(isNotUndefined(NULL)).toBe(TRUE)); + + // number + describe(`number`, () => { + it(`${NUMBER}`, () => expect(isNotUndefined(NUMBER)).toBe(TRUE)); + it(`Number(${NUMBER})`, () => expect(isNotUndefined(NUMBER_INSTANCE)).toBe(TRUE)); + it(`new Number(${NUMBER})`, () => expect(isNotUndefined(NUMBER_NEW_INSTANCE)).toBe(TRUE)); + }); + // string + describe(`string`, () => { + it(`${STRING}`, () => expect(isNotUndefined(STRING)).toBe(TRUE)); + it(`String(${STRING})`, () => expect(isNotUndefined(STRING_INSTANCE)).toBe(TRUE)); + it(`new String(${STRING})`, () => expect(isNotUndefined(STRING_NEW_INSTANCE)).toBe(TRUE)); + }); + // symbol + describe(`symbol`, () => { + it(`Symbol(${NUMBER})`, () => expect(isNotUndefined(SYMBOL_NUMBER)).toBe(TRUE)); + it(`Symbol(${STRING})`, () => expect(isNotUndefined(SYMBOL_STRING)).toBe(TRUE)); + }); + // undefined + it(`${UNDEFINED}`, () => expect(isNotUndefined(UNDEFINED)).toBe(FALSE)); + }); + }); +}); diff --git a/packages/type/src/is/not/test/is-not.spec.ts b/packages/type/src/is/not/test/is-not.spec.ts new file mode 100644 index 00000000..8c57dab8 --- /dev/null +++ b/packages/type/src/is/not/test/is-not.spec.ts @@ -0,0 +1,28 @@ +import { isNot } from '../lib/is-not.object'; + +describe('`isNot`', () => { + describe('DEFINED', () => { + it('isNot', () => expect(isNot).toBeDefined()); + // it('isNot.array()', () => expect(isNot.boolean).toBeDefined()); + it('isNot.boolean()', () => expect(isNot.boolean).toBeDefined()); + // it('isNot.booleanObject()', () => expect(isNot.booleanObject).toBeDefined()); + // it('isNot.booleanType()', () => expect(isNot.booleanType).toBeDefined()); + it('isNot.defined()', () => expect(isNot.defined).toBeDefined()); + it('isNot.function()', () => expect(isNot.function).toBeDefined()); + // it('isNot.instance()', () => expect(isNot.instance).toBeDefined()); + // it('isNot.key()', () => expect(isNot.key).toBeDefined()); + it('isNot.null()', () => expect(isNot.null).toBeDefined()); + it('isNot.number()', () => expect(isNot.number).toBeDefined()); + // it('isNot.numberObject()', () => expect(isNot.numberObject).toBeDefined()); + // it('isNot.numberType()', () => expect(isNot.numberType).toBeDefined()); + // it('isNot.object()', () => expect(isNot.object).toBeDefined()); + // it('isNot.objectKey()', () => expect(isNot.objectKey).toBeDefined()); + // it('isNot.primitive()', () => expect(isNot.primitive).toBeDefined()); + it('isNot.string()', () => expect(isNot.string).toBeDefined()); + // it('isNot.stringObject()', () => expect(isNot.stringObject).toBeDefined()); + // it('isNot.stringType()', () => expect(isNot.stringType).toBeDefined()); + // it('isNot.symbol()', () => expect(isNot.symbol).toBeDefined()); + // it('isNot.type()', () => expect(isNot.type).toBeDefined()); + it('isNot.undefined()', () => expect(isNot.undefined).toBeDefined()); + }); +}); From 9bbb5e0bb642d69fb33e2e5f81fc642802519763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 28 Apr 2021 19:30:08 +0200 Subject: [PATCH 172/201] feat: all `ResultCallback` feature to all functions --- .../src/is/not/lib/is-not-boolean.func.ts | 18 +++++++++++------ .../src/is/not/lib/is-not-defined.func.ts | 12 ++++++----- .../src/is/not/lib/is-not-function.func.ts | 12 ++++++----- .../type/src/is/not/lib/is-not-null.func.ts | 11 ++++++---- .../type/src/is/not/lib/is-not-number.func.ts | 20 ++++++++++++------- .../type/src/is/not/lib/is-not-string.func.ts | 12 ++++++----- .../src/is/not/lib/is-not-undefined.func.ts | 10 ++++++---- .../src/is/not/type/is-not-boolean.type.ts | 3 ++- .../src/is/not/type/is-not-defined.type.ts | 3 ++- .../src/is/not/type/is-not-function.type.ts | 3 ++- .../type/src/is/not/type/is-not-null.type.ts | 3 ++- .../src/is/not/type/is-not-number.type.ts | 3 ++- .../src/is/not/type/is-not-string.type.ts | 3 ++- .../src/is/not/type/is-not-undefined.type.ts | 3 ++- 14 files changed, 73 insertions(+), 43 deletions(-) diff --git a/packages/type/src/is/not/lib/is-not-boolean.func.ts b/packages/type/src/is/not/lib/is-not-boolean.func.ts index 92543c7a..f90d0a07 100644 --- a/packages/type/src/is/not/lib/is-not-boolean.func.ts +++ b/packages/type/src/is/not/lib/is-not-boolean.func.ts @@ -1,15 +1,21 @@ // Function. +import { resultCallback } from '../../../lib/result-callback.func'; import { typeOf } from '../../../lib/type-of.func'; // Type. import { IsNotBoolean } from '../type/is-not-boolean.type'; +import { ResultCallback } from '../../../type/result-callback.type'; /** * Checks if an unknown `value` is NOT a `boolean` type, NOT equal to `true` or `false` and NOT instance of `Boolean`. * @param value An unknown `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is not `boolean`. */ -export const isNotBoolean: IsNotBoolean = (value: unknown): boolean => - typeOf(value) !== 'boolean' && - typeof value !== 'boolean' && - value instanceof Boolean === false && - value !== true && - value !== false; +export const isNotBoolean: IsNotBoolean = (value: unknown, callback: ResultCallback = resultCallback): boolean => + callback( + typeOf(value) !== 'boolean' && + typeof value !== 'boolean' && + value instanceof Boolean === false && + value !== true && + value !== false + ); diff --git a/packages/type/src/is/not/lib/is-not-defined.func.ts b/packages/type/src/is/not/lib/is-not-defined.func.ts index 54a1fd7e..4015349d 100644 --- a/packages/type/src/is/not/lib/is-not-defined.func.ts +++ b/packages/type/src/is/not/lib/is-not-defined.func.ts @@ -1,13 +1,15 @@ // Function. +import { resultCallback } from '../../../lib/result-callback.func'; import { typeOf } from '../../../lib/type-of.func'; // Type. import { IsNotDefined } from '../type/is-not-defined.type'; +import { ResultCallback } from '../../../type/result-callback.type'; /** - * Checks if an unknown `value` is a `undefined` type and is equal to `undefined`. + * Checks if an unknown `value` is an `undefined` type and is equal to `undefined`. * @param value An unknown `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is not defined. */ -export const isNotDefined: IsNotDefined = (value: unknown): boolean => - typeOf(value) === 'undefined' && - typeof value === 'undefined' && - value === undefined; +export const isNotDefined: IsNotDefined = (value: unknown, callback: ResultCallback = resultCallback): boolean => + callback(typeOf(value) === 'undefined' && typeof value === 'undefined' && value === undefined); diff --git a/packages/type/src/is/not/lib/is-not-function.func.ts b/packages/type/src/is/not/lib/is-not-function.func.ts index fda68a8f..1e7878f5 100644 --- a/packages/type/src/is/not/lib/is-not-function.func.ts +++ b/packages/type/src/is/not/lib/is-not-function.func.ts @@ -1,13 +1,15 @@ // Function. +import { resultCallback } from '../../../lib/result-callback.func'; import { typeOf } from '../../../lib/type-of.func'; // Type. import { IsNotFunction } from '../type/is-not-function.type'; +import { ResultCallback } from '../../../type/result-callback.type'; /** - * Checks if an unknown `value` is NOT a `function` type and NOT an instance of `Function`. + * Checks if an unknown `value` is not a `function` type and not an instance of `Function`. * @param value An unknown `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is not a `function`. */ -export const isNotFunction: IsNotFunction = (value: unknown): boolean => - typeOf(value) !== 'function' && - typeof value !== 'function' && - value instanceof Function === false; +export const isNotFunction: IsNotFunction = (value: unknown, callback: ResultCallback = resultCallback): boolean => + callback(typeOf(value) !== 'function' && typeof value !== 'function' && value instanceof Function === false); diff --git a/packages/type/src/is/not/lib/is-not-null.func.ts b/packages/type/src/is/not/lib/is-not-null.func.ts index 1cbcdcd7..e3c7bff5 100644 --- a/packages/type/src/is/not/lib/is-not-null.func.ts +++ b/packages/type/src/is/not/lib/is-not-null.func.ts @@ -1,12 +1,15 @@ // Function. +import { resultCallback } from '../../../lib/result-callback.func'; import { typeOf } from '../../../lib/type-of.func'; // Type. import { IsNotNull } from '../type/is-not-null.type'; +import { ResultCallback } from '../../../type/result-callback.type'; /** - * Checks if an unknown `value` is NOT a `null` type and NOT equal to `null`. + * Checks if an unknown `value` is not a `null` type and not equal to `null`. * @param value An unknown `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is not `null`. */ -export const isNotNull: IsNotNull = (value: unknown): boolean => - typeOf(value) !== 'null' && - value !== null; +export const isNotNull: IsNotNull = (value: unknown, callback: ResultCallback = resultCallback): boolean => + callback(typeOf(value) !== 'null' && value !== null); diff --git a/packages/type/src/is/not/lib/is-not-number.func.ts b/packages/type/src/is/not/lib/is-not-number.func.ts index ac232589..3dea9829 100644 --- a/packages/type/src/is/not/lib/is-not-number.func.ts +++ b/packages/type/src/is/not/lib/is-not-number.func.ts @@ -1,14 +1,20 @@ // Function. +import { resultCallback } from '../../../lib/result-callback.func'; import { typeOf } from '../../../lib/type-of.func'; // Type. import { IsNotNumber } from '../type/is-not-number.type'; +import { ResultCallback } from '../../../type/result-callback.type'; + /** - * Checks if any `value` is NOT a `number` type and NOT an instance of `Number`. - * @param value An unknown value to check. + * Checks if any `value` is not a `number` type and not an instance of `Number`. + * @param value An unknown `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is not a `number`. */ -export const isNotNumber: IsNotNumber = (value: any): boolean => - typeOf(value) !== 'number' && - typeof value !== 'number' && - isFinite(value) === false && - value instanceof Number === false; +export const isNotNumber: IsNotNumber = (value: any, callback: ResultCallback = resultCallback): boolean => + callback( + typeOf(value) !== 'number' && + typeof value !== 'number' && + value instanceof Number === false + ); diff --git a/packages/type/src/is/not/lib/is-not-string.func.ts b/packages/type/src/is/not/lib/is-not-string.func.ts index 6abe382d..1408912a 100644 --- a/packages/type/src/is/not/lib/is-not-string.func.ts +++ b/packages/type/src/is/not/lib/is-not-string.func.ts @@ -1,13 +1,15 @@ // Function. +import { resultCallback } from '../../../lib/result-callback.func'; import { typeOf } from '../../../lib/type-of.func'; // Type. import { IsNotString } from '../type/is-not-string.type'; +import { ResultCallback } from '../../../type/result-callback.type'; /** - * Checks if an unknown `value` is NOT a `string` type and NOT an instance of `String`. + * Checks if an unknown `value` is not a `string` type and not an instance of `String`. * @param value An unknown `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is not a `string`. */ -export const isNotString: IsNotString = (value: unknown): boolean => - typeOf(value) !== 'string' && - typeof value !== 'string' && - value instanceof String === false; +export const isNotString: IsNotString = (value: unknown, callback: ResultCallback = resultCallback): boolean => + callback(typeOf(value) !== 'string' && typeof value !== 'string' && value instanceof String === false); diff --git a/packages/type/src/is/not/lib/is-not-undefined.func.ts b/packages/type/src/is/not/lib/is-not-undefined.func.ts index 2d78e874..afe5744c 100644 --- a/packages/type/src/is/not/lib/is-not-undefined.func.ts +++ b/packages/type/src/is/not/lib/is-not-undefined.func.ts @@ -1,13 +1,15 @@ // Function. +import { resultCallback } from '../../../lib/result-callback.func'; import { typeOf } from '../../../lib/type-of.func'; // Type. import { IsNotUndefined } from '../type/is-not-undefined.type'; +import { ResultCallback } from '../../../type/result-callback.type'; /** * Checks if an unknown `value` is NOT an `undefined` type and NOT equal to `undefined`. * @param value An unknown `value` to check. + * @param callback `ResultCallback` function to handle result before returns. + * @callback `resultCallback`. * @returns A `boolean` indicating whether or not the `value` is not `undefined`. */ -export const isNotUndefined: IsNotUndefined = (value: unknown): boolean => - typeOf(value) !== 'undefined' && - typeof value !== 'undefined' && - value !== undefined; +export const isNotUndefined: IsNotUndefined = (value: unknown, callback: ResultCallback = resultCallback): boolean => + callback(typeOf(value) !== 'undefined' && typeof value !== 'undefined' && value !== undefined); diff --git a/packages/type/src/is/not/type/is-not-boolean.type.ts b/packages/type/src/is/not/type/is-not-boolean.type.ts index 6689561a..47e3b15d 100644 --- a/packages/type/src/is/not/type/is-not-boolean.type.ts +++ b/packages/type/src/is/not/type/is-not-boolean.type.ts @@ -1 +1,2 @@ -export type IsNotBoolean = (value: unknown) => boolean; +import { ResultCallback } from '../../../type/result-callback.type'; +export type IsNotBoolean = (value: unknown, callback?: ResultCallback) => boolean; diff --git a/packages/type/src/is/not/type/is-not-defined.type.ts b/packages/type/src/is/not/type/is-not-defined.type.ts index ea742cb2..f2dbea98 100644 --- a/packages/type/src/is/not/type/is-not-defined.type.ts +++ b/packages/type/src/is/not/type/is-not-defined.type.ts @@ -1 +1,2 @@ -export type IsNotDefined = (value: unknown) => boolean; +import { ResultCallback } from '../../../type/result-callback.type'; +export type IsNotDefined = (value: unknown, callback?: ResultCallback) => boolean; diff --git a/packages/type/src/is/not/type/is-not-function.type.ts b/packages/type/src/is/not/type/is-not-function.type.ts index 886ab0ee..1e351720 100644 --- a/packages/type/src/is/not/type/is-not-function.type.ts +++ b/packages/type/src/is/not/type/is-not-function.type.ts @@ -1 +1,2 @@ -export type IsNotFunction = (value: unknown) => boolean; +import { ResultCallback } from '../../../type/result-callback.type'; +export type IsNotFunction = (value: unknown, callback?: ResultCallback) => boolean; diff --git a/packages/type/src/is/not/type/is-not-null.type.ts b/packages/type/src/is/not/type/is-not-null.type.ts index 0a3a5d63..9aad4260 100644 --- a/packages/type/src/is/not/type/is-not-null.type.ts +++ b/packages/type/src/is/not/type/is-not-null.type.ts @@ -1 +1,2 @@ -export type IsNotNull = (value: unknown) => boolean; +import { ResultCallback } from '../../../type/result-callback.type'; +export type IsNotNull = (value: unknown, callback?: ResultCallback) => boolean; diff --git a/packages/type/src/is/not/type/is-not-number.type.ts b/packages/type/src/is/not/type/is-not-number.type.ts index 36cec6b3..f8756ec4 100644 --- a/packages/type/src/is/not/type/is-not-number.type.ts +++ b/packages/type/src/is/not/type/is-not-number.type.ts @@ -1 +1,2 @@ -export type IsNotNumber = (value: any) => boolean; +import { ResultCallback } from '../../../type/result-callback.type'; +export type IsNotNumber = (value: any, callback?: ResultCallback) => boolean; diff --git a/packages/type/src/is/not/type/is-not-string.type.ts b/packages/type/src/is/not/type/is-not-string.type.ts index f7f9bea1..a90f76a3 100644 --- a/packages/type/src/is/not/type/is-not-string.type.ts +++ b/packages/type/src/is/not/type/is-not-string.type.ts @@ -1 +1,2 @@ -export type IsNotString = (value: unknown) => boolean; +import { ResultCallback } from '../../../type/result-callback.type'; +export type IsNotString = (value: unknown, callback?: ResultCallback) => boolean; diff --git a/packages/type/src/is/not/type/is-not-undefined.type.ts b/packages/type/src/is/not/type/is-not-undefined.type.ts index 1351db2e..105bc872 100644 --- a/packages/type/src/is/not/type/is-not-undefined.type.ts +++ b/packages/type/src/is/not/type/is-not-undefined.type.ts @@ -1 +1,2 @@ -export type IsNotUndefined = (value: unknown) => boolean; +import { ResultCallback } from '../../../type/result-callback.type'; +export type IsNotUndefined = (value: unknown, callback?: ResultCallback) => boolean; From 8c674cbe4917bff36cd247a6f0cb06cb6baf23ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 30 Apr 2021 18:38:13 +0200 Subject: [PATCH 173/201] docs(README.md): update --- README.md | 238 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 176 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 1925142b..d5d4c2c4 100644 --- a/README.md +++ b/README.md @@ -126,13 +126,13 @@ import { Constructor, CycleHook, Func, Key, Primitive, Primitives, ResultCallbac ## How angular-package understands Check -> Is to check the return value to be the same as expected. +> Is to check the return value to be **the same** as **expected**. Type guard -> Is to guard type from parameter to not let input unexpected value in the code editor. +> Is to guard type from parameter to **not let** input **unexpected** value in the **code editor**. Guard -> Is a combination of both above to type guard input in the code editor and check the return. +> Is a **combination** of both above to **guard type** inputted value in the **code editor** and to check it. ---- @@ -249,16 +249,19 @@ const is: Is = { Use `isArray()` or `is.array()` to check if **any** `value` is an [`Array`][Array], [`Array`][Array] instance, and `object` type. ```typescript -const isArray: IsArray = (value: any): value is Array => - typeOf(value) === 'array' && - Array.isArray(value) === true && - value instanceof Array === true && - typeof value === 'object'; +const isArray: IsArray = (value: any, callback: ResultCallback = resultCallback): value is Array => + callback( + typeOf(value) === 'array' && + Array.isArray(value) === true && + value instanceof Array === true && + typeof value === 'object' + ); ``` | Parameter | Type | Description | | :-------- | :---: | :---------- | | value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is an [`Array`][Array]. @@ -934,7 +937,7 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` Use `isType()` or `is.type()` to check if **any** `value` is the [`Type`](#Type) from a `type` of the [`Types`](#Types) type. ```typescript -const isType: IsType = (value: any, type: Types): value is T => { +const isType: IsType = (value: any, type: Types, callback: ResultCallback = resultCallback): value is T => { if (isString(type)) { switch (type) { // Primitives. @@ -944,23 +947,25 @@ const isType: IsType = (value: any, type: Types): value is T case 'null' : case 'string': case 'symbol': - case 'undefined': return isPrimitive(value, type); + case 'undefined': return isPrimitive(value, type, callback); // Function. - case 'function': return isFunction(value); + case 'function': return isFunction(value, callback); // Object. case 'object': return isObject(value); } } else if (isNotNull(type)) { - return isInstance(value, type); + return isInstance(value, type, callback); } return false; }; + ``` | Parameter | Type | Description | | :-------- | :------------------: | :---------- | | value | `any` | Any `value` to check if its type is from the `type` | | type | [`Types`](#Types) | A `string` or generic `Constructor` type from the [`Types`](#Types) to check the `value` | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is the [`Type`](#Type) from a `type` of the [`Types`](#Types). @@ -1006,124 +1011,139 @@ const isNot: IsNot = { ### isNotBoolean -Use `isNotBoolean()` or `is.not.boolean()` to check if an **unknown** `value` is NOT a `boolean` type, NOT equal to `true` or `false` and NOT an instance of a `Boolean`. +Use `isNotBoolean()` or `is.not.boolean()` to check if an **unknown** `value` is **not** a `boolean` type, **not** equal to `true` or `false` and **not** an instance of a [`Boolean`][Boolean]. ```typescript -const isNotBoolean: IsNotBoolean = (value: unknown): boolean => - typeOf(value) !== 'boolean' && - typeof value !== 'boolean' && - value instanceof Boolean === false && - value !== true && - value !== false; +const isNotBoolean: IsNotBoolean = (value: unknown, callback: ResultCallback = resultCallback): boolean => + callback( + typeOf(value) !== 'boolean' && + typeof value !== 'boolean' && + value instanceof Boolean === false && + value !== true && + value !== false + ); ``` | Parameter | Type | Description | | :-------- | :-------: | :---------- | -| value | `unknown` | An unknown `value` to check if it's NOT a `'boolean'` type, NOT equal to `true` or `false` and NOT an instance of `Boolean`. | +| value | `unknown` | An unknown `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | -The **return value** is a `boolean` indicating whether or not the `value` is `undefined`. +The **return value** is a `boolean` indicating whether or not the `value` is not a `boolean`. ---- ### isNotDefined -Use `isNotDefined()` or `is.not.defined()` to check if an **unknown** `value` is an `'undefined'` type and is equal to `undefined`. The return value is a `boolean` value. +Use `isNotDefined()` or `is.not.defined()` to check if an **unknown** `value` is an `undefined` type and is equal to `undefined`. ```typescript -const isNotDefined: IsNotDefined = (value: unknown): boolean => - typeOf(value) === 'undefined' && - typeof value === 'undefined' && - value === undefined; +const isNotDefined: IsNotDefined = (value: unknown, callback: ResultCallback = resultCallback): boolean => + callback(typeOf(value) === 'undefined' && typeof value === 'undefined' && value === undefined); ``` | Parameter | Type | Description | |-----------| :-------: |-------------| -| value | `unknown` | An unknown `value` to check if it's an `'undefined'` type and is equal to `undefined`. | +| value | `unknown` | An unknown `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The return value is a `boolean` indicating whether or not the `value` is not defined, is `undefined`. ---- ### isNotFunction -Use `isNotFunction()` or `is.not.function()` to check if an **unknown** `value` is NOT a `function` type and NOT an instance of `Function`. The return value is a `boolean` value. +Use `isNotFunction()` or `is.not.function()` to check if an **unknown** `value` is **not** a `function` type and **not** an instance of `Function`. ```typescript -const isNotFunction: IsNotFunction = (value: unknown): boolean => - typeOf(value) !== 'function' && - typeof value !== 'function' && - value instanceof Function === false; +const isNotFunction: IsNotFunction = (value: unknown, callback: ResultCallback = resultCallback): boolean => + callback(typeOf(value) !== 'function' && typeof value !== 'function' && value instanceof Function === false); ``` | Parameter | Type | Description | |-----------| :-------: |-------------| -| value | `unknown` | An unknown `value` to check. | +| value | `unknown` | An unknown `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The return value is a `boolean` indicating whether or not the `value` is not a `function`. ---- ### isNotNull -Use `isNotNull()` or `is.not.null()` to check if an **unknown** `value` is NOT a `null` type and NOT equal to `null`. The return value is a `boolean` value. +Use `isNotNull()` or `is.not.null()` to check if an **unknown** `value` is **not** a `null` type and **not** equal to `null`. ```typescript -const isNotNull: IsNotNull = (value: unknown): boolean => - typeOf(value) !== 'null' && - value !== null; +const isNotNull: IsNotNull = (value: unknown, callback: ResultCallback = resultCallback): boolean => + callback(typeOf(value) !== 'null' && value !== null); ``` | Parameter | Type | Description | |-----------| :-------: |-------------| -| value | `unknown` | An unknown `value` to check. | +| value | `unknown` | An unknown `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The return value is a `boolean` indicating whether or not the `value` is not `null`. ---- ### isNotNumber -Use `isNotNumber()` or `is.not.number()` to check if an **unknown** `value` is NOT a `number` type and NOT an instance of `Number`. The return value is a `boolean` value. +Use `isNotNumber()` or `is.not.number()` to check if an **unknown** `value` is **not** a `number` type and **not** an instance of `Number`. ```typescript -const isNotNumber: IsNotNumber = (value: any): boolean => - typeOf(value) !== 'number' && - typeof value !== 'number' && - isFinite(value) === false && - value instanceof Number === false; +const isNotNumber: IsNotNumber = (value: any, callback: ResultCallback = resultCallback): boolean => + callback( + typeOf(value) !== 'number' && + typeof value !== 'number' && + value instanceof Number === false + ); ``` | Parameter | Type | Description | |-----------| :-------: |-------------| -| value | `unknown` | An unknown `value` to check. | +| value | `unknown` | An unknown `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The return value is a `boolean` indicating whether or not the `value` is not a `number`. ---- ### isNotString -Use `isNotString()` or `is.not.string()` to check if an **unknown** `value` is NOT a `string` type and NOT an instance of `String`. The return value is a `boolean` value. +Use `isNotString()` or `is.not.string()` to check if an **unknown** `value` is **not** a `string` type and **not** an instance of `String`. ```typescript -const isNotString: IsNotString = (value: unknown): boolean => - typeOf(value) !== 'string' && - typeof value !== 'string' && - value instanceof String === false; +const isNotString: IsNotString = (value: unknown, callback: ResultCallback = resultCallback): boolean => + callback(typeOf(value) !== 'string' && typeof value !== 'string' && value instanceof String === false); ``` | Parameter | Type | Description | |-----------| :-------: |-------------| -| value | `unknown` | An unknown `value` to check. | +| value | `unknown` | An unknown `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The return value is a `boolean` indicating whether or not the `value` is not a `string`. ---- ### isNotUndefined -Use `isNotUndefined()` or `is.not.undefined()` to check if an **unknown** `value` is NOT an `undefined` type and NOT equal to `undefined`. The return value is a `boolean` value. +Use `isNotUndefined()` or `is.not.undefined()` to check if an **unknown** `value` is **not** an `undefined` type and **not** equal to `undefined`. ```typescript -const isNotUndefined: IsNotUndefined = (value: unknown): boolean => - typeOf(value) !== 'undefined' && - typeof value !== 'undefined' && - value !== undefined; +const isNotUndefined: IsNotUndefined = (value: unknown, callback: ResultCallback = resultCallback): boolean => + callback(typeOf(value) !== 'undefined' && typeof value !== 'undefined' && value !== undefined); ``` | Parameter | Type | Description | |-----------| :-------: |-------------| -| value | `unknown` | An Unknown `value` to check. | +| value | `unknown` | An unknown `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The return value is a `boolean` indicating whether or not the `value` is not `undefined`. + +---- ## Guard @@ -1153,19 +1173,57 @@ const guard: Guard = { Use `guardArray()` or `guard.is.array()` to guard the `value` to be an [`Array`][Array] of a generic `Type`. ```typescript -const guardArray: GuardArray = (value: Array): value is Array => isArray(value); +const guardArray: GuardArray = (value: Array, callback?: ResultCallback): value is Array => + isArray(value, callback); ``` -| Parameter | Type | Description | -|-----------| :-----------: |-------------| -| value | `Array` | A generic `Type` `Array` `value` to guard | +| Parameter | Type | Description | +|-----------| :---------------------------------: |-------------| +| value | `Array` | A generic `Type` `Array` `value` to guard | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | -The return value is a `boolean` indicating whether or not the `value` is an [`Array`][Array] of a generic `Type`. +The **return value** is a `boolean` indicating whether or not the `value` is an [`Array`][Array] of a generic `Type`. [Example usage on playground][guard-array] ---- +### guardBigInt + +Use `guardBigInt()` or `guard.is.bigint()` to guard the `value` to be a `bigint`. + +```typescript +const guardBigInt: GuardBigInt = (value: bigint, callback?: ResultCallback): value is bigint => + isBigInt(value, callback); +``` + +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :---------- | +| value | `bigint` | A `bigint` type `value` to guard | +| callback | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a `bigint`. + +---- + +### guardBoolean + +Use `guardBoolean()` or `guard.is.boolean()` to guard the `value` to be a `boolean`. + +```typescript +const guardBoolean: GuardBoolean = (value: boolean, callback?: ResultCallback): value is boolean => + isBoolean(value, callback); +``` + +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :---------- | +| value | `boolean` | A `boolean` type `value` to guard | +| callback | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a `boolean`. + +---- + ### guardFunction Use `guardFunction()` or `guard.is.function()` to guard the `value` to be a [`Func`](#Func) type. @@ -1200,6 +1258,24 @@ The **return value** is a `boolean` indicating whether or not the `value` is a [ ---- +### guardNull + +Use `guardNull()` or `guard.is.null()` to guard the `value` to be a `null`. + +```typescript +const guardNull: GuardNull = (value: null, callback?: ResultCallback): value is null => + isNull(value, callback); +``` + +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :---------- | +| value | `null` | A `null` type `value` to guard | +| callback | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a `null`. + +---- + ### guardNumber Use `guardNumber()` or `guard.is.number()` to guard the `value` to be a `number`. @@ -1293,6 +1369,24 @@ The return value is a `boolean` indicating whether or not the `value` is a `stri ---- +### guardSymbol + +Use `guardSymbol()` or `guard.is.symbol()` to guard the `value` to be a `symbol`. + +```typescript +const guardSymbol: GuardSymbol = (value: symbol, callback?: ResultCallback): value is symbol => + isSymbol(value, callback); +``` + +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :---------- | +| value | `null` | A `null` type `value` to guard | +| callback | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a `symbol`. + +---- + ### guardType Use `guardType()` or `guard.is.type()` to guard the `value` to be the [`Type`](#Type) from a `type` of the [`Types`](#Types). @@ -1310,6 +1404,26 @@ The return value is a `boolean` indicating whether or not the `value` is a `type [Example usage on playground][guard-type] +---- + +### guardUndefined + +Use `guardUndefined()` or `guard.is.undefined()` to guard the `value` to be `undefined`. + +```typescript +const guardUndefined: GuardUndefined = (value: undefined, callback?: ResultCallback): value is undefined => + isUndefined(value, callback); +``` + +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :---------- | +| value | `undefined` | A `undefined` type `value` to guard | +| callback | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is `undefined`. + +---- + ## Common types ### Constructor From d4aab97a3dd8853dd12259ee78aa1e4e122121d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 30 Apr 2021 19:12:19 +0200 Subject: [PATCH 174/201] docs(README.md): update --- README.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d5d4c2c4..7fde0f2e 100644 --- a/README.md +++ b/README.md @@ -161,13 +161,13 @@ npm i --save @angular-package/type ## resultCallback -Default function to handle `callback` parameter. +Default function to handle `callback`. ```typescript const resultCallback: ResultCallback = (result: boolean): boolean => result; ``` -Custom function to handle `callback` parameter. +Custom function to handle `callback`. ```typescript const customCallback: ResultCallback = (result: boolean): boolean => { @@ -1154,13 +1154,20 @@ Object `guard` with all **guard** functions. ```typescript const guardIs: GuardIs = { array: guardArray, + bigint: guardBigInt, + boolean: guardBoolean, function: guardFunction, + instance: guardInstance, + key: guardKey, number: guardNumber, - objectKey: guardObjectKey, + null: guardNull, object: guardObject, + objectKey: guardObjectKey, primitive: guardPrimitive, string: guardString, - type: guardType + symbol: guardSymbol, + type: guardType, + undefined: guardUndefined }; const guard: Guard = { is: guardIs From 023bd3fc61d9e9820abd221a544aeb244a6c0b58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Fri, 30 Apr 2021 19:42:21 +0200 Subject: [PATCH 175/201] docs(README.md): update --- README.md | 226 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 129 insertions(+), 97 deletions(-) diff --git a/README.md b/README.md index 7fde0f2e..1b7a2a39 100644 --- a/README.md +++ b/README.md @@ -201,8 +201,8 @@ const are: Are = { const areString = (...args: any): boolean => check('string', ...args); ``` -| Parameter | Type | Description | -|-----------| :---: |-------------| +| Parameter | Type | Description | +| :-------- | :---: | :------------------------------------------------- | | ...args | `any` | Any arguments to check they're all a `string` type | The **return value** is a `boolean` value. @@ -258,8 +258,8 @@ const isArray: IsArray = (value: any, callback: ResultCallback = resultCal ); ``` -| Parameter | Type | Description | -| :-------- | :---: | :---------- | +| Parameter | Type | Description | +| :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -316,8 +316,8 @@ const isBoolean: IsBoolean = (value: any, callback: ResultCallback = resultCallb callback(typeOf(value) === 'boolean' && (isBooleanType(value) || isBooleanObject(value))); ``` -| Parameter | Type | Description | -| :---------| :---: | :---------- | +| Parameter | Type | Description | +| :---------| :---: | :------------------- | | value | `any` | Any `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -345,8 +345,8 @@ const isBooleanObject: IsBooleanObject = (value: any, callback: ResultCallback = callback(typeof value === 'object' && value instanceof Boolean === true && value instanceof Object === true); ``` -| Parameter | Type | Description | -| :---------| :---: | :---------- | +| Parameter | Type | Description | +| :---------| :---: | :------------------- | | value | `any` | Any `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -377,8 +377,8 @@ const isBooleanType: IsBooleanType = (value: any, callback: ResultCallback = res ); ``` -| Parameter | Type | Description | -| :---------| :---: | :---------- | +| Parameter | Type | Description | +| :---------| :---: | :------------------- | | value | `any` | Any `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -404,8 +404,8 @@ const isDefined: IsDefined = (value: unknown, callback: ResultCallback = resultC callback(typeOf(value) !== 'undefined' && typeof value !== 'undefined' && value !== undefined); ``` -| Parameter | Type | Description | -| :-------- | :-------: | :---------- | +| Parameter | Type | Description | +| :-------- | :-------: | :---------------------------- | | value | `unknown` | An `unknown` `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -436,8 +436,8 @@ const isFunction: IsFunction = (value: any, callback: ResultCallback = resultCal ); ``` -| Parameter | Type | Description | -| :-------- | :---: | :---------- | +| Parameter | Type | Description | +| :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -510,8 +510,8 @@ const isKey: IsKey = (value: any, callback: ResultCallback = resultCallback): va callback(isString(value) || isNumber(value) || isSymbol(value)); ``` -| Parameter | Type | Description | -| :-------- | :---: |:----------- | +| Parameter | Type | Description | +| :-------- | :---: |:-------------------- | | value | `any` | Any `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -546,8 +546,8 @@ const isNull: IsNull = (value: any, callback: ResultCallback = resultCallback): callback(typeOf(value) === 'null' && typeof value === 'object' && value === null); ``` -| Parameter | Type | Description | -| :-------- | :---: |------------ | +| Parameter | Type | Description | +| :-------- | :---: |--------------------- | | value | `any` | Any `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -581,8 +581,8 @@ const isNumber: IsNumber = (value: any, callback: ResultCallback = resultCallbac callback(typeOf(value) === 'number' && isFinite(value) === true && (isNumberType(value) || isNumberObject(value))); ``` -| Parameter | Type | Description | -| :-------- | :---: | :---------- | +| Parameter | Type | Description | +| :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -601,8 +601,8 @@ const isNumberObject: IsNumberObject = (value: any, callback: ResultCallback = r callback(typeof value === 'object' && value instanceof Number === true && value instanceof Object === true); ``` -| Parameter | Type | Description | -| :-------- | :---: | :---------- | +| Parameter | Type | Description | +| :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -650,8 +650,8 @@ const isNumberType: IsNumberType = (value: any, callback: ResultCallback = resul callback(value instanceof Number === false && value instanceof Object === false && typeof value === 'number'); ``` -| Parameter | Type | Description | -| :-------- | :---: | :---------- | +| Parameter | Type | Description | +| :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -811,8 +811,8 @@ const isObjectKey: IsObjectKey = ( ); ``` -| Parameter | Type | Description | -| :-------- | :------------------------------: | :---------- | +| Parameter | Type | Description | +| :-------- | :------------------------------: | :---------------------------------------------------- | | value | `any` | Any `value` to check if it contains a specified `key` | | key | [`Key`](#key) \| [`Key`](#Key)[] | A [`Key`](#Key) type or an array of [`Key`](#Key) type to check in the `value` | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -846,9 +846,9 @@ const isPrimitive: IsPrimitive = ( }; ``` -| Parameter | Type | Description | -| :-------- | :-------------------------: | :---------- | -| value | `any` | Any `value` to check if it's a `Primitive` from the `type` | +| Parameter | Type | Description | +| :-------- | :-------------------------: | :------------------------------------------------------------------------ | +| value | `any` | Any `value` to check if it's a `Primitive` from the `type` | | type | [`Primitives`](#Primitives) | A `string` type from the [`Primitives`](#Primitives) to check the `value` | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -867,8 +867,8 @@ const isString: IsString = (value: any, callback: ResultCallback = resultCallbac callback(typeOf(value) === 'string' && (isStringObject(value) || isStringType(value))); ``` -| Parameter | Type | Description | -| :-------- | :---------------------------------: | :---------- | +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :------------------- | | value | `any` | Any `value` to check | | callback | [`ResultCallback`](#ResultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -885,8 +885,8 @@ const isStringObject: IsStringObject = (value: any, callback: ResultCallback = r callback(value instanceof Object === true && value instanceof String === true && typeof value === 'object'); ``` -| Parameter | Type | Description | -| :-------- | :---------------------------------: | :---------- | +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :------------------- | | value | `any` | Any `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -903,8 +903,8 @@ const isStringType: IsStringType = (value: any, callback: ResultCallback = resul callback(value instanceof Object === false && value instanceof String === false && typeof value === 'string'); ``` -| Parameter | Type | Description | -| :-------- | :---------------------------------: | :---------- | +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :------------------- | | value | `any` | Any `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -921,8 +921,8 @@ const isSymbol: IsSymbol = (value: any, callback: ResultCallback = resultCallbac callback(typeOf(value) === 'symbol' && typeof value === 'symbol'); ``` -| Parameter | Type | Description | -| :-------- | :---: | :---------- | +| Parameter | Type | Description | +| :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -961,8 +961,8 @@ const isType: IsType = (value: any, type: Types, callback: Re ``` -| Parameter | Type | Description | -| :-------- | :------------------: | :---------- | +| Parameter | Type | Description | +| :-------- | :------------------: | :-------------------------------------------------- | | value | `any` | Any `value` to check if its type is from the `type` | | type | [`Types`](#Types) | A `string` or generic `Constructor` type from the [`Types`](#Types) to check the `value` | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -982,8 +982,8 @@ const isUndefined: IsUndefined = (value: any, callback: ResultCallback = resultC callback(typeOf(value) === 'undefined' && typeof value === 'undefined' && value === undefined); ``` -| Parameter | Type | Description | -| :-------- | :---: | :---------- | +| Parameter | Type | Description | +| :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -1024,8 +1024,8 @@ const isNotBoolean: IsNotBoolean = (value: unknown, callback: ResultCallback = r ); ``` -| Parameter | Type | Description | -| :-------- | :-------: | :---------- | +| Parameter | Type | Description | +| :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -1042,8 +1042,8 @@ const isNotDefined: IsNotDefined = (value: unknown, callback: ResultCallback = r callback(typeOf(value) === 'undefined' && typeof value === 'undefined' && value === undefined); ``` -| Parameter | Type | Description | -|-----------| :-------: |-------------| +| Parameter | Type | Description | +| :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -1060,8 +1060,8 @@ const isNotFunction: IsNotFunction = (value: unknown, callback: ResultCallback = callback(typeOf(value) !== 'function' && typeof value !== 'function' && value instanceof Function === false); ``` -| Parameter | Type | Description | -|-----------| :-------: |-------------| +| Parameter | Type | Description | +| :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -1078,8 +1078,8 @@ const isNotNull: IsNotNull = (value: unknown, callback: ResultCallback = resultC callback(typeOf(value) !== 'null' && value !== null); ``` -| Parameter | Type | Description | -|-----------| :-------: |-------------| +| Parameter | Type | Description | +| :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -1100,8 +1100,8 @@ const isNotNumber: IsNotNumber = (value: any, callback: ResultCallback = resultC ); ``` -| Parameter | Type | Description | -|-----------| :-------: |-------------| +| Parameter | Type | Description | +| :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -1118,8 +1118,8 @@ const isNotString: IsNotString = (value: unknown, callback: ResultCallback = res callback(typeOf(value) !== 'string' && typeof value !== 'string' && value instanceof String === false); ``` -| Parameter | Type | Description | -|-----------| :-------: |-------------| +| Parameter | Type | Description | +| :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -1136,8 +1136,8 @@ const isNotUndefined: IsNotUndefined = (value: unknown, callback: ResultCallback callback(typeOf(value) !== 'undefined' && typeof value !== 'undefined' && value !== undefined); ``` -| Parameter | Type | Description | -|-----------| :-------: |-------------| +| Parameter | Type | Description | +| :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | @@ -1204,10 +1204,10 @@ const guardBigInt: GuardBigInt = (value: bigint, callback?: ResultCallback): val isBigInt(value, callback); ``` -| Parameter | Type | Description | -| :-------- | :---------------------------------: | :---------- | +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :------------------------------- | | value | `bigint` | A `bigint` type `value` to guard | -| callback | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `bigint`. @@ -1222,10 +1222,10 @@ const guardBoolean: GuardBoolean = (value: boolean, callback?: ResultCallback): isBoolean(value, callback); ``` -| Parameter | Type | Description | -| :-------- | :---------------------------------: | :---------- | +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :-------------------------------- | | value | `boolean` | A `boolean` type `value` to guard | -| callback | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `boolean`. @@ -1236,12 +1236,14 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` Use `guardFunction()` or `guard.is.function()` to guard the `value` to be a [`Func`](#Func) type. ```typescript -const guardFunction: GuardFunction = (value: Func): value is Func => isFunction(value); +const guardFunction: GuardFunction = (value: Func, callback?: ResultCallback): value is Func => + isFunction(value, callback); ``` -| Parameter | Type | Description | -| :-------- | :-------------: | :---------------------------------- | -| value | [`Func`](#Func) | A [`Func`](#Func) type `value` to guard | +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :-------------------------------------- | +| value | [`Func`](#Func) | A [`Func`](#Func) type `value` to guard | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The return value is a `boolean` indicating whether or not the `value` is a [`Func`](#Func). @@ -1249,17 +1251,38 @@ The return value is a `boolean` indicating whether or not the `value` is a [`Fun ---- +### guardInstance + +Use `guardInstance()` or `guard.is.instance()` to guard the `value` to be an `object` of a generic `Obj` type equal to an `instance` of [`Constructor`](#Constructor) type. + +```typescript +const guardInstance: GuardInstance = (value: Obj, instance: Constructor, callback?: ResultCallback): value is Obj => + isInstance(value, instance, callback); +``` + +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :--------------------------------------------------- | +| value | `Obj` | An `Obj` type `value` to compare with the `instance` | +| instance | [`Constructor`](#Constructor) | A generic `Obj` [`Constructor`](#Constructor) type to create an `instance` to compare with the `value` | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is an `instance` of a generic `Obj`. + +---- + ### guardKey Use `guardKey()` or `guard.is.key()` to guard the `value` to be one of the `string`, `number`, or `symbol`. ```typescript -const guardKey: GuardKey = (value: Key): value is Key => isKey(value); +const guardKey: GuardKey = (value: Key, callback?: ResultCallback): value is Key => + isKey(value, callback); ``` -| Parameter | Type | Description | -| :-------- | :-----------: | :---------- | -| value | [`Key`](#Key) | A [`Key`](#Key) type `value` to guard | +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :------------------------------------ | +| value | [`Key`](#Key) | A [`Key`](#Key) type `value` to guard | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a [`Key`](#Key). @@ -1274,10 +1297,10 @@ const guardNull: GuardNull = (value: null, callback?: ResultCallback): value is isNull(value, callback); ``` -| Parameter | Type | Description | -| :-------- | :---------------------------------: | :---------- | +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :----------------------------- | | value | `null` | A `null` type `value` to guard | -| callback | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `null`. @@ -1288,12 +1311,14 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` Use `guardNumber()` or `guard.is.number()` to guard the `value` to be a `number`. ```typescript -const guardNumber: GuardNumber = (value: number): value is number => isNumber(value); +const guardNumber: GuardNumber = (value: number, callback?: ResultCallback): value is number => + isNumber(value, callback); ``` -| Parameter | Type | Description | -|-----------| :------: |--------------| -| value | `number` | A `number` type `value` to guard. | +| Parameter | Type | Description | +|---------- | :---------------------------------: | :-------------------------------- | +| value | `number` | A `number` type `value` to guard. | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `number`. @@ -1309,8 +1334,8 @@ Use `guardObject()` or `guard.is.object()` to guard the `value` to be an `object const guardObject: GuardObject = (value: Obj): value is Obj => isObject(value); ``` -| Parameter | Type | Description | -| :-------- | :--------------------: | :---------- | +| Parameter | Type | Description | +| :-------- | :--------------------: | :------------------------------------ | | value | `Obj` extends `object` | A generic `Obj` type `value` to guard | The **return value** is a `boolean` indicating whether or not the `value` is an `object` of a generic `Obj`. @@ -1328,10 +1353,10 @@ const guardObjectKey: GuardObjectKey = (value) ? isKey(key) ? key in value : true : false; ``` -| Parameter | Type | Description | -| :-----------| :-----------: | :------------ | -| value | `Obj` | A generic `Obj` type `value` that contains the `key` to guard | -| key | `Key` | A `Key` type name of the property that the `value` contains | +| Parameter | Type | Description | +| :---------- | :-----------: | :------------------------------------------------------------ | +| value | `Obj` | A generic `Obj` type `value` that contains the `key` to guard | +| key | `Key` | A `Key` type name of the property that the `value` contains | The **return value** is a `boolean` indicating whether or not the `value` is an `object` of a generic `Obj` containing the `Key`. @@ -1344,13 +1369,16 @@ The **return value** is a `boolean` indicating whether or not the `value` is an Use `guardPrimitive()` or `guard.is.primitive()` to guard the `value` to be the [`Primitive`](#Primitive) from a `type` of the [`Primitives`](#Primitives). ```typescript -const guardPrimitive: GuardPrimitive = (value: Type, type: Primitives): value is Type => isPrimitive(value, type); +const guardPrimitive: GuardPrimitive = + (value: Type, type: Primitives, callback?: ResultCallback): value is Type => + isPrimitive(value, type, callback); ``` -| Parameter | Type | Description | -| :---------- | :--------------------------------------: | :---------- | +| Parameter | Type | Description | +| :---------- | :--------------------------------------: | :---------------------------------- | | value | `Type` extends [`Primitive`](#Primitive) | A `Primitive` type `value` to guard | | type | [`Primitives`](#Primitives) | A `string` type from the [`Primitives`](#Primitives) to check the `value` | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The return value is a `boolean` indicating whether or not the `value` is the [`Primitive`](#Primitive) from the `type`. @@ -1363,12 +1391,14 @@ The return value is a `boolean` indicating whether or not the `value` is the [`P Use `guardString()` or `guard.is.string()` to guard the `value` to be a `string`. ```typescript -const guardString: GuardString = (value: string): value is string => isString(value); +const guardString: GuardString = (value: string, callback?: ResultCallback): value is string => + isString(value, callback); ``` -| Parameter | Type | Description | -|-------------| :------: |---------------| -| value | `string` | A `string` type `value` to guard | +| Parameter | Type | Description | +|-------------| :---------------------------------: | :------------------------------- | +| value | `string` | A `string` type `value` to guard | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The return value is a `boolean` indicating whether or not the `value` is a `string`. @@ -1385,10 +1415,10 @@ const guardSymbol: GuardSymbol = (value: symbol, callback?: ResultCallback): val isSymbol(value, callback); ``` -| Parameter | Type | Description | -| :-------- | :---------------------------------: | :---------- | +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :----------------------------- | | value | `null` | A `null` type `value` to guard | -| callback | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `symbol`. @@ -1399,13 +1429,15 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` Use `guardType()` or `guard.is.type()` to guard the `value` to be the [`Type`](#Type) from a `type` of the [`Types`](#Types). ```typescript -const guardType: GuardType = (value: T, type: Types): value is T => isType(value, type); +const guardType: GuardType = (value: T, type: Types, callback?: ResultCallback): value is T => + isType(value, type, callback); ``` -| Parameter | Type | Description | -| :-------- | :-------------------------: | :---------- | +| Parameter | Type | Description | +| :-------- | :-------------------------: | :------------------------------------------------- | | value | `T` extends [`Type`](#Type) | A [`Type`](#Type) `value` to guard with the `type` | | type | [`Types`](#Types) | A `string` or generic [`Constructor`](#Constructor) type from the [`Types`](#Types) to check the `value` | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The return value is a `boolean` indicating whether or not the `value` is a `type` from the [`Types`](#Types). @@ -1422,8 +1454,8 @@ const guardUndefined: GuardUndefined = (value: undefined, callback?: ResultCallb isUndefined(value, callback); ``` -| Parameter | Type | Description | -| :-------- | :---------------------------------: | :---------- | +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :---------------------------------- | | value | `undefined` | A `undefined` type `value` to guard | | callback | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | From becf857520c04908f9b4a820d0cc8052f423733a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 2 May 2021 23:33:09 +0200 Subject: [PATCH 176/201] refactor(isString): change the order of check by setting type as first --- packages/type/src/is/lib/is-string.func.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/is/lib/is-string.func.ts b/packages/type/src/is/lib/is-string.func.ts index 11454ca6..0b01886e 100644 --- a/packages/type/src/is/lib/is-string.func.ts +++ b/packages/type/src/is/lib/is-string.func.ts @@ -14,4 +14,4 @@ import { ResultCallback } from '../../type/result-callback.type'; * @returns A `boolean` indicating whether or not the `value` is a `string`. */ export const isString: IsString = (value: any, callback: ResultCallback = resultCallback): value is string => - callback(typeOf(value) === 'string' && (isStringObject(value) || isStringType(value))); + callback(typeOf(value) === 'string' && (isStringType(value) || isStringObject(value))); From 9b7672d190b4133b523d39b629d7b872e472e4da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 2 May 2021 23:41:26 +0200 Subject: [PATCH 177/201] feat: add features - `guardBigInt()` to guard the value to be a bigint - `guardBoolean()` to guard the value to be a boolean - `guardInstance()` to be an instance - `guardNull()` to guard the value to be a `null` - `guardSymbol()` to guard the value to be a `symbol` - `guardUndefined()` to guard the value to be `undefined` --- packages/type/src/guard/lib/guard-big-int.func.ts | 13 +++++++++++++ packages/type/src/guard/lib/guard-boolean.func.ts | 13 +++++++++++++ .../type/src/guard/lib/guard-instance.func.ts | 15 +++++++++++++++ packages/type/src/guard/lib/guard-null.func.ts | 13 +++++++++++++ packages/type/src/guard/lib/guard-symbol.func.ts | 14 ++++++++++++++ .../type/src/guard/lib/guard-undefined.func.ts | 13 +++++++++++++ .../type/src/guard/type/guard-big-int.type.ts | 2 ++ .../type/src/guard/type/guard-boolean.type.ts | 2 ++ .../type/src/guard/type/guard-instance.type.ts | 3 +++ packages/type/src/guard/type/guard-null.type.ts | 2 ++ packages/type/src/guard/type/guard-symbol.type.ts | 2 ++ .../type/src/guard/type/guard-undefined.type.ts | 2 ++ 12 files changed, 94 insertions(+) create mode 100644 packages/type/src/guard/lib/guard-big-int.func.ts create mode 100644 packages/type/src/guard/lib/guard-boolean.func.ts create mode 100644 packages/type/src/guard/lib/guard-instance.func.ts create mode 100644 packages/type/src/guard/lib/guard-null.func.ts create mode 100644 packages/type/src/guard/lib/guard-symbol.func.ts create mode 100644 packages/type/src/guard/lib/guard-undefined.func.ts create mode 100644 packages/type/src/guard/type/guard-big-int.type.ts create mode 100644 packages/type/src/guard/type/guard-boolean.type.ts create mode 100644 packages/type/src/guard/type/guard-instance.type.ts create mode 100644 packages/type/src/guard/type/guard-null.type.ts create mode 100644 packages/type/src/guard/type/guard-symbol.type.ts create mode 100644 packages/type/src/guard/type/guard-undefined.type.ts diff --git a/packages/type/src/guard/lib/guard-big-int.func.ts b/packages/type/src/guard/lib/guard-big-int.func.ts new file mode 100644 index 00000000..a65dad13 --- /dev/null +++ b/packages/type/src/guard/lib/guard-big-int.func.ts @@ -0,0 +1,13 @@ +// Function. +import { isBigInt } from '../../is/lib/is-big-int.func'; +// Type. +import { GuardBigInt } from '../type/guard-big-int.type'; +import { ResultCallback } from '../../type/result-callback.type'; +/** + * Guard the `value` to be a `bigint`. + * @param value A `bigint` type `value` to guard. + * @param callback Optional `ResultCallback` function to handle result before returns. + * @returns A `boolean` indicating whether or not the `value` is a `bigint`. + */ +export const guardBigInt: GuardBigInt = (value: bigint, callback?: ResultCallback): value is bigint => + isBigInt(value, callback); diff --git a/packages/type/src/guard/lib/guard-boolean.func.ts b/packages/type/src/guard/lib/guard-boolean.func.ts new file mode 100644 index 00000000..45cd759a --- /dev/null +++ b/packages/type/src/guard/lib/guard-boolean.func.ts @@ -0,0 +1,13 @@ +// Function. +import { isBoolean } from '../../is/lib/is-boolean.func'; +// Type. +import { GuardBoolean } from '../type/guard-boolean.type'; +import { ResultCallback } from '../../type/result-callback.type'; +/** + * Guard the `value` to be a `boolean`. + * @param value A `boolean` type `value` to guard. + * @param callback Optional `ResultCallback` function to handle result before returns. + * @returns A `boolean` indicating whether or not the `value` is a `boolean`. + */ +export const guardBoolean: GuardBoolean = (value: boolean, callback?: ResultCallback): value is boolean => + isBoolean(value, callback); diff --git a/packages/type/src/guard/lib/guard-instance.func.ts b/packages/type/src/guard/lib/guard-instance.func.ts new file mode 100644 index 00000000..14169c5b --- /dev/null +++ b/packages/type/src/guard/lib/guard-instance.func.ts @@ -0,0 +1,15 @@ +// Function. +import { isInstance } from '../../is/lib/is-instance.func'; +// Type. +import { Constructor } from '../../type/constructor.type'; +import { GuardInstance } from '../type/guard-instance.type'; +import { ResultCallback } from '../../type/result-callback.type'; +/** + * Guard the `value` to guard the `value` to be an `object` of a generic `Obj` type equal to an `instance`. + * @param value An `Obj` type `value` to compare with the `instance`. + * @param instance A generic `Obj` `Constructor` type to create an `instance` to compare with the `value`. + * @param callback Optional `ResultCallback` function to handle result before returns. + * @returns A `boolean` indicating whether or not the `value` is a `symbol`. + */ +export const guardInstance: GuardInstance = (value: Obj, instance: Constructor, callback?: ResultCallback): value is Obj => + isInstance(value, instance, callback); diff --git a/packages/type/src/guard/lib/guard-null.func.ts b/packages/type/src/guard/lib/guard-null.func.ts new file mode 100644 index 00000000..3d8cf171 --- /dev/null +++ b/packages/type/src/guard/lib/guard-null.func.ts @@ -0,0 +1,13 @@ +// Function. +import { isNull } from '../../is/lib/is-null.func'; +// Type. +import { GuardNull } from '../type/guard-null.type'; +import { ResultCallback } from '../../type/result-callback.type'; +/** + * Guard the `value` to be a `null`. + * @param value A `null` type `value` to guard. + * @param callback Optional `ResultCallback` function to handle result before returns. + * @returns A `boolean` indicating whether or not the `value` is a `null`. + */ +export const guardNull: GuardNull = (value: null, callback?: ResultCallback): value is null => + isNull(value, callback); diff --git a/packages/type/src/guard/lib/guard-symbol.func.ts b/packages/type/src/guard/lib/guard-symbol.func.ts new file mode 100644 index 00000000..17eb6ddc --- /dev/null +++ b/packages/type/src/guard/lib/guard-symbol.func.ts @@ -0,0 +1,14 @@ +// Function. +import { isSymbol } from '../../is/lib/is-symbol.func'; +import { resultCallback } from '../../lib/result-callback.func'; +// Type. +import { GuardSymbol } from '../type/guard-symbol.type'; +import { ResultCallback } from '../../type/result-callback.type'; +/** + * Guard the `value` to be a `symbol`. + * @param value A `symbol` type `value` to guard. + * @param callback Optional `ResultCallback` function to handle result before returns. + * @returns A `boolean` indicating whether or not the `value` is a `symbol`. + */ +export const guardSymbol: GuardSymbol = (value: symbol, callback?: ResultCallback): value is symbol => + isSymbol(value, callback); diff --git a/packages/type/src/guard/lib/guard-undefined.func.ts b/packages/type/src/guard/lib/guard-undefined.func.ts new file mode 100644 index 00000000..6c452401 --- /dev/null +++ b/packages/type/src/guard/lib/guard-undefined.func.ts @@ -0,0 +1,13 @@ +// Function. +import { isUndefined } from '../../is/lib/is-undefined.func'; +// Type. +import { GuardUndefined } from '../type/guard-undefined.type'; +import { ResultCallback } from '../../type/result-callback.type'; +/** + * Guard the `value` to be `undefined`. + * @param value A `undefined` type `value` to guard. + * @param callback Optional `ResultCallback` function to handle result before returns. + * @returns A `boolean` indicating whether or not the `value` is `undefined`. + */ +export const guardUndefined: GuardUndefined = (value: undefined, callback?: ResultCallback): value is undefined => + isUndefined(value, callback); diff --git a/packages/type/src/guard/type/guard-big-int.type.ts b/packages/type/src/guard/type/guard-big-int.type.ts new file mode 100644 index 00000000..25f520e3 --- /dev/null +++ b/packages/type/src/guard/type/guard-big-int.type.ts @@ -0,0 +1,2 @@ +import { ResultCallback } from '../../type/result-callback.type'; +export type GuardBigInt = (value: bigint, callback?: ResultCallback) => value is bigint; diff --git a/packages/type/src/guard/type/guard-boolean.type.ts b/packages/type/src/guard/type/guard-boolean.type.ts new file mode 100644 index 00000000..d9fb88c4 --- /dev/null +++ b/packages/type/src/guard/type/guard-boolean.type.ts @@ -0,0 +1,2 @@ +import { ResultCallback } from '../../type/result-callback.type'; +export type GuardBoolean = (value: boolean, callback?: ResultCallback) => value is boolean; diff --git a/packages/type/src/guard/type/guard-instance.type.ts b/packages/type/src/guard/type/guard-instance.type.ts new file mode 100644 index 00000000..22911fcf --- /dev/null +++ b/packages/type/src/guard/type/guard-instance.type.ts @@ -0,0 +1,3 @@ +import { Constructor } from '../../type/constructor.type'; +import { ResultCallback } from '../../type/result-callback.type'; +export type GuardInstance = (value: Obj, instance: Constructor, callback?: ResultCallback) => value is Obj; diff --git a/packages/type/src/guard/type/guard-null.type.ts b/packages/type/src/guard/type/guard-null.type.ts new file mode 100644 index 00000000..75643565 --- /dev/null +++ b/packages/type/src/guard/type/guard-null.type.ts @@ -0,0 +1,2 @@ +import { ResultCallback } from '../../type/result-callback.type'; +export type GuardNull = (value: null, callback?: ResultCallback) => value is null; diff --git a/packages/type/src/guard/type/guard-symbol.type.ts b/packages/type/src/guard/type/guard-symbol.type.ts new file mode 100644 index 00000000..8cd97295 --- /dev/null +++ b/packages/type/src/guard/type/guard-symbol.type.ts @@ -0,0 +1,2 @@ +import { ResultCallback } from '../../type/result-callback.type'; +export type GuardSymbol = (value: symbol, callback?: ResultCallback) => value is symbol; diff --git a/packages/type/src/guard/type/guard-undefined.type.ts b/packages/type/src/guard/type/guard-undefined.type.ts new file mode 100644 index 00000000..875793e2 --- /dev/null +++ b/packages/type/src/guard/type/guard-undefined.type.ts @@ -0,0 +1,2 @@ +import { ResultCallback } from '../../type/result-callback.type'; +export type GuardUndefined = (value: undefined, callback?: ResultCallback) => value is undefined; From 54a56e4fc5c67c91199671e7210e1c6692e86a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 2 May 2021 23:43:20 +0200 Subject: [PATCH 178/201] chore: add feature to exports --- packages/type/src/guard/index.ts | 12 ++++++++++-- packages/type/src/public-api.ts | 9 ++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/type/src/guard/index.ts b/packages/type/src/guard/index.ts index 9b2b827d..e3bd41a8 100644 --- a/packages/type/src/guard/index.ts +++ b/packages/type/src/guard/index.ts @@ -1,10 +1,18 @@ +// `guard` object. export { guard } from './lib/guard.object'; - +// `guard` prefix functions, export { guardArray } from './lib/guard-array.func'; +export { guardBigInt } from './lib/guard-big-int.func'; +export { guardBoolean } from './lib/guard-boolean.func'; export { guardFunction } from './lib/guard-function.func'; +export { guardInstance } from './lib/guard-instance.func'; +export { guardKey } from './lib/guard-key.func'; export { guardNumber } from './lib/guard-number.func'; -export { guardObjectKey } from './lib/guard-object-key.func'; +export { guardNull } from './lib/guard-null.func'; export { guardObject } from './lib/guard-object.func'; +export { guardObjectKey } from './lib/guard-object-key.func'; export { guardPrimitive } from './lib/guard-primitive.func'; export { guardString } from './lib/guard-string.func'; +export { guardSymbol } from './lib/guard-symbol.func'; export { guardType } from './lib/guard-type.func'; +export { guardUndefined } from './lib/guard-undefined.func'; diff --git a/packages/type/src/public-api.ts b/packages/type/src/public-api.ts index 5fa72627..65c6856b 100644 --- a/packages/type/src/public-api.ts +++ b/packages/type/src/public-api.ts @@ -8,13 +8,20 @@ export { guard } from './guard'; // `guard` functions. export { guardArray, + guardBigInt, + guardBoolean, guardFunction, + guardInstance, + guardKey, + guardNull, guardNumber, guardObject, guardObjectKey, guardPrimitive, guardString, - guardType + guardSymbol, + guardType, + guardUndefined } from './guard'; // `are` object and functions. From 1fa3645a06be8e48f6e76616a7d83ec2a9fa1cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 2 May 2021 23:44:26 +0200 Subject: [PATCH 179/201] refactor: add `callback` to guard function types --- packages/type/src/guard/type/guard-array.type.ts | 3 ++- packages/type/src/guard/type/guard-function.type.ts | 3 ++- packages/type/src/guard/type/guard-key.type.ts | 3 ++- packages/type/src/guard/type/guard-number.type.ts | 3 ++- packages/type/src/guard/type/guard-object.type.ts | 3 ++- packages/type/src/guard/type/guard-primitive.type.ts | 3 ++- packages/type/src/guard/type/guard-string.type.ts | 3 ++- packages/type/src/guard/type/guard-type.type.ts | 3 ++- 8 files changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/type/src/guard/type/guard-array.type.ts b/packages/type/src/guard/type/guard-array.type.ts index 6e4613f9..9599fb30 100644 --- a/packages/type/src/guard/type/guard-array.type.ts +++ b/packages/type/src/guard/type/guard-array.type.ts @@ -1 +1,2 @@ -export type GuardArray = (value: Array) => value is Array; +import { ResultCallback } from '../../type/result-callback.type'; +export type GuardArray = (value: Array, callback?: ResultCallback) => value is Array; diff --git a/packages/type/src/guard/type/guard-function.type.ts b/packages/type/src/guard/type/guard-function.type.ts index 6a37aa45..82f6b8c0 100644 --- a/packages/type/src/guard/type/guard-function.type.ts +++ b/packages/type/src/guard/type/guard-function.type.ts @@ -1,2 +1,3 @@ import { Func } from '../../type/func.type'; -export type GuardFunction = (value: Func) => value is Func; +import { ResultCallback } from '../../type/result-callback.type'; +export type GuardFunction = (value: Func, callback?: ResultCallback) => value is Func; diff --git a/packages/type/src/guard/type/guard-key.type.ts b/packages/type/src/guard/type/guard-key.type.ts index 3bb94bfe..274cb19f 100644 --- a/packages/type/src/guard/type/guard-key.type.ts +++ b/packages/type/src/guard/type/guard-key.type.ts @@ -1,2 +1,3 @@ import { Key } from '../../type/key.type'; -export type GuardKey = (value: Key) => boolean; +import { ResultCallback } from '../../type/result-callback.type'; +export type GuardKey = (value: Key, callback?: ResultCallback) => boolean; diff --git a/packages/type/src/guard/type/guard-number.type.ts b/packages/type/src/guard/type/guard-number.type.ts index 2ebe8a2f..6ab2e6ba 100644 --- a/packages/type/src/guard/type/guard-number.type.ts +++ b/packages/type/src/guard/type/guard-number.type.ts @@ -1 +1,2 @@ -export type GuardNumber = (value: number) => value is number; +import { ResultCallback } from '../../type/result-callback.type'; +export type GuardNumber = (value: number, callback?: ResultCallback) => value is number; diff --git a/packages/type/src/guard/type/guard-object.type.ts b/packages/type/src/guard/type/guard-object.type.ts index 1139e329..761a5e83 100644 --- a/packages/type/src/guard/type/guard-object.type.ts +++ b/packages/type/src/guard/type/guard-object.type.ts @@ -1 +1,2 @@ -export type GuardObject = (value: Obj) => value is Obj; +import { ResultCallback } from '../../type/result-callback.type'; +export type GuardObject = (value: Obj, callback?: ResultCallback) => value is Obj; diff --git a/packages/type/src/guard/type/guard-primitive.type.ts b/packages/type/src/guard/type/guard-primitive.type.ts index ffcff5b4..fc0a2467 100644 --- a/packages/type/src/guard/type/guard-primitive.type.ts +++ b/packages/type/src/guard/type/guard-primitive.type.ts @@ -1,3 +1,4 @@ import { Primitive } from '../../type/primitive.type'; import { Primitives } from '../../type/primitives.type'; -export type GuardPrimitive = (value: T, type: Primitives) => value is T; +import { ResultCallback } from '../../type/result-callback.type'; +export type GuardPrimitive = (value: T, type: Primitives, callback?: ResultCallback) => value is T; diff --git a/packages/type/src/guard/type/guard-string.type.ts b/packages/type/src/guard/type/guard-string.type.ts index 6f752b53..250702f4 100644 --- a/packages/type/src/guard/type/guard-string.type.ts +++ b/packages/type/src/guard/type/guard-string.type.ts @@ -1 +1,2 @@ -export type GuardString = (value: string) => value is string; +import { ResultCallback } from '../../type/result-callback.type'; +export type GuardString = (value: string, callback?: ResultCallback) => value is string; diff --git a/packages/type/src/guard/type/guard-type.type.ts b/packages/type/src/guard/type/guard-type.type.ts index 2b74f63d..6563c07a 100644 --- a/packages/type/src/guard/type/guard-type.type.ts +++ b/packages/type/src/guard/type/guard-type.type.ts @@ -1,3 +1,4 @@ +import { ResultCallback } from '../../type/result-callback.type'; import { Types } from '../../type/types.type'; import { Type } from '../../type/type.type'; -export type GuardType = (value: T, type: Types) => value is T; +export type GuardType = (value: T, type: Types, callback?: ResultCallback) => value is T; From 42f35343c78a91edd0906604a9a6065ffc0b21f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 2 May 2021 23:45:33 +0200 Subject: [PATCH 180/201] refactor: add `callback` to guard functions --- .../type/src/guard/lib/guard-array.func.ts | 5 ++++- .../type/src/guard/lib/guard-function.func.ts | 5 ++++- .../type/src/guard/lib/guard-is.object.ts | 21 ++++++++++++++----- packages/type/src/guard/lib/guard-key.func.ts | 5 ++++- .../type/src/guard/lib/guard-number.func.ts | 5 ++++- .../type/src/guard/lib/guard-object.func.ts | 5 ++++- .../src/guard/lib/guard-primitive.func.ts | 5 ++++- .../type/src/guard/lib/guard-string.func.ts | 5 ++++- .../type/src/guard/lib/guard-type.func.ts | 5 ++++- 9 files changed, 48 insertions(+), 13 deletions(-) diff --git a/packages/type/src/guard/lib/guard-array.func.ts b/packages/type/src/guard/lib/guard-array.func.ts index beda4de3..56f392ef 100644 --- a/packages/type/src/guard/lib/guard-array.func.ts +++ b/packages/type/src/guard/lib/guard-array.func.ts @@ -2,9 +2,12 @@ import { isArray } from '../../is/lib/is-array.func'; // Type. import { GuardArray } from '../type/guard-array.type'; +import { ResultCallback } from '../../type/result-callback.type'; /** * Guard the `value` to be an `Array` of a generic `Type`. * @param value A generic `Type` `Array` `value` to guard. + * @param callback Optional `ResultCallback` function to handle result before returns. * @returns A `boolean` indicating whether or not the `value` is an `Array` of a generic `Type`. */ -export const guardArray: GuardArray = (value: Array): value is Array => isArray(value); +export const guardArray: GuardArray = (value: Array, callback?: ResultCallback): value is Array => + isArray(value, callback); diff --git a/packages/type/src/guard/lib/guard-function.func.ts b/packages/type/src/guard/lib/guard-function.func.ts index 85af962e..e99c26e1 100644 --- a/packages/type/src/guard/lib/guard-function.func.ts +++ b/packages/type/src/guard/lib/guard-function.func.ts @@ -3,9 +3,12 @@ import { isFunction } from '../../is/lib/is-function.func'; // Type. import { GuardFunction } from '../type/guard-function.type'; import { Func } from '../../type/func.type'; +import { ResultCallback } from '../../type/result-callback.type'; /** * Guard the `value` to be a `Func` type. * @param value A `Func` type `value` to guard. + * @param callback Optional `ResultCallback` function to handle result before returns. * @returns A `boolean` indicating whether or not the `value` is a `Func`. */ -export const guardFunction: GuardFunction = (value: Func): value is Func => isFunction(value); +export const guardFunction: GuardFunction = (value: Func, callback?: ResultCallback): value is Func => + isFunction(value, callback); diff --git a/packages/type/src/guard/lib/guard-is.object.ts b/packages/type/src/guard/lib/guard-is.object.ts index b0a53672..ecfec87a 100644 --- a/packages/type/src/guard/lib/guard-is.object.ts +++ b/packages/type/src/guard/lib/guard-is.object.ts @@ -1,25 +1,36 @@ // Function. import { guardArray } from './guard-array.func'; +import { guardBigInt } from './guard-big-int.func'; +import { guardBoolean } from './guard-boolean.func'; import { guardFunction } from './guard-function.func'; +import { guardInstance } from './guard-instance.func'; +import { guardKey } from './guard-key.func'; +import { guardNull } from './guard-null.func'; import { guardNumber } from './guard-number.func'; import { guardObject } from './guard-object.func'; import { guardObjectKey } from './guard-object-key.func'; import { guardPrimitive } from './guard-primitive.func'; import { guardString } from './guard-string.func'; +import { guardSymbol } from './guard-symbol.func'; import { guardType } from './guard-type.func'; -import { guardKey } from './guard-key.func'; +import { guardUndefined } from './guard-undefined.func'; // Interface. import { GuardIs } from '../interface/guard-is.interface'; -// Object. +// `guardIs`. export const guardIs: GuardIs = { - // TODO: add other guards etc. boolean, null, undefined array: guardArray, + bigint: guardBigInt, + boolean: guardBoolean, function: guardFunction, + instance: guardInstance, key: guardKey, number: guardNumber, - objectKey: guardObjectKey, + null: guardNull, object: guardObject, + objectKey: guardObjectKey, primitive: guardPrimitive, string: guardString, - type: guardType + symbol: guardSymbol, + type: guardType, + undefined: guardUndefined }; diff --git a/packages/type/src/guard/lib/guard-key.func.ts b/packages/type/src/guard/lib/guard-key.func.ts index 9663cf31..c68e5930 100644 --- a/packages/type/src/guard/lib/guard-key.func.ts +++ b/packages/type/src/guard/lib/guard-key.func.ts @@ -3,9 +3,12 @@ import { isKey } from '../../is/lib/is-key.func'; // Type. import { GuardKey } from '../type/guard-key.type'; import { Key } from '../../type/key.type'; +import { ResultCallback } from '../../type/result-callback.type'; /** * Guard the `value` to be one of the `string`, `number`, or `symbol`. * @param value A `Key` type `value` to guard. + * @param callback Optional `ResultCallback` function to handle result before returns. * @returns A `boolean` indicating whether or not the `value` is a `Key`. */ -export const guardKey: GuardKey = (value: Key): value is Key => isKey(value); +export const guardKey: GuardKey = (value: Key, callback?: ResultCallback): value is Key => + isKey(value, callback); diff --git a/packages/type/src/guard/lib/guard-number.func.ts b/packages/type/src/guard/lib/guard-number.func.ts index fb53e6d3..9747e88b 100644 --- a/packages/type/src/guard/lib/guard-number.func.ts +++ b/packages/type/src/guard/lib/guard-number.func.ts @@ -2,9 +2,12 @@ import { isNumber } from '../../is/lib/is-number.func'; // Type. import { GuardNumber } from '../type/guard-number.type'; +import { ResultCallback } from '../../type/result-callback.type'; /** * Guard the `value` to be a `number`. * @param value A `number` type `value` to guard. + * @param callback Optional `ResultCallback` function to handle result before returns. * @returns A `boolean` indicating whether or not the `value` is a `number`. */ -export const guardNumber: GuardNumber = (value: number): value is number => isNumber(value); +export const guardNumber: GuardNumber = (value: number, callback?: ResultCallback): value is number => + isNumber(value, callback); diff --git a/packages/type/src/guard/lib/guard-object.func.ts b/packages/type/src/guard/lib/guard-object.func.ts index 0fe3a2fd..7614cb20 100644 --- a/packages/type/src/guard/lib/guard-object.func.ts +++ b/packages/type/src/guard/lib/guard-object.func.ts @@ -2,9 +2,12 @@ import { isObject } from '../../is/lib/is-object.func'; // Type. import { GuardObject } from '../type/guard-object.type'; +import { ResultCallback } from '../../type/result-callback.type'; /** * Guard the `value` to be an `object` of a generic `Obj` type. * @param value A generic `Obj` type `value` to guard. + * @param callback Optional `ResultCallback` function to handle result before returns. * @returns A `boolean` indicating whether or not the `value` is an `object` of a generic `Obj`. */ -export const guardObject: GuardObject = (value: Obj): value is Obj => isObject(value); +export const guardObject: GuardObject = (value: Obj, callback?: ResultCallback): value is Obj => + isObject(value); diff --git a/packages/type/src/guard/lib/guard-primitive.func.ts b/packages/type/src/guard/lib/guard-primitive.func.ts index 94ba710e..9d3fbc7f 100644 --- a/packages/type/src/guard/lib/guard-primitive.func.ts +++ b/packages/type/src/guard/lib/guard-primitive.func.ts @@ -4,11 +4,14 @@ import { isPrimitive } from '../../is/lib/is-primitive.func'; import { GuardPrimitive } from '../type/guard-primitive.type'; import { Primitive } from '../../type/primitive.type'; import { Primitives } from '../../type/primitives.type'; +import { ResultCallback } from '../../type/result-callback.type'; /** * Guard the `value` to be the `Primitive` from a `type` of the `Primitives`. * @param value A `Primitive` type `value` to guard. * @param type A `string` type from the `Primitives` to check the `value`. + * @param callback Optional `ResultCallback` function to handle result before returns. * @returns A `boolean` indicating whether or not the `value` is the `Primitive` from the `type`. */ export const guardPrimitive: GuardPrimitive = - (value: Type, type: Primitives): value is Type => isPrimitive(value, type); + (value: Type, type: Primitives, callback?: ResultCallback): value is Type => + isPrimitive(value, type, callback); diff --git a/packages/type/src/guard/lib/guard-string.func.ts b/packages/type/src/guard/lib/guard-string.func.ts index 14e8fd56..03e930ff 100644 --- a/packages/type/src/guard/lib/guard-string.func.ts +++ b/packages/type/src/guard/lib/guard-string.func.ts @@ -2,9 +2,12 @@ import { isString } from '../../is/lib/is-string.func'; // Type. import { GuardString } from '../type/guard-string.type'; +import { ResultCallback } from '../../type/result-callback.type'; /** * Guard the `value` to be a `string`. * @param value A `string` type `value` to guard. + * @param callback Optional `ResultCallback` function to handle result before returns. * @returns A `boolean` indicating whether or not the `value` is a `string`. */ -export const guardString: GuardString = (value: string): value is string => isString(value); +export const guardString: GuardString = (value: string, callback?: ResultCallback): value is string => + isString(value, callback); diff --git a/packages/type/src/guard/lib/guard-type.func.ts b/packages/type/src/guard/lib/guard-type.func.ts index 4c6d60b8..d6180297 100644 --- a/packages/type/src/guard/lib/guard-type.func.ts +++ b/packages/type/src/guard/lib/guard-type.func.ts @@ -2,12 +2,15 @@ import { isType } from '../../is/lib/is-type.func'; // Type. import { GuardType } from '../type/guard-type.type'; +import { ResultCallback } from '../../type/result-callback.type'; import { Type } from '../../type/type.type'; import { Types } from '../../type/types.type'; /** * Guard the `value` to be the `Type` from a `type` of the `Types`. * @param value A `Type` `value` to guard with the `type`. * @param type A `string` or generic `Constructor` type from the `Types` to check the `value`. + * @param callback Optional `ResultCallback` function to handle result before returns. * @returns A `boolean` indicating whether or not the `value` is a type from the `Types`. */ -export const guardType: GuardType = (value: T, type: Types): value is T => isType(value, type); +export const guardType: GuardType = (value: T, type: Types, callback?: ResultCallback): value is T => + isType(value, type, callback); From 433c44f8e33979315758ea5cb02dbeb4dce526c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 2 May 2021 23:46:52 +0200 Subject: [PATCH 181/201] chore: categorize and sort imports --- packages/type/src/guard/lib/guard.object.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/type/src/guard/lib/guard.object.ts b/packages/type/src/guard/lib/guard.object.ts index da7697c9..2bf7dc5a 100644 --- a/packages/type/src/guard/lib/guard.object.ts +++ b/packages/type/src/guard/lib/guard.object.ts @@ -1,6 +1,8 @@ -import { Guard } from '../interface/guard-interface'; +// Object. import { guardIs } from './guard-is.object'; - +// Interface. +import { Guard } from '../interface/guard-interface'; +// `guard` export const guard: Guard = { is: guardIs }; From fe30bc045af5f7c9dc4ea68fabffe96db84f8f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 2 May 2021 23:47:07 +0200 Subject: [PATCH 182/201] refactor(GuardIs): add features to interface --- .../src/guard/interface/guard-is.interface.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/type/src/guard/interface/guard-is.interface.ts b/packages/type/src/guard/interface/guard-is.interface.ts index 96ee125f..e897c4e2 100644 --- a/packages/type/src/guard/interface/guard-is.interface.ts +++ b/packages/type/src/guard/interface/guard-is.interface.ts @@ -1,24 +1,33 @@ - import { GuardArray } from '../type/guard-array.type'; +import { GuardBigInt } from '../type/guard-big-int.type'; +import { GuardBoolean } from '../type/guard-boolean.type'; import { GuardFunction } from '../type/guard-function.type'; +import { GuardKey } from '../type/guard-key.type'; import { GuardNumber } from '../type/guard-number.type'; +import { GuardObject } from '../type/guard-object.type'; import { GuardObjectKey } from '../type/guard-object-key.type'; import { GuardPrimitive } from '../type/guard-primitive.type'; import { GuardString } from '../type/guard-string.type'; import { GuardType } from '../type/guard-type.type'; -import { GuardObject } from '../type/guard-object.type'; -import { GuardKey } from '../type/guard-key.type'; +import { GuardInstance } from '../type/guard-instance.type'; +import { GuardNull } from '../type/guard-null.type'; +import { GuardSymbol } from '../type/guard-symbol.type'; +import { GuardUndefined } from '../type/guard-undefined.type'; export interface GuardIs { array: GuardArray; + bigint: GuardBigInt; + boolean: GuardBoolean; function: GuardFunction; + instance: GuardInstance; key: GuardKey; - // TODO: Guard not - // not: GuardNotIs; + null: GuardNull; number: GuardNumber; object: GuardObject; objectKey: GuardObjectKey; primitive: GuardPrimitive; string: GuardString; + symbol: GuardSymbol; type: GuardType; + undefined: GuardUndefined; } From cf3d95e093d9f4cd8807c5951bde389ca7501768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Sun, 2 May 2021 23:47:31 +0200 Subject: [PATCH 183/201] test: add guardBigInt and `guard` object tests --- .../type/src/guard/test/guard-bigint.spec.ts | 86 +++++++++++++++++++ packages/type/src/guard/test/guard.spec.ts | 21 +++++ 2 files changed, 107 insertions(+) create mode 100644 packages/type/src/guard/test/guard-bigint.spec.ts create mode 100644 packages/type/src/guard/test/guard.spec.ts diff --git a/packages/type/src/guard/test/guard-bigint.spec.ts b/packages/type/src/guard/test/guard-bigint.spec.ts new file mode 100644 index 00000000..782cb3d9 --- /dev/null +++ b/packages/type/src/guard/test/guard-bigint.spec.ts @@ -0,0 +1,86 @@ +// Function. +import { guardBigInt } from '../lib/guard-big-int.func'; +// Variables. +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from '../../is/test/variables/big-int.const'; +import { Class, CLASS } from '../../is/test/variables/class.const'; +import { FUNCTION } from '../../is/test/variables/function.const'; +import { NULL } from '../../is/test/variables/null.const'; +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from '../../is/test/variables/number.const'; +import { OBJECT_ONE, OBJECT_TWO, OBJECT_ONE_NEW, OBJECT_TWO_NEW } from '../../is/test/variables/object.const'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from '../../is/test/variables/string.const'; +import { SYMBOL_NUMBER, SYMBOL_STRING } from '../../is/test/variables/symbol.const'; +import { TRUE, FALSE, FALSE_EXPECTATION, TRUE_EXPECTATION, TRUE_INSTANCE, FALSE_INSTANCE } from '../../is/test/variables/boolean.const'; +import { UNDEFINED } from '../../is/test/variables/undefined.const'; + +describe(`guardBigInt`, () => { + // Defined. + it('is DEFINED', () => expect(guardBigInt).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + it('callback', () => { + guardBigInt(STRING, (result: boolean) => { + expect(result).toBe(TRUE); + return result; + }); + }); + + // ... arrays. + describe(`array`, () => { + // it(`${FUNCTION}`, () => expect(guardBigInt(FUNCTION, 'function')).toBe(FALSE)); + // it(`${Class}`, () => expect(guardBigInt(Class, 'function')).toBe(FALSE)); + }); + // ... function. + describe(`function`, () => { + it(`FUNCTION`, () => expect(guardBigInt(FUNCTION)).toBe(FALSE)); + it(`Class`, () => expect(guardBigInt(Class)).toBe(FALSE)); + }); + // ... objects. + describe('object', () => { + it(`CLASS`, () => expect(guardBigInt(CLASS)).toBe(FALSE)); + it(`OBJECT_ONE`, () => expect(guardBigInt(OBJECT_ONE)).toBe(FALSE)); + it(`OBJECT_TWO`, () => expect(guardBigInt(OBJECT_TWO)).toBe(FALSE)); + it(`new Object(OBJECT_ONE_NEW})`, () => expect(guardBigInt(OBJECT_ONE_NEW)).toBe(FALSE)); + it(`new Object(OBJECT_TWO_NEW})`, () => expect(guardBigInt(OBJECT_TWO_NEW)).toBe(FALSE)); + }); + // ... primitives. + describe(`primitive`, () => { + // bigint + describe(`bigint`, () => { + it(`${BIGINT}`, () => expect(guardBigInt(BIGINT)).toBe(FALSE)); + it(`${BIGINT_EXPECTATION}`, () => expect(guardBigInt(BIGINT_INSTANCE)).toBe(FALSE)); + }); + + // boolean + describe(`boolean`, () => { + it(`${TRUE}`, () => expect(guardBigInt(TRUE)).toBe(FALSE)); + it(`${FALSE}`, () => expect(guardBigInt(FALSE)).toBe(FALSE)); + it(`${FALSE_EXPECTATION}`, () => expect(guardBigInt(TRUE_INSTANCE)).toBe(FALSE)); + it(`${TRUE_EXPECTATION}`, () => expect(guardBigInt(FALSE_INSTANCE)).toBe(FALSE)); + }); + + // null + it(`${NULL}`, () => expect(guardBigInt(NULL)).toBe(FALSE)); + + // number + describe(`number`, () => { + it(`${NUMBER}`, () => expect(guardBigInt(NUMBER)).toBe(FALSE)); + it(`Number(${NUMBER})`, () => expect(guardBigInt(NUMBER_INSTANCE)).toBe(FALSE)); + it(`new Number(${NUMBER})`, () => expect(guardBigInt(NUMBER_NEW_INSTANCE)).toBe(FALSE)); + }); + // string + describe(`string`, () => { + it(`${STRING}`, () => expect(guardBigInt(STRING)).toBe(TRUE)); + it(`String(${STRING})`, () => expect(guardBigInt(STRING_INSTANCE)).toBe(TRUE)); + it(`new String(${STRING})`, () => expect(guardBigInt(STRING_NEW_INSTANCE)).toBe(TRUE)); + }); + // symbol + describe(`symbol`, () => { + it(`Symbol(${NUMBER})`, () => expect(guardBigInt(SYMBOL_NUMBER)).toBe(FALSE)); + it(`Symbol(${STRING})`, () => expect(guardBigInt(SYMBOL_STRING)).toBe(FALSE)); + }); + // undefined + it(`${UNDEFINED}`, () => expect(guardBigInt(UNDEFINED)).toBe(FALSE)); + }); + }); +}); diff --git a/packages/type/src/guard/test/guard.spec.ts b/packages/type/src/guard/test/guard.spec.ts new file mode 100644 index 00000000..d2d5f165 --- /dev/null +++ b/packages/type/src/guard/test/guard.spec.ts @@ -0,0 +1,21 @@ +import { guard } from '../lib/guard.object'; + +describe('`guard`', () => { + describe('DEFINED', () => { + it('guard', () => expect(guard).toBeDefined()); + it('guard.is.array()', () => expect(guard.is.array).toBeDefined()); + it('guard,is.boolean()', () => expect(guard.is.boolean).toBeDefined()); + it('guard,is.function()', () => expect(guard.is.function).toBeDefined()); + it('guard,is.instance()', () => expect(guard.is.instance).toBeDefined()); + it('guard,is.key()', () => expect(guard.is.key).toBeDefined()); + it('guard,is.null()', () => expect(guard.is.null).toBeDefined()); + it('guard,is.number()', () => expect(guard.is.number).toBeDefined()); + it('guard,is.object()', () => expect(guard.is.object).toBeDefined()); + it('guard,is.objectKey()', () => expect(guard.is.objectKey).toBeDefined()); + it('guard,is.primitive()', () => expect(guard.is.primitive).toBeDefined()); + it('guard,is.string()', () => expect(guard.is.string).toBeDefined()); + it('guard,is.symbol()', () => expect(guard.is.symbol).toBeDefined()); + it('guard,is.type()', () => expect(guard.is.type).toBeDefined()); + it('guard,is.undefined()', () => expect(guard.is.undefined).toBeDefined()); + }); +}); From 4ab26c7e18042e34cbff4e1282bfd6ef9e5440fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 3 May 2021 18:38:50 +0200 Subject: [PATCH 184/201] feat(isParam): experimental decorator --- .../type/src/is/lib/is-param.decorator.ts | 40 ++++++++++ packages/type/src/is/test/is-param.spec.ts | 78 +++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 packages/type/src/is/lib/is-param.decorator.ts create mode 100644 packages/type/src/is/test/is-param.spec.ts diff --git a/packages/type/src/is/lib/is-param.decorator.ts b/packages/type/src/is/lib/is-param.decorator.ts new file mode 100644 index 00000000..82076e60 --- /dev/null +++ b/packages/type/src/is/lib/is-param.decorator.ts @@ -0,0 +1,40 @@ +import { Func } from '../../type/func.type'; +import { is } from './is.object'; + +export function isParam(...param: Array): MethodDecorator { + return (target: Func | object, key: string | symbol, descriptor: any): any => { + const originalMethod = descriptor.value; + + descriptor.value = function(): void { + if (is.array(param) && is.defined(arguments)) { + param.forEach((name: string, index: number) => { + if (is.number(index) && index < arguments.length) { + if (is.defined(arguments[index])) { + switch (name) { + case 'number': + if (is.number(arguments[index]) === false) { + arguments[index] = undefined; + } + break; + case 'object': + if (is.object(arguments[index]) === false) { + arguments[index] = undefined; + } + break; + case 'string': + if (is.string(arguments[index]) === false) { + arguments[index] = undefined; + } + break; + } + } + } + }); + } + const result = originalMethod.apply(this, arguments); + return result; + }; + + return descriptor; + }; +} diff --git a/packages/type/src/is/test/is-param.spec.ts b/packages/type/src/is/test/is-param.spec.ts new file mode 100644 index 00000000..9a2ff9a5 --- /dev/null +++ b/packages/type/src/is/test/is-param.spec.ts @@ -0,0 +1,78 @@ +import { NUMBER } from './variables/number.const'; +import { STRING } from './variables/string.const'; +import { isParam } from '../lib/is-param.decorator'; + +class TestClass { + @isParam('object', 'string', 'number') + public testMethod(object?: any, firstName?: any, age?: any): { object: any, firstName: any, age: any } { + return {object, firstName, age}; + } +} + +describe(`isParam`, () => { + const resultTRUE = new TestClass().testMethod({firstName: 'NoName'}, STRING, NUMBER); + const resultFALSE = new TestClass().testMethod(NUMBER, {firstName: 'NoName'}, STRING); + + // Defined. + it('is DEFINED', () => expect(isParam).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + // ... objects. + describe('object', () => { + it(`CLASS`, () => { + expect(resultTRUE.object).toEqual({firstName: 'NoName'}); + expect(resultFALSE.object).toBeUndefined(); + }); + }); + + // ... primitives. + describe(`primitive`, () => { + // bigint + // describe(`bigint`, () => { + // it(`${BIGINT}`, () => expect(isPrimitive(BIGINT, 'bigint')).toBe(TRUE)); + // it(`${BIGINT_EXPECTATION}`, () => expect(isPrimitive(BIGINT_INSTANCE, 'bigint')).toBe(TRUE)); + // }); + + // boolean + // describe(`boolean`, () => { + // it(`${TRUE}`, () => expect(isPrimitive(TRUE, 'boolean')).toBe(TRUE)); + // it(`${FALSE}`, () => expect(isPrimitive(FALSE, 'boolean')).toBe(TRUE)); + // it(`${FALSE_EXPECTATION}`, () => expect(isPrimitive(TRUE_INSTANCE, 'boolean')).toBe(TRUE)); + // it(`${TRUE_EXPECTATION}`, () => expect(isPrimitive(FALSE_INSTANCE, 'boolean')).toBe(TRUE)); + // }); + + // null + // it(`${NULL}`, () => expect(isPrimitive(NULL, 'null')).toBe(TRUE)); + + // number + describe(`number`, () => { + it(`${NUMBER}`, () => { + expect(resultTRUE.age).toBe(NUMBER); + expect(resultFALSE.age).toBeUndefined(); + }); + // it(`Number(${NUMBER})`, () => expect(isPrimitive(NUMBER_INSTANCE, 'number')).toBe(TRUE)); + // it(`new Number(${NUMBER})`, () => expect(isPrimitive(NUMBER_NEW_INSTANCE, 'number')).toBe(TRUE)); + }); + + // string + describe(`string`, () => { + it(`${STRING}`, () => { + expect(resultTRUE.firstName).toBe(STRING); + expect(resultFALSE.firstName).toBeUndefined(); + }); + // it(`String(${STRING})`, () => expect(isPrimitive(STRING_INSTANCE, 'string')).toBe(TRUE)); + // it(`new String(${STRING})`, () => expect(isPrimitive(STRING_NEW_INSTANCE, 'string')).toBe(TRUE)); + }); + + // symbol + describe(`symbol`, () => { + // it(`Symbol(${NUMBER})`, () => expect(isPrimitive(SYMBOL_NUMBER, 'symbol')).toBe(TRUE)); + // it(`Symbol(${STRING})`, () => expect(isPrimitive(SYMBOL_STRING, 'symbol')).toBe(TRUE)); + }); + + // undefined + // it(`${UNDEFINED}`, () => expect(isPrimitive(UNDEFINED, 'undefined')).toBe(TRUE)); + }); + }); +}); From 151d3b69800ba09796376c623dc86808f06814e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 3 May 2021 18:51:34 +0200 Subject: [PATCH 185/201] refactor(isParam): remove `type` --- packages/type/src/is/lib/is-param.decorator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/type/src/is/lib/is-param.decorator.ts b/packages/type/src/is/lib/is-param.decorator.ts index 82076e60..620b0fa2 100644 --- a/packages/type/src/is/lib/is-param.decorator.ts +++ b/packages/type/src/is/lib/is-param.decorator.ts @@ -1,7 +1,7 @@ import { Func } from '../../type/func.type'; import { is } from './is.object'; -export function isParam(...param: Array): MethodDecorator { +export function isParam(...param: Array): MethodDecorator { return (target: Func | object, key: string | symbol, descriptor: any): any => { const originalMethod = descriptor.value; From 5d57ed9b2935f4caa3016c775a69ce187e36f9f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 3 May 2021 18:56:11 +0200 Subject: [PATCH 186/201] feat(BigIntObject): experimental BigIntObject --- packages/type/src/lib/bigint-object.class.ts | 11 ++++++++ packages/type/src/test/bigint-object.spec.ts | 27 ++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 packages/type/src/lib/bigint-object.class.ts create mode 100644 packages/type/src/test/bigint-object.spec.ts diff --git a/packages/type/src/lib/bigint-object.class.ts b/packages/type/src/lib/bigint-object.class.ts new file mode 100644 index 00000000..186756f9 --- /dev/null +++ b/packages/type/src/lib/bigint-object.class.ts @@ -0,0 +1,11 @@ +import { PrimitiveObject } from './primitive-object.class'; + +export class BigIntObject { + static set set(value: any) { + PrimitiveObject.bigint = BigInt(value); + } + static get get(): BigInt { + return PrimitiveObject.bigint; + } +} + diff --git a/packages/type/src/test/bigint-object.spec.ts b/packages/type/src/test/bigint-object.spec.ts new file mode 100644 index 00000000..e7221145 --- /dev/null +++ b/packages/type/src/test/bigint-object.spec.ts @@ -0,0 +1,27 @@ +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from '../is/test/variables/big-int.const'; +import { BigIntObject } from '../lib/bigint-object.class'; + + +describe(`BigIntObject`, () => { + // Defined. + it('is DEFINED', () => expect(BigIntObject).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + + // ... primitives. + describe(`primitive`, () => { + // bigint + describe(`bigint`, () => { + it(`${BIGINT}`, () => { + BigIntObject.set = BIGINT; + expect(BigIntObject.get).toEqual(BIGINT); + }); + it(`${BIGINT_EXPECTATION}`, () => { + BigIntObject.set = BIGINT_INSTANCE; + expect(BigIntObject.get).toEqual(BIGINT_INSTANCE); + }); + }); + }); + }); +}); From 73d4667ed4e94e46be9be2740573b78fc62126bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 3 May 2021 19:05:59 +0200 Subject: [PATCH 187/201] feat(SymbolObject): experimental symbol --- packages/type/src/lib/symbol-object.class.ts | 10 ++++++++++ packages/type/src/test/symbol-object.spec.ts | 21 ++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 packages/type/src/lib/symbol-object.class.ts create mode 100644 packages/type/src/test/symbol-object.spec.ts diff --git a/packages/type/src/lib/symbol-object.class.ts b/packages/type/src/lib/symbol-object.class.ts new file mode 100644 index 00000000..a45e96c3 --- /dev/null +++ b/packages/type/src/lib/symbol-object.class.ts @@ -0,0 +1,10 @@ +import { PrimitiveObject } from './primitive-object.class'; + +export class SymbolObject { + static set set(value: string | number | undefined) { + PrimitiveObject.symbol = Symbol(value); + } + static get get(): Symbol { + return PrimitiveObject.symbol; + } +} diff --git a/packages/type/src/test/symbol-object.spec.ts b/packages/type/src/test/symbol-object.spec.ts new file mode 100644 index 00000000..71db2393 --- /dev/null +++ b/packages/type/src/test/symbol-object.spec.ts @@ -0,0 +1,21 @@ +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from '../is/test/variables/string.const'; +import { SymbolObject } from '../lib/symbol-object.class'; +import { SYMBOL_NUMBER } from '../is/test/variables/symbol.const'; + +describe(`SymbolObject`, () => { + // Defined. + it('is DEFINED', () => expect(SymbolObject).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + + // ... primitives. + describe(`primitive`, () => { + // string + describe(`symbol`, () => { + SymbolObject.set = STRING; + it(`Symbol(${STRING})`, () => expect(SymbolObject.get).toBeDefined()); + }); + }); + }); +}); From 475faa1f285297ca48463b95ea94368d0f751c41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 3 May 2021 19:06:18 +0200 Subject: [PATCH 188/201] feat(BooleanObject): experimental object for boolean --- packages/type/src/lib/boolean-object.class.ts | 14 +++++++++++ packages/type/src/test/boolean-object.spec.ts | 25 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 packages/type/src/lib/boolean-object.class.ts create mode 100644 packages/type/src/test/boolean-object.spec.ts diff --git a/packages/type/src/lib/boolean-object.class.ts b/packages/type/src/lib/boolean-object.class.ts new file mode 100644 index 00000000..632f34b7 --- /dev/null +++ b/packages/type/src/lib/boolean-object.class.ts @@ -0,0 +1,14 @@ +import { PrimitiveObject } from './primitive-object.class'; + +export class BooleanObject { + /** + * `false` when empty, 0, null, '', false + * `true` when 'true', 'false', 'Su Lin whatever', [], {}, true + */ + static set set(value: any) { + PrimitiveObject.boolean = new Boolean(value); + } + static get get(): Boolean { + return PrimitiveObject.boolean; + } +} diff --git a/packages/type/src/test/boolean-object.spec.ts b/packages/type/src/test/boolean-object.spec.ts new file mode 100644 index 00000000..1d37f69e --- /dev/null +++ b/packages/type/src/test/boolean-object.spec.ts @@ -0,0 +1,25 @@ +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from '../is/test/variables/big-int.const'; +import { BigIntObject } from '../lib/bigint-object.class'; + + +describe(`BigIntObject`, () => { + // Defined. + it('is DEFINED', () => expect(BigIntObject).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + + // ... primitives. + describe(`primitive`, () => { + // bigint + describe(`bigint`, () => { + + BigIntObject.set = BIGINT; + it(`${BIGINT}`, () => expect(BigIntObject.get).toEqual(BIGINT)); + + BigIntObject.set = BIGINT_INSTANCE; + it(`${BIGINT_EXPECTATION}`, () => expect(BigIntObject.get).toEqual(BIGINT_INSTANCE)); + }); + }); + }); +}); From c579f9ee9a25065dbfe5f4c2801a9fda8c2a4f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 3 May 2021 19:06:33 +0200 Subject: [PATCH 189/201] feat(NumberObject): experimental object for number --- packages/type/src/lib/number-object.class.ts | 10 ++++++++ packages/type/src/test/number-object.spec.ts | 27 ++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 packages/type/src/lib/number-object.class.ts create mode 100644 packages/type/src/test/number-object.spec.ts diff --git a/packages/type/src/lib/number-object.class.ts b/packages/type/src/lib/number-object.class.ts new file mode 100644 index 00000000..30f19bdb --- /dev/null +++ b/packages/type/src/lib/number-object.class.ts @@ -0,0 +1,10 @@ +import { PrimitiveObject } from './primitive-object.class'; + +export class NumberObject { + static set set(value: any) { + PrimitiveObject.number = new Number(value); + } + static get get(): Number { + return PrimitiveObject.number; + } +} diff --git a/packages/type/src/test/number-object.spec.ts b/packages/type/src/test/number-object.spec.ts new file mode 100644 index 00000000..381857fc --- /dev/null +++ b/packages/type/src/test/number-object.spec.ts @@ -0,0 +1,27 @@ +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from '../is/test/variables/number.const'; +import { NumberObject } from '../lib/number-object.class'; + + +describe(`NumberObject`, () => { + // Defined. + it('is DEFINED', () => expect(NumberObject).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + + // ... primitives. + describe(`primitive`, () => { + // number + describe(`number`, () => { + NumberObject.set = NUMBER; + it(`${NUMBER}`, () => expect(NumberObject.get).toEqual(NUMBER)); + + NumberObject.set = NUMBER_INSTANCE; + it(`Number(${NUMBER})`, () => expect(NumberObject.get).toEqual(NUMBER_INSTANCE)); + + NumberObject.set = NUMBER_NEW_INSTANCE; + it(`new Number(${NUMBER})`, () => expect(NumberObject.get).toEqual(NUMBER_NEW_INSTANCE)); + }); + }); + }); +}); From 0e8b902ec8a19793146841d29c886be5518c734a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 3 May 2021 19:06:56 +0200 Subject: [PATCH 190/201] feat(StringObject): experimental object for string --- packages/type/src/lib/string-object.class.ts | 10 ++++++++ packages/type/src/test/string-object.spec.ts | 27 ++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 packages/type/src/lib/string-object.class.ts create mode 100644 packages/type/src/test/string-object.spec.ts diff --git a/packages/type/src/lib/string-object.class.ts b/packages/type/src/lib/string-object.class.ts new file mode 100644 index 00000000..234536bb --- /dev/null +++ b/packages/type/src/lib/string-object.class.ts @@ -0,0 +1,10 @@ +import { PrimitiveObject } from './primitive-object.class'; + +export class StringObject { + static set set(value: any) { + PrimitiveObject.string = new String(value); + } + static get get(): String { + return PrimitiveObject.string; + } +} diff --git a/packages/type/src/test/string-object.spec.ts b/packages/type/src/test/string-object.spec.ts new file mode 100644 index 00000000..37606814 --- /dev/null +++ b/packages/type/src/test/string-object.spec.ts @@ -0,0 +1,27 @@ +import { StringObject } from '../lib/string-object.class'; +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from '../is/test/variables/string.const'; + + +describe(`StringObject`, () => { + // Defined. + it('is DEFINED', () => expect(StringObject).toBeDefined()); + + // Checks ... + describe(`checks`, () => { + + // ... primitives. + describe(`primitive`, () => { + // string + describe(`string`, () => { + StringObject.set = STRING; + it(`${STRING}`, () => expect(StringObject.get).toEqual(STRING)); + + StringObject.set = STRING_INSTANCE; + it(`Number(${STRING})`, () => expect(StringObject.get).toEqual(STRING_INSTANCE)); + + StringObject.set = STRING_NEW_INSTANCE; + it(`new Number(${STRING})`, () => expect(StringObject.get).toEqual(STRING_NEW_INSTANCE)); + }); + }); + }); +}); From def17e626bd8beba2fc08c7a1c9463dda290eddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 3 May 2021 19:07:15 +0200 Subject: [PATCH 191/201] test(guardBigInt): update --- .../type/src/guard/test/guard-bigint.spec.ts | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/type/src/guard/test/guard-bigint.spec.ts b/packages/type/src/guard/test/guard-bigint.spec.ts index 782cb3d9..6c71783f 100644 --- a/packages/type/src/guard/test/guard-bigint.spec.ts +++ b/packages/type/src/guard/test/guard-bigint.spec.ts @@ -2,13 +2,13 @@ import { guardBigInt } from '../lib/guard-big-int.func'; // Variables. import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from '../../is/test/variables/big-int.const'; -import { Class, CLASS } from '../../is/test/variables/class.const'; -import { FUNCTION } from '../../is/test/variables/function.const'; +// import { Class, CLASS } from '../../is/test/variables/class.const'; +// import { FUNCTION } from '../../is/test/variables/function.const'; import { NULL } from '../../is/test/variables/null.const'; import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from '../../is/test/variables/number.const'; -import { OBJECT_ONE, OBJECT_TWO, OBJECT_ONE_NEW, OBJECT_TWO_NEW } from '../../is/test/variables/object.const'; +// import { OBJECT_ONE, OBJECT_TWO, OBJECT_ONE_NEW, OBJECT_TWO_NEW } from '../../is/test/variables/object.const'; import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from '../../is/test/variables/string.const'; -import { SYMBOL_NUMBER, SYMBOL_STRING } from '../../is/test/variables/symbol.const'; +// import { SYMBOL_NUMBER, SYMBOL_STRING } from '../../is/test/variables/symbol.const'; import { TRUE, FALSE, FALSE_EXPECTATION, TRUE_EXPECTATION, TRUE_INSTANCE, FALSE_INSTANCE } from '../../is/test/variables/boolean.const'; import { UNDEFINED } from '../../is/test/variables/undefined.const'; @@ -20,7 +20,7 @@ describe(`guardBigInt`, () => { describe(`checks`, () => { it('callback', () => { guardBigInt(STRING, (result: boolean) => { - expect(result).toBe(TRUE); + expect(result).toBe(FALSE); return result; }); }); @@ -32,23 +32,23 @@ describe(`guardBigInt`, () => { }); // ... function. describe(`function`, () => { - it(`FUNCTION`, () => expect(guardBigInt(FUNCTION)).toBe(FALSE)); - it(`Class`, () => expect(guardBigInt(Class)).toBe(FALSE)); + // it(`FUNCTION`, () => expect(guardBigInt(FUNCTION)).toBe(FALSE)); + // it(`Class`, () => expect(guardBigInt(Class)).toBe(FALSE)); }); // ... objects. describe('object', () => { - it(`CLASS`, () => expect(guardBigInt(CLASS)).toBe(FALSE)); - it(`OBJECT_ONE`, () => expect(guardBigInt(OBJECT_ONE)).toBe(FALSE)); - it(`OBJECT_TWO`, () => expect(guardBigInt(OBJECT_TWO)).toBe(FALSE)); - it(`new Object(OBJECT_ONE_NEW})`, () => expect(guardBigInt(OBJECT_ONE_NEW)).toBe(FALSE)); - it(`new Object(OBJECT_TWO_NEW})`, () => expect(guardBigInt(OBJECT_TWO_NEW)).toBe(FALSE)); + // it(`CLASS`, () => expect(guardBigInt(CLASS)).toBe(FALSE)); + // it(`OBJECT_ONE`, () => expect(guardBigInt(OBJECT_ONE)).toBe(FALSE)); + // it(`OBJECT_TWO`, () => expect(guardBigInt(OBJECT_TWO)).toBe(FALSE)); + // it(`new Object(OBJECT_ONE_NEW})`, () => expect(guardBigInt(OBJECT_ONE_NEW)).toBe(FALSE)); + // it(`new Object(OBJECT_TWO_NEW})`, () => expect(guardBigInt(OBJECT_TWO_NEW)).toBe(FALSE)); }); // ... primitives. describe(`primitive`, () => { // bigint describe(`bigint`, () => { - it(`${BIGINT}`, () => expect(guardBigInt(BIGINT)).toBe(FALSE)); - it(`${BIGINT_EXPECTATION}`, () => expect(guardBigInt(BIGINT_INSTANCE)).toBe(FALSE)); + it(`${BIGINT}`, () => expect(guardBigInt(BIGINT)).toBe(TRUE)); + it(`${BIGINT_EXPECTATION}`, () => expect(guardBigInt(BIGINT_INSTANCE)).toBe(TRUE)); }); // boolean @@ -70,14 +70,14 @@ describe(`guardBigInt`, () => { }); // string describe(`string`, () => { - it(`${STRING}`, () => expect(guardBigInt(STRING)).toBe(TRUE)); - it(`String(${STRING})`, () => expect(guardBigInt(STRING_INSTANCE)).toBe(TRUE)); - it(`new String(${STRING})`, () => expect(guardBigInt(STRING_NEW_INSTANCE)).toBe(TRUE)); + it(`${STRING}`, () => expect(guardBigInt(STRING)).toBe(FALSE)); + it(`String(${STRING})`, () => expect(guardBigInt(STRING_INSTANCE)).toBe(FALSE)); + it(`new String(${STRING})`, () => expect(guardBigInt(STRING_NEW_INSTANCE)).toBe(FALSE)); }); // symbol describe(`symbol`, () => { - it(`Symbol(${NUMBER})`, () => expect(guardBigInt(SYMBOL_NUMBER)).toBe(FALSE)); - it(`Symbol(${STRING})`, () => expect(guardBigInt(SYMBOL_STRING)).toBe(FALSE)); + // it(`Symbol(${NUMBER})`, () => expect(guardBigInt(SYMBOL_NUMBER)).toBe(FALSE)); + // it(`Symbol(${STRING})`, () => expect(guardBigInt(SYMBOL_STRING)).toBe(FALSE)); }); // undefined it(`${UNDEFINED}`, () => expect(guardBigInt(UNDEFINED)).toBe(FALSE)); From 57059652b46a804a1f1166695a3f0a6a13928b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 3 May 2021 19:07:51 +0200 Subject: [PATCH 192/201] feat(PrimitiveObject): object to hold static primitives --- packages/type/src/lib/primitive-object.class.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 packages/type/src/lib/primitive-object.class.ts diff --git a/packages/type/src/lib/primitive-object.class.ts b/packages/type/src/lib/primitive-object.class.ts new file mode 100644 index 00000000..6aeea8f5 --- /dev/null +++ b/packages/type/src/lib/primitive-object.class.ts @@ -0,0 +1,7 @@ +export class PrimitiveObject { + static bigint: BigInt; + static boolean: Boolean; + static number: Number; + static string: String; + static symbol: Symbol; +} From 69044991497f59c361fdfbed641db5976118300f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 3 May 2021 19:09:56 +0200 Subject: [PATCH 193/201] test(BooleanObject): fix to use boolean --- packages/type/src/test/boolean-object.spec.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/type/src/test/boolean-object.spec.ts b/packages/type/src/test/boolean-object.spec.ts index 1d37f69e..c86c2470 100644 --- a/packages/type/src/test/boolean-object.spec.ts +++ b/packages/type/src/test/boolean-object.spec.ts @@ -1,10 +1,10 @@ -import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from '../is/test/variables/big-int.const'; -import { BigIntObject } from '../lib/bigint-object.class'; +import { TRUE, TRUE_EXPECTATION, TRUE_INSTANCE } from '../is/test/variables/boolean.const'; +import { BooleanObject } from '../lib/boolean-object.class'; -describe(`BigIntObject`, () => { +describe(`BooleanObject`, () => { // Defined. - it('is DEFINED', () => expect(BigIntObject).toBeDefined()); + it('is DEFINED', () => expect(BooleanObject).toBeDefined()); // Checks ... describe(`checks`, () => { @@ -12,13 +12,13 @@ describe(`BigIntObject`, () => { // ... primitives. describe(`primitive`, () => { // bigint - describe(`bigint`, () => { + describe(`boolean`, () => { - BigIntObject.set = BIGINT; - it(`${BIGINT}`, () => expect(BigIntObject.get).toEqual(BIGINT)); + BooleanObject.set = TRUE; + it(`${TRUE}`, () => expect(BooleanObject.get).toEqual(TRUE)); - BigIntObject.set = BIGINT_INSTANCE; - it(`${BIGINT_EXPECTATION}`, () => expect(BigIntObject.get).toEqual(BIGINT_INSTANCE)); + BooleanObject.set = TRUE_INSTANCE; + it(`${TRUE_EXPECTATION}`, () => expect(BooleanObject.get).toEqual(TRUE_INSTANCE)); }); }); }); From a595e8f5b81caf885ac903f02659f42663804636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 3 May 2021 19:27:00 +0200 Subject: [PATCH 194/201] test(BooleanObject): update --- packages/type/src/test/boolean-object.spec.ts | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/packages/type/src/test/boolean-object.spec.ts b/packages/type/src/test/boolean-object.spec.ts index c86c2470..6f2baf11 100644 --- a/packages/type/src/test/boolean-object.spec.ts +++ b/packages/type/src/test/boolean-object.spec.ts @@ -1,4 +1,4 @@ -import { TRUE, TRUE_EXPECTATION, TRUE_INSTANCE } from '../is/test/variables/boolean.const'; +import { TRUE, TRUE_EXPECTATION, TRUE_INSTANCE, FALSE, FALSE_INSTANCE, FALSE_EXPECTATION } from '../is/test/variables/boolean.const'; import { BooleanObject } from '../lib/boolean-object.class'; @@ -14,11 +14,37 @@ describe(`BooleanObject`, () => { // bigint describe(`boolean`, () => { - BooleanObject.set = TRUE; - it(`${TRUE}`, () => expect(BooleanObject.get).toEqual(TRUE)); + it(`${TRUE}`, () => { + BooleanObject.set = TRUE; + expect(BooleanObject.get).not.toEqual(FALSE_INSTANCE); + expect(BooleanObject.get.valueOf()).toBeInstanceOf(Boolean); + expect(BooleanObject.get.valueOf()).toBeTruthy(); + expect(BooleanObject.get.valueOf()).toBe(TRUE); + }); - BooleanObject.set = TRUE_INSTANCE; - it(`${TRUE_EXPECTATION}`, () => expect(BooleanObject.get).toEqual(TRUE_INSTANCE)); + it(`${TRUE_EXPECTATION}`, () => { + BooleanObject.set = TRUE_INSTANCE; + expect(BooleanObject.get.valueOf()).toBeInstanceOf(Boolean); + expect(BooleanObject.get.valueOf()).toBeTrue(); + expect(BooleanObject.get.valueOf()).toBeTruthy(); + expect(BooleanObject.get.valueOf()).toBe(TRUE); + }); + + it(`${FALSE}`, () => { + BooleanObject.set = FALSE; + expect(BooleanObject.get).not.toEqual(TRUE_INSTANCE); + expect(BooleanObject.get.valueOf()).toBeInstanceOf(Boolean); + expect(BooleanObject.get.valueOf()).toBeFalse(); + expect(BooleanObject.get.valueOf()).toBe(FALSE); + }); + + it(`${FALSE_EXPECTATION}`, () => { + BooleanObject.set = FALSE_INSTANCE; + expect(BooleanObject.get.valueOf().valueOf()).toBeInstanceOf(Boolean); + expect(BooleanObject.get.valueOf().valueOf()).toBeTrue(); + expect(BooleanObject.get.valueOf().valueOf()).toBeTruthy(); + expect(BooleanObject.get.valueOf().valueOf()).toBe(TRUE); + }); }); }); }); From 86e1ef4a79f8f6e42317b19fe07bc7ca8bb105ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 3 May 2021 19:32:46 +0200 Subject: [PATCH 195/201] docs(README.md): update --- README.md | 280 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 242 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 1b7a2a39..41b2d0d1 100644 --- a/README.md +++ b/README.md @@ -24,13 +24,20 @@ Common types, type guards and type checkers. // `guard` prefix functions. import { guardArray, + guardBigInt, + guardBoolean, guardFunction, + guardInstance, + guardKey, + guardNull, guardNumber, guardObject, guardObjectKey, guardPrimitive, guardString, - guardType + guardSymbol, + guardType, + guardUndefined } from '@angular-package/type'; ``` @@ -91,48 +98,62 @@ import { Constructor, CycleHook, Func, Key, Primitive, Primitives, ResultCallbac * Checks if * **any** value is - * an `Array` of any type with [isArray](#isArray). - * a `'bigint'` type with [isBigInt](#isBigInt). - * a `'boolean'` type with [isBoolean](#isBoolean). - * a `function` type with [isFunction](#isFunction). - * a generic type `instance` with [isInstance](#isInstance). - * a `null` type with [isNull](#isNull). - * a `number` type with [isNumber](#isNumber). - * a generic type `'object'` with [isObject](#isObject). - * a one of the primitive `boolean`, `bigint`, `number`, `string` type with [isPrimitive](#isPrimitive). - * a `string` type with [isString](#isString). - * a `symbol` type with [isSymbol](#isSymbol). - * a generic type instance, `'function'`, `'object'` or primitive type with [isType](#isType). - * a `'undefined'` type with [isUndefined](#isUndefined). + * an `Array` of any type with [`isArray`](#isArray). + * a `bigint` type with [`isBigInt`](#isBigInt). + * a `boolean` with [`isBoolean`](#isBoolean). + * an `object`type and instance of [`Boolean`][Boolean] and [`Object`][Object] with [`isBooleanObject`](#isBooleanObject). + * a `boolean` type not an instance of [`Boolean`][Boolean] and [`Object`][Object], and equal to `true` or `false` with [`isBooleanType`](#isBooleanType). + * a `function` with [`isFunction`](#isFunction). + * a generic type `instance` with [`isInstance`](#isInstance). + * a [`Key`](#Key) type with [`isKey()`](#isKey). + * a `null` with [isNull](#isNull). + * a `number` with [isNumber](#isNumber). + * an `object` type and instance of [`Number`][Number] and [`Object`][Object] with [`isNumberObject`](#isNumberObject). + * a `number` type and **not** instance of [`Number`][Number] and [`Object`][Object] with [`isNumberType`](#isNumberType). + * a generic type `object` with [isObject](#isObject). + * an `object` with its own specified [`Key`](#Key) with [`isObjectKey`](#isObjectKey). + * a one of the primitive `boolean`, `bigint`, `number`, `string` with [`isPrimitive`](#isPrimitive). + * a `string` with [isString](#isString). + * an `object` type and instance of [`String`][String] and [`Object`][Object]. + * a `symbol` with [`isSymbol`](#isSymbol). + * a generic type instance, `function`, `object` or primitive type with [`isType`](#isType). + * a `undefined` type with [`isUndefined`](#isUndxefined). * an **unknown** value is - * defined with [isDefined](#isDefined). - * an **unknown** value is NOT - * a `'boolean'` type with [isNotBoolean](#isNotBoolean) - * a `'function'` type with [isNotFunction](#isNotFunction) - * a `'null'` type with [isNotNull](#isNotNull) - * a `'number'` type with [isNotNumber](#isNotNumber) - * a `'string'` type with [isNotString](#isNotString) - * a `'undefined'` type with [isNotUndefined](#isNotUndefined) + * defined with [`isDefined`](#isDefined). + * an **unknown** value is **not** a + * `boolean` type with [`isNotBoolean`](#isNotBoolean) + * `function` type with [`isNotFunction`](#isNotFunction) + * `null` type with [`isNotNull`](#isNotNull) + * `number` type with [`isNotNumber`](#isNotNumber) + * `string` type with [`isNotString`](#isNotString) + * `undefined` type with [`isNotUndefined`](#isNotUndefined) * Guard the value to be - * an `Array` of generic type with [guardArray](#guardArray). - * a `function` type with [guardFunction](#guardFunction). - * a `number` type with [guardNumber](#guardNumber). - * a generic `'object'` type that contains `key` with [guardObjectKey](#guardObjectKey). - * a generic `'object'` type with [guardObject](#guardObject). - * a one of the `Primitives` with [guardPrimitive](#guardPrimitive). - * a `string` type with [guardString](#guardString). - * a generic type from one of the [`Types`](#types) type with [Type guard](#guardType). + * an [`Array`][Array] of a generic type with [`guardArray`](#guardArray). + * a `bigint` with [`guardBigInt()`](#guardBigInt). + * a `boolean` with [`guardBoolean()`](#guardBoolean). + * a `function` type with [`guardFunction`](#guardFunction). + * an instance with [`guardInstance()`](#guardInstance). + * a `null` with [`guardNull`](#guardNull). + * a [`Key`](#Key) with [`guardKey`](#guardKey). + * a `number` with [`guardNumber()`](#guardNumber). + * an `object` of a generic type with [`guardObject`](#guardObject). + * an `object` of a generic type that contains `key` with [`guardObjectKey`](#guardObjectKey). + * a one of the [`Primitives`](#Primitives) with [`guardPrimitive`](#guardPrimitive). + * a `string` with [`guardString`](#guardString). + * a `symbol` with [`guardSymbol`](#guardSymbol). + * a generic type from one of the [`Types`](#types) type with [`Type guard`](#guardType). + * `undefined` with [`guardUndefined`](#guardUndefined). ## How angular-package understands Check -> Is to check the return value to be **the same** as **expected**. +> Is to check the inputted value to be **the same** as **expected**. Type guard -> Is to guard type from parameter to **not let** input **unexpected** value in the **code editor**. +> Is to guard the parameter type to **not let** input **unexpected** value in the **code editor**. Guard -> Is a **combination** of both above to **guard type** inputted value in the **code editor** and to check it. +> Is a **combination** of both above to **guard type** in the **code editor** and to check inputted value. ---- @@ -143,6 +164,14 @@ Guard * [is](#is) * [isNot](#isNot) * [Guard](#guard) +* [Experimental](#Experimental) + * [BigIntObject](#BigIntObject) + * [BooleanObject](#BooleanObject) + * [NumberObject](#NumberObject) + * [PrimitiveObject](#PrimitiveObject) + * [StringObject](#StringObject) + * [SymbolObject](#SymbolObject) + * [isParam](#isParam) * [Common types](#common-types) * [Git](#git) * [Commit](#commit) @@ -185,7 +214,7 @@ const stringResult = isString('Lorem ipsum', customCallback); ### are -Object `are` with some of **check are** functions. +Tne object contains prefixed with `are` functions. ```typescript const are: Are = { @@ -193,6 +222,8 @@ const are: Are = { }; ``` +---- + ### areString Use `areString()` or `are.string()` to check if all of **any** arguments are a `string` type. @@ -213,7 +244,7 @@ The **return value** is a `boolean` value. ### is -Object `is` with all **check is** functions and **check is not** in `not` property. +The object contains prefixed with `is` functions and prefixed with `isNot` functions in property `not`. ```typescript const is: Is = { @@ -244,6 +275,8 @@ const is: Is = { }; ``` +---- + ### isArray Use `isArray()` or `is.array()` to check if **any** `value` is an [`Array`][Array], [`Array`][Array] instance, and `object` type. @@ -643,7 +676,7 @@ isNumberObject(NUMBER_NEW_INSTANCE); // true ### isNumberType -Use `isNumberType()` or `is.numberType()` to check if **any** `value` is a `number` type not an instance of [`Number`][Number] and [`Object`][Object] or `object` type instance of [`Number`][Number] and [`Object`][Object]. +Use `isNumberType()` or `is.numberType()` to check if **any** `value` is a `number` type not an instance of [`Number`][Number] and [`Object`][Object]. ```typescript const isNumberType: IsNumberType = (value: any, callback: ResultCallback = resultCallback): value is number => @@ -864,7 +897,7 @@ Use `isString()` or `is.string()` to check if **any** `value` is a `string` type ```typescript const isString: IsString = (value: any, callback: ResultCallback = resultCallback): value is string => - callback(typeOf(value) === 'string' && (isStringObject(value) || isStringType(value))); + callback(typeOf(value) === 'string' && (isStringType(value) || isStringObject(value))); ``` | Parameter | Type | Description | @@ -1149,7 +1182,7 @@ The return value is a `boolean` indicating whether or not the `value` is not `un ### guard -Object `guard` with all **guard** functions. +The object contains prefixed with `guard` functions in `is` property. ```typescript const guardIs: GuardIs = { @@ -1463,6 +1496,177 @@ The **return value** is a `boolean` indicating whether or not the `value` is `un ---- +## Experimental + +### BigIntObject + +```typescript +class BigIntObject { + static set set(value: any) { + PrimitiveObject.bigint = BigInt(value); + } + static get get(): BigInt { + return PrimitiveObject.bigint; + } +} +``` + +---- + +### BooleanObject + +```typescript +class BooleanObject { + /** + * `false` when empty, 0, null, '', false + * `true` when 'true', 'false', 'Su Lin whatever', [], {}, true + */ + static set set(value: any) { + PrimitiveObject.boolean = new Boolean(value); + } + static get get(): Boolean { + return PrimitiveObject.boolean; + } +} +``` + +---- + +### NumberObject + +```typescript +class NumberObject { + static set set(value: any) { + PrimitiveObject.number = new Number(value); + } + static get get(): Number { + return PrimitiveObject.number; + } +} +``` + +---- + +### PrimitiveObject + +```typescript +class PrimitiveObject { + static bigint: BigInt; + static boolean: Boolean; + static number: Number; + static string: String; + static symbol: Symbol; +} +``` + +---- + +### StringObject + +```typescript +class StringObject { + static set set(value: any) { + PrimitiveObject.string = new String(value); + } + static get get(): String { + return PrimitiveObject.string; + } +} +``` + +---- + +### SymbolObject + +```typescript +class SymbolObject { + static set set(value: string | number | undefined) { + PrimitiveObject.symbol = Symbol(value); + } + static get get(): Symbol { + return PrimitiveObject.symbol; + } +} +``` + +---- + +### isParam + +Method decorator to check the type and return `undefined` if it's not the same as expected. + +```typescript +function isParam(...param: Array): MethodDecorator { + return (target: Func | object, key: string | symbol, descriptor: any): any => { + const originalMethod = descriptor.value; + + descriptor.value = function(): void { + if (is.array(param) && is.defined(arguments)) { + param.forEach((name: string, index: number) => { + if (is.number(index) && index < arguments.length) { + if (is.defined(arguments[index])) { + switch (name) { + case 'number': + if (is.number(arguments[index]) === false) { + arguments[index] = undefined; + } + break; + case 'object': + if (is.object(arguments[index]) === false) { + arguments[index] = undefined; + } + break; + case 'string': + if (is.string(arguments[index]) === false) { + arguments[index] = undefined; + } + break; + } + } + } + }); + } + const result = originalMethod.apply(this, arguments); + return result; + }; + + return descriptor; + }; +} +``` + +Example usage. + +```typescript +// Example usage +const STRING: any = '!@#$%^&*()abcdefghijklmnoprstuwyz'; +const NUMBER: any = 10304050; +// TestClass +class TestClass { + @isParam('object', 'string', 'number') + public testMethod(object?: any, firstName?: any, age?: any): { object: any, firstName: any, age: any } { + return {object, firstName, age}; + } +} +const resultTRUE = new TestClass().testMethod({firstName: 'NoName'}, STRING, NUMBER); +const resultFALSE = new TestClass().testMethod(NUMBER, {firstName: 'NoName'}, STRING); + +resultTRUE === { + object: {firstName: 'NoName'}, + string: '!@#$%^&*()abcdefghijklmnoprstuwyz', + number: 10304050 +}; + +resultTRUE === { + object: undefined, + string: undefined, + number: undefined +}; + +``` + +---- + ## Common types ### Constructor From d90310b8231b257f3b36de94598099523ce03369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 3 May 2021 19:37:29 +0200 Subject: [PATCH 196/201] docs(README.md): fix --- README.md | 77 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 41b2d0d1..c48b68b9 100644 --- a/README.md +++ b/README.md @@ -98,51 +98,52 @@ import { Constructor, CycleHook, Func, Key, Primitive, Primitives, ResultCallbac * Checks if * **any** value is - * an `Array` of any type with [`isArray`](#isArray). - * a `bigint` type with [`isBigInt`](#isBigInt). - * a `boolean` with [`isBoolean`](#isBoolean). - * an `object`type and instance of [`Boolean`][Boolean] and [`Object`][Object] with [`isBooleanObject`](#isBooleanObject). - * a `boolean` type not an instance of [`Boolean`][Boolean] and [`Object`][Object], and equal to `true` or `false` with [`isBooleanType`](#isBooleanType). - * a `function` with [`isFunction`](#isFunction). - * a generic type `instance` with [`isInstance`](#isInstance). + * an `Array` of any type with [`isArray()`](#isArray). + * a `bigint` type with [`isBigInt()`](#isBigInt). + * a `boolean` with [`isBoolean()`](#isBoolean). + * an `object`type and instance of [`Boolean`][Boolean] and [`Object`][Object] with [`isBooleanObject()`](#isBooleanObject). + * a `boolean` type not an instance of [`Boolean`][Boolean] and [`Object`][Object], and equal to `true` or `false` with [`isBooleanType()`](#isBooleanType). + * a `function` with [`isFunction()`](#isFunction). + * a generic type `instance` with [`isInstance()`](#isInstance). * a [`Key`](#Key) type with [`isKey()`](#isKey). - * a `null` with [isNull](#isNull). - * a `number` with [isNumber](#isNumber). - * an `object` type and instance of [`Number`][Number] and [`Object`][Object] with [`isNumberObject`](#isNumberObject). - * a `number` type and **not** instance of [`Number`][Number] and [`Object`][Object] with [`isNumberType`](#isNumberType). - * a generic type `object` with [isObject](#isObject). - * an `object` with its own specified [`Key`](#Key) with [`isObjectKey`](#isObjectKey). - * a one of the primitive `boolean`, `bigint`, `number`, `string` with [`isPrimitive`](#isPrimitive). - * a `string` with [isString](#isString). - * an `object` type and instance of [`String`][String] and [`Object`][Object]. - * a `symbol` with [`isSymbol`](#isSymbol). - * a generic type instance, `function`, `object` or primitive type with [`isType`](#isType). - * a `undefined` type with [`isUndefined`](#isUndxefined). + * a `null` with [`isNull()`](#isNull). + * a `number` with [`isNumber()`](#isNumber). + * an `object` type and instance of [`Number`][Number] and [`Object`][Object] with [`isNumberObject()`](#isNumberObject). + * a `number` type and **not** instance of [`Number`][Number] and [`Object`][Object] with [`isNumberType()`](#isNumberType). + * a generic type `object` with [`isObject()`](#isObject). + * an `object` with its own specified [`Key`](#Key) with [`isObjectKey()`](#isObjectKey). + * a one of the primitive `boolean`, `bigint`, `number`, `string` with [`isPrimitive()`](#isPrimitive). + * a `string` with [`isString()`](#isString). + * an `object` type and instance of [`String`][String] and [`Object`][Object] with [`isStringObject()`](#isStringObject). + * a `string` type and **not** instance of [`String`][String] and [`Object`][Object] with [`isStringType()`](#isStringType). + * a `symbol` with [`isSymbol()`](#isSymbol). + * a generic type instance, `function`, `object` or primitive type with [`isType()`](#isType). + * a `undefined` type with [`isUndefined()`](#isUndefined). * an **unknown** value is - * defined with [`isDefined`](#isDefined). + * defined with [`isDefined()`](#isDefined). * an **unknown** value is **not** a - * `boolean` type with [`isNotBoolean`](#isNotBoolean) - * `function` type with [`isNotFunction`](#isNotFunction) - * `null` type with [`isNotNull`](#isNotNull) - * `number` type with [`isNotNumber`](#isNotNumber) - * `string` type with [`isNotString`](#isNotString) - * `undefined` type with [`isNotUndefined`](#isNotUndefined) + * `boolean` type with [`isNotBoolean()`](#isNotBoolean) + * `function` type with [`isNotFunction()`](#isNotFunction) + * `null` type with [`isNotNull()`](#isNotNull) + * `number` type with [`isNotNumber()`](#isNotNumber) + * `string` type with [`isNotString()`](#isNotString) + * `undefined` type with [`isNotUndefined()`](#isNotUndefined) * Guard the value to be - * an [`Array`][Array] of a generic type with [`guardArray`](#guardArray). + * an [`Array`][Array] of a generic type with [`guardArray()`](#guardArray). * a `bigint` with [`guardBigInt()`](#guardBigInt). * a `boolean` with [`guardBoolean()`](#guardBoolean). - * a `function` type with [`guardFunction`](#guardFunction). + * a `function` type with [`guardFunction()`](#guardFunction). * an instance with [`guardInstance()`](#guardInstance). - * a `null` with [`guardNull`](#guardNull). - * a [`Key`](#Key) with [`guardKey`](#guardKey). + * a `null` with [`guardNull()`](#guardNull). + * a [`Key`](#Key) with [`guardKey()`](#guardKey). * a `number` with [`guardNumber()`](#guardNumber). - * an `object` of a generic type with [`guardObject`](#guardObject). - * an `object` of a generic type that contains `key` with [`guardObjectKey`](#guardObjectKey). - * a one of the [`Primitives`](#Primitives) with [`guardPrimitive`](#guardPrimitive). - * a `string` with [`guardString`](#guardString). - * a `symbol` with [`guardSymbol`](#guardSymbol). - * a generic type from one of the [`Types`](#types) type with [`Type guard`](#guardType). - * `undefined` with [`guardUndefined`](#guardUndefined). + * an `object` of a generic type with [`guardObject()`](#guardObject). + * an `object` of a generic type that contains `key` with [`guardObjectKey()`](#guardObjectKey). + * a one of the [`Primitives`](#Primitives) with [`guardPrimitive()`](#guardPrimitive). + * a `string` with [`guardString()`](#guardString). + * a `symbol` with [`guardSymbol()`](#guardSymbol). + * a generic type from one of the [`Types`](#types) type with [`guardType()`](#guardType). + * `undefined` with [`guardUndefined()`](#guardUndefined). ## How angular-package understands @@ -171,7 +172,7 @@ Guard * [PrimitiveObject](#PrimitiveObject) * [StringObject](#StringObject) * [SymbolObject](#SymbolObject) - * [isParam](#isParam) + * [isParam()](#isParam) * [Common types](#common-types) * [Git](#git) * [Commit](#commit) From b90e9bbd44cac87cfe6eb7017c6679f381f1da9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 3 May 2021 19:51:52 +0200 Subject: [PATCH 197/201] docs(README.md): update --- README.md | 10 +- packages/type/README.md | 1716 ++++++++++++++++++++++++++++++--------- 2 files changed, 1336 insertions(+), 390 deletions(-) diff --git a/README.md b/README.md index c48b68b9..fac015f0 100644 --- a/README.md +++ b/README.md @@ -930,16 +930,16 @@ The **return value** is a `boolean` indicating whether or not the `value` is a [ ### isStringType -Use `isStringObject()` or `is.stringObject()` to check if **any** `value` is a `string` type and **not** instance of [`String`][String] and [`Object`][Object]. +Use `isStringType()` or `is.stringType()` to check if **any** `value` is a `string` type and **not** instance of [`String`][String] and [`Object`][Object]. ```typescript const isStringType: IsStringType = (value: any, callback: ResultCallback = resultCallback): value is string => callback(value instanceof Object === false && value instanceof String === false && typeof value === 'string'); ``` -| Parameter | Type | Description | -| :-------- | :---------------------------------: | :------------------- | -| value | `any` | Any `value` to check | +| Parameter | Type | Description | +| :-------- | :---------------------------------------------------------------------: | :------------------- | +| value | `any` | Any `value` to check | | callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `string`. @@ -1451,7 +1451,7 @@ const guardSymbol: GuardSymbol = (value: symbol, callback?: ResultCallback): val | Parameter | Type | Description | | :-------- | :---------------------------------: | :----------------------------- | -| value | `null` | A `null` type `value` to guard | +| value | `symbol` | A `symbol` type `value` to guard | | callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `symbol`. diff --git a/packages/type/README.md b/packages/type/README.md index 78219b2f..fac015f0 100644 --- a/packages/type/README.md +++ b/packages/type/README.md @@ -8,7 +8,7 @@ Useful packages based on the [angular.io](https://angular.io/). | prism | `Prism` highlighter module. | *In Progress* | [Readme][prism-readme-github] | | property | Features to handle properties. | *In Progress* | [Readme][property-readme-github] | | ui | User interface based on **[Spectre.css](https://github.com/picturepan2/spectre)**. | *In Progress* | [Github][ui-readme-github] | -| type | Common types, type guards and checkers. | [![npm version][type-npm-svg]][type-npm-badge] | [Github][type-readme-github] \| [npm][type-readme-npm] | +| type | Common types, type guards and type checkers. | [![npm version][type-npm-svg]][type-npm-badge] | [Github][type-readme-github] \| [npm][type-readme-npm] | ## angular-package/type @@ -21,43 +21,58 @@ Common types, type guards and type checkers. [![GitHub license](https://img.shields.io/github/license/angular-package/type)](https://github.com/angular-package/type/blob/main/LICENSE) ```typescript -// Guard functions. +// `guard` prefix functions. import { guardArray, + guardBigInt, + guardBoolean, guardFunction, + guardInstance, + guardKey, + guardNull, guardNumber, guardObject, guardObjectKey, guardPrimitive, guardString, - guardType + guardSymbol, + guardType, + guardUndefined } from '@angular-package/type'; ``` ```typescript -// Check is functions. +// Check `is` prefix functions. import { isArray, isBigInt, isBoolean, + isBooleanObject, + isBooleanType, isDefined, isFunction, isInstance, + isKey, isNull, isNumber, + isNumberObject, + isNumberType, isObject, + isObjectKey, isPrimitive, isString, + isStringObject, + isStringType, isSymbol, isType, isUndefined } from '@angular-package/type'; -// Check are functions. +// Check `are` prefix functions. import { areString } from '@angular-package/type'; ``` ```typescript -// Check is NOT functions. +// Check `isNot` prefix functions. import { isNotBoolean, isNotDefined, @@ -70,74 +85,95 @@ import { ``` ```typescript -// Guard and is object. -import { are, guard, is } from '@angular-package/type'; +// Object. +import { are, guard, is, isNot } from '@angular-package/type'; ``` ```typescript // Types. -import { Constructor, CycleHook, Func, Primitive, Primitives, Types } from '@angular-package/type'; +import { Constructor, CycleHook, Func, Key, Primitive, Primitives, ResultCallback, Type, Types } from '@angular-package/type'; ``` ## Features * Checks if * **any** value is - * an `Array` of any type with [isArray](#isArray). - * a `'bigint'` type with [isBigInt](#isBigInt). - * a `'boolean'` type with [isBoolean](#isBoolean). - * a `function` type with [isFunction](#isFunction). - * a generic type `instance` with [isInstance](#isInstance). - * a `null` type with [isNull](#isNull). - * a `number` type with [isNumber](#isNumber). - * a generic type `'object'` with [isObject](#isObject). - * a one of the primitive `boolean`, `bigint`, `number`, `string` type with [isPrimitive](#isPrimitive). - * a `string` type with [isString](#isString). - * a `symbol` type with [isSymbol](#isSymbol). - * a generic type instance, `'function'`, `'object'` or primitive type with [isType](#isType). - * a `'undefined'` type with [isUndefined](#isUndefined). + * an `Array` of any type with [`isArray()`](#isArray). + * a `bigint` type with [`isBigInt()`](#isBigInt). + * a `boolean` with [`isBoolean()`](#isBoolean). + * an `object`type and instance of [`Boolean`][Boolean] and [`Object`][Object] with [`isBooleanObject()`](#isBooleanObject). + * a `boolean` type not an instance of [`Boolean`][Boolean] and [`Object`][Object], and equal to `true` or `false` with [`isBooleanType()`](#isBooleanType). + * a `function` with [`isFunction()`](#isFunction). + * a generic type `instance` with [`isInstance()`](#isInstance). + * a [`Key`](#Key) type with [`isKey()`](#isKey). + * a `null` with [`isNull()`](#isNull). + * a `number` with [`isNumber()`](#isNumber). + * an `object` type and instance of [`Number`][Number] and [`Object`][Object] with [`isNumberObject()`](#isNumberObject). + * a `number` type and **not** instance of [`Number`][Number] and [`Object`][Object] with [`isNumberType()`](#isNumberType). + * a generic type `object` with [`isObject()`](#isObject). + * an `object` with its own specified [`Key`](#Key) with [`isObjectKey()`](#isObjectKey). + * a one of the primitive `boolean`, `bigint`, `number`, `string` with [`isPrimitive()`](#isPrimitive). + * a `string` with [`isString()`](#isString). + * an `object` type and instance of [`String`][String] and [`Object`][Object] with [`isStringObject()`](#isStringObject). + * a `string` type and **not** instance of [`String`][String] and [`Object`][Object] with [`isStringType()`](#isStringType). + * a `symbol` with [`isSymbol()`](#isSymbol). + * a generic type instance, `function`, `object` or primitive type with [`isType()`](#isType). + * a `undefined` type with [`isUndefined()`](#isUndefined). * an **unknown** value is - * defined with [isDefined](#isDefined). - * an **unknown** value is NOT - * a `'boolean'` type with [isNotBoolean](#isNotBoolean) - * a `'function'` type with [isNotFunction](#isNotFunction) - * a `'null'` type with [isNotNull](#isNotNull) - * a `'number'` type with [isNotNumber](#isNotNumber) - * a `'string'` type with [isNotString](#isNotString) - * a `'undefined'` type with [isNotUndefined](#isNotUndefined) + * defined with [`isDefined()`](#isDefined). + * an **unknown** value is **not** a + * `boolean` type with [`isNotBoolean()`](#isNotBoolean) + * `function` type with [`isNotFunction()`](#isNotFunction) + * `null` type with [`isNotNull()`](#isNotNull) + * `number` type with [`isNotNumber()`](#isNotNumber) + * `string` type with [`isNotString()`](#isNotString) + * `undefined` type with [`isNotUndefined()`](#isNotUndefined) * Guard the value to be - * an `Array` of generic type with [guardArray](#guardArray). - * a `function` type with [guardFunction](#guardFunction). - * a `number` type with [guardNumber](#guardNumber). - * a generic `'object'` type that contains `key` with [guardObjectKey](#guardObjectKey). - * a generic `'object'` type with [guardObject](#guardObject). - * a one of the `Primitives` with [guardPrimitive](#guardPrimitive). - * a `string` type with [guardString](#guardString). - * a generic type from one of the [`Types`](#types) type with [Type guard](#guardType). + * an [`Array`][Array] of a generic type with [`guardArray()`](#guardArray). + * a `bigint` with [`guardBigInt()`](#guardBigInt). + * a `boolean` with [`guardBoolean()`](#guardBoolean). + * a `function` type with [`guardFunction()`](#guardFunction). + * an instance with [`guardInstance()`](#guardInstance). + * a `null` with [`guardNull()`](#guardNull). + * a [`Key`](#Key) with [`guardKey()`](#guardKey). + * a `number` with [`guardNumber()`](#guardNumber). + * an `object` of a generic type with [`guardObject()`](#guardObject). + * an `object` of a generic type that contains `key` with [`guardObjectKey()`](#guardObjectKey). + * a one of the [`Primitives`](#Primitives) with [`guardPrimitive()`](#guardPrimitive). + * a `string` with [`guardString()`](#guardString). + * a `symbol` with [`guardSymbol()`](#guardSymbol). + * a generic type from one of the [`Types`](#types) type with [`guardType()`](#guardType). + * `undefined` with [`guardUndefined()`](#guardUndefined). ## How angular-package understands Check -> Is to check the return value to be the same as expected. +> Is to check the inputted value to be **the same** as **expected**. Type guard -> Is to guard type from parameter to not let input unexpected value in the code editor. +> Is to guard the parameter type to **not let** input **unexpected** value in the **code editor**. Guard -> Is a combination of both above to type guard input in the code editor and check the return. +> Is a **combination** of both above to **guard type** in the **code editor** and to check inputted value. ---- * [Installation](#installation) -* [Object](#are-object) - * [`are`](#are-object) - * [`guard`](#guard-object) - * [`is`](#is-object) -* [Checks](#checks) - * [are](#areString) - * [is](#isArray) -* [Guards](#guards) -* [Types](#types) +* [resultCallback](#resultCallback) +* [Check](#check) + * [are](#are) + * [is](#is) + * [isNot](#isNot) +* [Guard](#guard) +* [Experimental](#Experimental) + * [BigIntObject](#BigIntObject) + * [BooleanObject](#BooleanObject) + * [NumberObject](#NumberObject) + * [PrimitiveObject](#PrimitiveObject) + * [StringObject](#StringObject) + * [SymbolObject](#SymbolObject) + * [isParam()](#isParam) +* [Common types](#common-types) * [Git](#git) * [Commit](#commit) * [Versioning](#versioning) @@ -153,614 +189,1486 @@ Install `@angular-package/type` package with command: npm i --save @angular-package/type ``` -## are Object +## resultCallback -Object `are` with some of **check are** functions. +Default function to handle `callback`. ```typescript -const are: Are = { - string: areString +const resultCallback: ResultCallback = (result: boolean): boolean => result; +``` + +Custom function to handle `callback`. + +```typescript +const customCallback: ResultCallback = (result: boolean): boolean => { + if (result === false) { + throw new Error('error'); + } + return result; }; + +const stringResult = isString('Lorem ipsum', customCallback); + ``` -## guard Object +## Check + +### are -Object `guard` with all **guard** functions. +Tne object contains prefixed with `are` functions. ```typescript -const guardIs: GuardIs = { - array: guardArray, - function: guardFunction, - number: guardNumber, - objectKey: guardObjectKey, - object: guardObject, - primitive: guardPrimitive, - string: guardString, - type: guardType -}; -const guard: Guard = { - is: guardIs +const are: Are = { + string: areString }; +``` + +---- + +### areString + + Use `areString()` or `are.string()` to check if all of **any** arguments are a `string` type. +```typescript +const areString = (...args: any): boolean => check('string', ...args); ``` -## is Object +| Parameter | Type | Description | +| :-------- | :---: | :------------------------------------------------- | +| ...args | `any` | Any arguments to check they're all a `string` type | + +The **return value** is a `boolean` value. + +[Example usage on playground][are-string] -Object `is` with all **check is** functions and **check is not** in `not` property. +---- + +### is + +The object contains prefixed with `is` functions and prefixed with `isNot` functions in property `not`. ```typescript const is: Is = { array: isArray, - bigInt: isBigInt, + bigInt: isBigInt, // deprecated + bigint: isBigInt, boolean: isBoolean, + booleanObject: isBooleanObject, + booleanType: isBooleanType, defined: isDefined, function: isFunction, + instance: isInstance, + key: isKey, not: isNot, null: isNull, number: isNumber, + numberObject: isNumberObject, + numberType: isNumberType, object: isObject, + objectKey: isObjectKey, primitive: isPrimitive, string: isString, + stringObject: isStringObject, + stringType: isStringType, symbol: isSymbol, type: isType, undefined: isUndefined }; ``` -## isNot Object +---- -Object `isNot` with all **check is not** functions. +### isArray + +Use `isArray()` or `is.array()` to check if **any** `value` is an [`Array`][Array], [`Array`][Array] instance, and `object` type. ```typescript -const isNot: IsNot = { - boolean: isNotBoolean, - defined: isNotDefined, - function: isNotFunction, - null: isNotNull, - number: isNotNumber, - string: isNotString, - undefined: isNotUndefined -}; +const isArray: IsArray = (value: any, callback: ResultCallback = resultCallback): value is Array => + callback( + typeOf(value) === 'array' && + Array.isArray(value) === true && + value instanceof Array === true && + typeof value === 'object' + ); ``` -## Checks +| Parameter | Type | Description | +| :-------- | :---: | :------------------- | +| value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | -### areString +The **return value** is a `boolean` indicating whether or not the `value` is an [`Array`][Array]. - Use `areString()` or `are.string()` to check if all of **any** arguments are a `'string'` type. The return value is a `boolean` value. +```typescript +// Example usage +const ARRAY_NUMBER = [1, 2, 3]; +const ARRAY_STRING = ['a', 'b', 'c']; + +isArray(ARRAY_NUMBER); // true +isArray(ARRAY_STRING); // true +``` + +[Example usage on playground][is-array] + +---- + +### isBigInt + +Use `isBigInt()` or `is.bigint()` to check if **any** `value` is a `bigint` type. ```typescript -const areString = (...args: any): boolean => check('string', ...args); +const isBigInt: IsBigInt = (value: any, callback: ResultCallback = resultCallback): value is bigint => + callback(typeOf(value) === 'bigint' && typeof value === 'bigint'); ``` | Parameter | Type | Description | -|-----------| :---: |-------------| -| ...args | `any` | Any arguments to check they're all a `'string'` type. | +| :-------- | :---: | :---------- | +| value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | -[Example usage][are-string] +The **return value** is a `boolean` indicating whether or not the `value` is a `bigint`. -### isArray +```typescript +// Example usage +const BIGINT = 9007199254740991n; +const NUMBER = 27; + +isBigInt(NUMBER); // false +isBigInt(BIGINT); // true +``` -Use `isArray()` or `is.array()` to check if **any** `value` is an `Array` of `'object'` generic `Type` type and `Array` instance. The return value is a `boolean` value. +[Example usage on playground][is-bigint] | [How to detect `bigint` type][detect-bigint] + +---- + +### isBoolean + +Use `isBoolean()` or `is.boolean()` to check if **any** `value` is a `boolean` type not instance of [`Boolean`][Boolean] and [`Object`][Object] or `object` type instance of [`Boolean`][Boolean] and [`Object`][Object]. ```typescript -const isArray: IsArray = (value: any): value is Array => - typeOf(value) === 'array' && - Array.isArray(value) === true && - value instanceof Array === true && - typeof value === 'object'; +const isBoolean: IsBoolean = (value: any, callback: ResultCallback = resultCallback): value is boolean => + callback(typeOf(value) === 'boolean' && (isBooleanType(value) || isBooleanObject(value))); ``` -| Parameter | Type | Description | -|-----------| :---: |-------------| -| value | `any` | Any `value` to check if it's an `Array` of `'object'` generic `Type` type and `Array` instance. | +| Parameter | Type | Description | +| :---------| :---: | :------------------- | +| value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | -[Example usage][is-array] +The **return value** is a `boolean` indicating whether or not the `value` is a `boolean`. -### isBigInt +```typescript +// Example usage +const BOOLEAN = false; +const BOOLEAN_INSTANCE = new Boolean(false); -Use `isBigInt()` or `is.bigInt()` to check if **any** `value` is a `'bigint'` type. The return value is a `boolean` value. +isBoolean(BOOLEAN); // true +isBoolean(BOOLEAN_INSTANCE); // true +``` + +[Example usage on playground][is-boolean] | [How to detect the `boolean` type][detect-boolean] + +---- + +### isBooleanObject + +Use `isBooleanObject()` or `is.booleanObject()` to check if **any** `value` is an `object` type and instance of [`Boolean`][Boolean] and [`Object`][Object]. ```typescript -const isBigInt: IsBigInt = (value: any): value is bigint => - typeOf(value) === 'bigint' && - typeof value === 'bigint'; +const isBooleanObject: IsBooleanObject = (value: any, callback: ResultCallback = resultCallback): value is boolean => + callback(typeof value === 'object' && value instanceof Boolean === true && value instanceof Object === true); ``` -| Parameter | Type | Description | -|-----------| :---: |-------------| -| value | `any` | Any `value` to check if it's a `'bigint'` type. | +| Parameter | Type | Description | +| :---------| :---: | :------------------- | +| value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | -[Example usage][is-bigint] | [How to detect 'bigint' type][detect-bigint] +The **return value** is a `boolean` indicating whether or not the `value` is a [`Boolean`][Boolean] instance. -### isBoolean +```typescript +// Example usage +const BOOLEAN = false; +const BOOLEAN_INSTANCE = new Boolean(false); + +isBooleanObject(BOOLEAN); // false +isBooleanObject(BOOLEAN_INSTANCE); // true +``` + +---- + +### isBooleanType -Use `isBoolean()` or `is.boolean()` to check if **any** `value` is a `'boolean'` type not instance of `Boolean` and `Object` or `'object'` type instance of `Boolean` and `Object`. The return value is a `boolean` value. - -```typescript -const isBoolean: IsBoolean = (value: any): value is boolean => - typeOf(value) === 'boolean' && - ( - ( - typeof value === 'object' && - value instanceof Boolean === true && - value instanceof Object === true - ) - || - ( - value instanceof Boolean === false && - value instanceof Object === false && - typeof value === 'boolean' && - (value === true || value === false) - ) +Use `isBooleanType()` or `is.booleanType()` to check if **any** `value` is a `boolean` type not an instance of [`Boolean`][Boolean] and [`Object`][Object], and equal to `true` or `false`. + +```typescript +const isBooleanType: IsBooleanType = (value: any, callback: ResultCallback = resultCallback): value is boolean => + callback( + value instanceof Boolean === false && + value instanceof Object === false && + typeof value === 'boolean' && + (value === true || value === false) ); ``` -| Parameter | Type | Description | -|-----------| :---: |-------------| -| value | `any` | Any `value` to check if it's a `'boolean'` type not instance of `Boolean` and `Object` or `'object'` type instance of `Boolean` and `Object`. | +| Parameter | Type | Description | +| :---------| :---: | :------------------- | +| value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a `boolean` type. + +```typescript +// Example usage +const BOOLEAN = false; +const BOOLEAN_INSTANCE = new Boolean(false); -[Example usage][is-boolean] | [How to detect 'boolean' type][detect-boolean] +isBooleanType(BOOLEAN); // true +isBooleanType(BOOLEAN_INSTANCE); // false +``` + +---- ### isDefined -Use `isDefined()` or `is.defined()` to check if an **unknown** `value` is NOT an `'undefined'` type and is not equal to `undefined`. The return value is a `boolean` value. +Use `isDefined()` or `is.defined()` to check if an **unknown** `value` is NOT an `undefined` type and is NOT equal to `undefined`. + +```typescript +const isDefined: IsDefined = (value: unknown, callback: ResultCallback = resultCallback): boolean => + callback(typeOf(value) !== 'undefined' && typeof value !== 'undefined' && value !== undefined); +``` + +| Parameter | Type | Description | +| :-------- | :-------: | :---------------------------- | +| value | `unknown` | An `unknown` `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is defined, not `undefined`. ```typescript -const isDefined: IsDefined = (value: unknown): boolean => - typeOf(value) !== 'undefined' && - typeof value !== 'undefined' && - value !== undefined; +// Example usage +const UNDEFINED = undefined; +let defined; + +isDefined(UNDEFINED); // false +isDefined(defined); // false ``` -| Parameter | Type | Description | -|-----------| :-------: |-------------| -| value | `unknown` | An unknown `value` to check if it's NOT an `'undefined'` type and is not equal to `undefined`. | +---- ### isFunction -Use `isFunction()` or `is.function()` to check if **any** `value` is a `'function'` type, instance of `Function`, and `Object`. The return value is a `boolean` value. +Use `isFunction()` or `is.function()` to check if **any** `value` is a `function` type, an instance of [`Function`][Function] and [`Object`][Object]. ```typescript -const isFunction: IsFunction = (value: any): value is Func => - typeOf(value) === 'function' && - typeof value === 'function' && - value instanceof Function === true && - value instanceof Object === true; +const isFunction: IsFunction = (value: any, callback: ResultCallback = resultCallback): value is Func => + callback( + typeOf(value) === 'function' && + typeof value === 'function' && + value instanceof Function === true && + value instanceof Object === true + ); ``` -| Parameter | Type | Description | -|-----------| :---: |-------------| -| value | `any` | Any `value` to check it's a `'function'` type, instance of `Function` and `Object`. | +| Parameter | Type | Description | +| :-------- | :---: | :------------------- | +| value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a `function`. + +```typescript +// Example usage +class Class { x = 5; } +const FUNC: Func = (x: number): any => { return x + 5; } + +isFunction(Class); // true +isFunction(FUNC); // true +isFunction(() => 5); // true +``` -[Example usage][is-function] | [How to detect 'function' type][detect-function] +[Example usage on playground][is-function] | [How to detect `function` type][detect-function] + +---- ### isInstance -Use `isInstance()` or `is.instance()` to check if **any** value is a generic `Obj` type `constructor` instance and is an `Object`. +Use `isInstance()` or `is.instance()` to check if **any** value is an `object` of a generic `Obj` type equal to an `instance` of [`Constructor`](#Constructor) type. ```typescript -const isInstance: IsInstance = (value: any, instance: Constructor): value is Obj => - isObject(value) && - value instanceof instance === true && - isString(instance.prototype.constructor.name) === true; +const isInstance: IsInstance = ( + value: any, + instance: Constructor, + callback: ResultCallback = resultCallback + ): value is Obj => + callback( + isObject(value) ? + isFunction(instance) ? + value instanceof instance === true + : false + : false + ); ``` -| Parameter | Type | Description | -|-----------| :----------------: |-------------| -| value | `any` | Any generic `Obj` type `value` instance to compare with `type` instance. | -| type | `Constructor` | Creates generic `Obj` type instance to compare with argument `value`. | +| Parameter | Type | Description | +| :-------- | :--------------------------------: | :---------- | +| value | `any` | Any `value` to compare with the `instance` | +| instance | [`Constructor`](#Constructor) | A generic `Obj` [`Constructor`](#Constructor) type to create an `instance` to compare with the `value` | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is an `instance` of a generic `Obj`. -[Example usage][is-instance] | [How to detect `constructor` instance][detect-instance] +```typescript +// Example usage +class Some { x = 127; } +class Two { y = 'Lorem ipsum'; } + +const SOME = new Some(); +const TWO = new Two(); + +isInstance(TWO, Some); // false +isInstance(SOME, Some); // true +isInstance(TWO, Two); // true and type error +``` + +[Example usage on playground][is-instance] | [How to detect `constructor` instance][detect-instance] + +---- + +### isKey + +Use `isKey()` or `is.key()` to check if **any** `value` is one of the `string`, `number`, or `symbol`. + +```typescript +const isKey: IsKey = (value: any, callback: ResultCallback = resultCallback): value is Key => + callback(isString(value) || isNumber(value) || isSymbol(value)); +``` + +| Parameter | Type | Description | +| :-------- | :---: |:-------------------- | +| value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a [`Key`](#Key). + +```typescript +// Example usage +const STRING = 'surname'; +const STRING_INSTANCE = new String(STRING); +isKey(STRING); // true +isKey(STRING_INSTANCE); // true + +const NUMBER = 27; +const NUMBER_INSTANCE = new Number(NUMBER); +isKey(NUMBER); // true +isKey(NUMBER_INSTANCE); // true + +const SYMBOL_NUMBER: unique symbol = Symbol(NUMBER); +const SYMBOL_STRING: unique symbol = Symbol(STRING); +isKey(SYMBOL_NUMBER); // true +isKey(SYMBOL_STRING); // true +``` + +---- ### isNull -Use `isNull()` or `is.null()` to check if **any** `value` is an `'object'` type and equal to `null`. +Use `isNull()` or `is.null()` to check if **any** `value` is an `object` type and equal to `null`. ```typescript -const isNull: IsNull = (value: any): value is null => - typeOf(value) === 'null' && - typeof value === 'object' && - value === null; +const isNull: IsNull = (value: any, callback: ResultCallback = resultCallback): value is null => + callback(typeOf(value) === 'null' && typeof value === 'object' && value === null); ``` -| Parameter | Type | Description | -|-----------| :---: |-------------| -| value | `any` | Any `value` to check if it's a `null` value and an `'object'` type. | +| Parameter | Type | Description | +| :-------- | :---: |--------------------- | +| value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is `null`. + +```typescript +// Example usage +/** + * typeof === 'object' + * instanceof Function === false + * instanceof Number === false + * instanceof Object === false + */ +const NULL: any = null; +const NUMBER = 27; + +isNull(NULL); // true +isNull(NUMBER); // false +``` + +[Example usage on playground][is-null] | [How to detect `null` type][detect-null] -[Example usage][is-null] | [How to detect `null` type][detect-null] +---- ### isNumber -Use `isNumber()` or `is.number()` to check if **any** `value` is a '`number`' type not instance of `Number` and `Object` or `'object'` type instance of `Number` and `Object`. The return value is a `boolean` value. - -```typescript -const isNumber: IsNumber = (value: any): value is number => - typeOf(value) === 'number' && - ( - isFinite(value) === true && - ( - value instanceof Number === false && - value instanceof Object === false && - typeof value === 'number' - ) - || - ( - typeof value === 'object' && - value instanceof Number === true && - value instanceof Object === true - ) - ); +Use `isNumber()` or `is.number()` to check if **any** `value` is a `number` type not an instance of [`Number`][Number] and [`Object`][Object] or `object` type instance of [`Number`][Number] and [`Object`][Object]. + +```typescript +const isNumber: IsNumber = (value: any, callback: ResultCallback = resultCallback): value is number => + callback(typeOf(value) === 'number' && isFinite(value) === true && (isNumberType(value) || isNumberObject(value))); ``` -| Parameter | Type | Description | -|-----------| :---: |-------------| -| value | `any` | Any ``value`` to check if it's a `'number'` type not instance of `Number` and `Object` or `'object'` type instance of `Number` and `Object`. | +| Parameter | Type | Description | +| :-------- | :---: | :------------------- | +| value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | -[Example usage][is-number] | [How to detect `'number'` type][detect-number] +The **return value** is a `boolean` indicating whether or not the `value` is a `number`. + +[Example usage on playground][is-number] | [How to detect a `number` type][detect-number] + +---- + +### isNumberObject + +Use `isNumberObject()` or `is.numberObject()` to check if **any** `value` is an `object` type and instance of [`Number`][Number] and [`Object`][Object]. + +```typescript +const isNumberObject: IsNumberObject = (value: any, callback: ResultCallback = resultCallback): value is number => + callback(typeof value === 'object' && value instanceof Number === true && value instanceof Object === true); +``` + +| Parameter | Type | Description | +| :-------- | :---: | :------------------- | +| value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a [`Number`][Number] instance. + +```typescript +// Example usage +/** + * typeof === 'number' + * instanceof Function === false + * instanceof Number === false + * instanceof Object === false + */ +const NUMBER: any = 10304050; + +/** + * typeof === 'number' + * instanceof Function === false + * instanceof Number === false + * instanceof Object === false + */ +const NUMBER_INSTANCE: any = Number(NUMBER); + +/** + * typeof === 'number' + * instanceof Function === false + * instanceof Number === true + * instanceof Object === true + */ +const NUMBER_NEW_INSTANCE: any = new Number(NUMBER); + +isNumberObject(NUMBER); // false +isNumberObject(NUMBER_INSTANCE); // false +isNumberObject(NUMBER_NEW_INSTANCE); // true +``` + +---- + +### isNumberType + +Use `isNumberType()` or `is.numberType()` to check if **any** `value` is a `number` type not an instance of [`Number`][Number] and [`Object`][Object]. + +```typescript +const isNumberType: IsNumberType = (value: any, callback: ResultCallback = resultCallback): value is number => + callback(value instanceof Number === false && value instanceof Object === false && typeof value === 'number'); +``` + +| Parameter | Type | Description | +| :-------- | :---: | :------------------- | +| value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a `number`. + +```typescript +// Example usage +/** + * typeof === 'number' + * instanceof Function === false + * instanceof Number === false + * instanceof Object === false + */ +const NUMBER: any = 10304050; + +/** + * typeof === 'number' + * instanceof Function === false + * instanceof Number === false + * instanceof Object === false + */ +const NUMBER_INSTANCE: any = Number(NUMBER); + +/** + * typeof === 'number' + * instanceof Function === false + * instanceof Number === true + * instanceof Object === true + */ +const NUMBER_NEW_INSTANCE: any = new Number(NUMBER); + +isNumberType(NUMBER); // true +isNumberType(NUMBER_INSTANCE); // true +isNumberType(NUMBER_NEW_INSTANCE); // false +``` + +---- ### isObject -Use `isObject()` or `is.object()` to check if **any** `value` is a generic `Obj` `'object'` type and `Object` instance with the possibility of containing `key`. The return value is a `boolean` value. +Use `isObject()` or `is.object()` to check if **any** `value` is an `object` of a generic `Obj` type and [`Object`][Object] instance with the possibility of containing the `key`. ```typescript -const isObject: IsObject = (value: any, key?: string): value is Obj => - typeOf(value) === 'object' && - typeof value === 'object' && - value instanceof Object === true - ? isString(key) === true - ? value.hasOwnProperty(key) === true +const isObject: IsObject = (value: any, key?: Key): value is Obj => + (typeOf(value) === 'object' && typeof value === 'object' && value instanceof Object === true) + ? isKey(key) + ? key in value : true : false; ``` -| Parameter | Type | Description | -|-----------| :------: |-------------| -| value | `any` | Any `value` to check if it's a generic `'object'` type and `Object` instance. | -| key? | `string` | Property name to find in argument `value`. | +| Parameter | Type | Description | +| :-------- | :-----------: | :---------- | +| value | `any` | Any `value` to check | +| key? | [`Key`](#Key) | Property name to find in the `value` | + +The **return value** is a `boolean` indicating whether or not the `value` is an `object`. + +[Example usage on playground][is-object] | [How to detect an `object` type][detect-object] + +```typescript +// Example usage +const SYMBOL_NUMBER: unique symbol = Symbol(NUMBER); +const SYMBOL_STRING: unique symbol = Symbol(STRING); + +/** + * typeof === 'number' + * instanceof Function === false + * instanceof Number === false + * instanceof Object === false + */ +const NUMBER: any = 10304050; + +/** + * typeof === 'number' + * instanceof Function === false + * instanceof Number === false + * instanceof Object === false + */ +const NUMBER_INSTANCE: any = Number(NUMBER); + +/** + * typeof === 'number' + * instanceof Function === false + * instanceof Number === true + * instanceof Object === true + */ +const NUMBER_NEW_INSTANCE: any = new Number(NUMBER); + +/** + * typeof === 'string' + * instanceof Function === false + * instanceof Object === false + * instanceof String === false + */ +const STRING: any = '!@#$%^&*()abcdefghijklmnoprstuwyz'; + +/** + * typeof === 'string' + * instanceof Function === false + * instanceof Object === false + * instanceof String === false + */ +const STRING_INSTANCE: any = String(STRING); + +/** + * typeof === 'string' + * instanceof Function === false + * instanceof Object === true + * instanceof String === true + */ +const STRING_NEW_INSTANCE: any = new String(STRING); + +const OBJECT_ONE: ObjectOne = { + 'key as string': true, + 1030405027: 'key is number', + 5: 'key is also number', + [NUMBER]: 'key is number', + [STRING]: 'key is string', + [SYMBOL_NUMBER]: 'key is symbol number', + [SYMBOL_STRING]: 6, + x: 3000 +}; + +isObject(OBJECT_ONE); // true +isObject(OBJECT_ONE, 'key as string'); // true +isObject(OBJECT_ONE, STRING); // true +isObject(OBJECT_ONE, STRING_NEW_INSTANCE); // true +isObject(OBJECT_ONE, 1030405027); // true +isObject(OBJECT_ONE, NUMBER); // true +isObject(OBJECT_ONE, NUMBER_NEW_INSTANCE); // true +isObject(OBJECT_ONE, SYMBOL_NUMBER); // true +isObject(OBJECT_ONE, SYMBOL_STRING); // true + +``` + +---- + +### isObjectKey + +Use `isObject()` or `is.object()` to check if **any** `value` is an `object` with its own specified keys of the [`Key`](#Key). -[Example usage][is-object] | [How to detect `'object'` type][detect-object] +```typescript +const isObjectKey: IsObjectKey = ( + value: any, + key: Key | Key[], + callback: ResultCallback = resultCallback +): value is Type => + callback( + isObject(value) ? + isArray(key) ? + key.every(k => isKey(k) ? ({}).hasOwnProperty.call(value, k) === true : false) + : isKey(key) ? + ({}).hasOwnProperty.call(value, key) + : false + : false + ); +``` + +| Parameter | Type | Description | +| :-------- | :------------------------------: | :---------------------------------------------------- | +| value | `any` | Any `value` to check if it contains a specified `key` | +| key | [`Key`](#key) \| [`Key`](#Key)[] | A [`Key`](#Key) type or an array of [`Key`](#Key) type to check in the `value` | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is an `object` with its own specified keys. + +---- ### isPrimitive -Use `isPrimitive()` or `is.primitive()` to check if **any** `value` is a generic `Type` type one of the primitive `'boolean'`, `'bigint'`, `'number'`, `'string'`, `'symbol'`, `'undefined'` type. The return value is a `boolean` value. +Use `isPrimitive()` or `is.primitive()` to check if **any** `value` is the [`Primitive`](#Primitive) type from a `type` of the [`Primitives`](#Primitives) type. ```typescript -const isPrimitive: IsPrimitive = (value: any, type: Primitives): value is Type => { +const isPrimitive: IsPrimitive = ( + value: any, + type: Primitives, + callback: ResultCallback = resultCallback +): value is T => { if (isString(type)) { switch (type) { - case 'bigint': return isBigInt(value); - case 'boolean': return isBoolean(value); - case 'number': return isNumber(value); - case 'string': return isString(value); - case 'symbol': return isSymbol(value); - case 'undefined': return isUndefined(value); + case 'bigint': return isBigInt(value, callback); + case 'boolean': return isBoolean(value, callback); + case 'number': return isNumber(value, callback); + case 'null': return isNull(value, callback); + case 'string': return isString(value, callback); + case 'symbol': return isSymbol(value, callback); + case 'undefined': return isUndefined(value, callback); } } + return false; }; ``` -| Parameter | Type | Description | -|-----------| :----------: |--------------| -| value | `any` | Any `value` to check if it's a generic `Type` type from on of the `type`. | -| type | `Primitives` | One of the `Primitives` `'boolean'`, `'bigint'`, `'number'`, `'string'`, `'symbol'`, `'undefined'` type to check `value`. | +| Parameter | Type | Description | +| :-------- | :-------------------------: | :------------------------------------------------------------------------ | +| value | `any` | Any `value` to check if it's a `Primitive` from the `type` | +| type | [`Primitives`](#Primitives) | A `string` type from the [`Primitives`](#Primitives) to check the `value` | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | -[Example usage][is-primitive] +The **return value** is a `boolean` indicating whether or not the `value` is a `type` from the [`Primitives`](#Primitives). + +[Example usage on playground][is-primitive] + +---- ### isString -Use `isString()` or `is.string()` to check if **any** `value` is a `'string'` type, not instance of `Object` and `String` or `'object'` type and instance of `String` and `Object`. The return value is a `boolean` value. +Use `isString()` or `is.string()` to check if **any** `value` is a `string` type, not instance of [`Object`][Object] and [`String`][String] or `object` type and instance of [`String`][String] and [`Object`][Object]. ```typescript -const isString: IsString = (value: any): value is string => - typeOf(value) === 'string' && - ( - typeof value === 'object' && - value instanceof Object === true && - value instanceof String === true - ) - || - ( - value instanceof Object === false && - value instanceof String === false && - typeof value === 'string' - ); +const isString: IsString = (value: any, callback: ResultCallback = resultCallback): value is string => + callback(typeOf(value) === 'string' && (isStringType(value) || isStringObject(value))); ``` -| Parameter | Type | Description | -|-----------| :---: |-------------| -| value | `any` | Any value to check if it's a `'string'` type, not an instance of `Object` and `String` or `'object'` type and instance of `String` and `Object`. | +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :------------------- | +| value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a `string`. + +---- + +### isStringObject -[Example usage][is-string] | [How to detect `'string'` type][detect-string] +Use `isStringObject()` or `is.stringObject()` to check if **any** `value` is an `object` type and instance of [`String`][String] and [`Object`][Object]. + +```typescript +const isStringObject: IsStringObject = (value: any, callback: ResultCallback = resultCallback): value is string => + callback(value instanceof Object === true && value instanceof String === true && typeof value === 'object'); +``` + +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :------------------- | +| value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a [`String`][String] instance. + +---- + +### isStringType + +Use `isStringType()` or `is.stringType()` to check if **any** `value` is a `string` type and **not** instance of [`String`][String] and [`Object`][Object]. + +```typescript +const isStringType: IsStringType = (value: any, callback: ResultCallback = resultCallback): value is string => + callback(value instanceof Object === false && value instanceof String === false && typeof value === 'string'); +``` + +| Parameter | Type | Description | +| :-------- | :---------------------------------------------------------------------: | :------------------- | +| value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a `string`. + +---- ### isSymbol -Use `isSymbol()` or `is.symbol()` to check if **any** `value` is a `'symbol'` type. The return value is a `boolean` value. +Use `isSymbol()` or `is.symbol()` to check if **any** `value` is a `symbol` type. ```typescript -const isSymbol: IsSymbol = (value: any): value is symbol => - typeOf(value) === 'symbol' && - typeof value === 'symbol'; +const isSymbol: IsSymbol = (value: any, callback: ResultCallback = resultCallback): value is symbol => + callback(typeOf(value) === 'symbol' && typeof value === 'symbol'); ``` -| Parameter | Type | Description | -|-----------| :---: |-------------| -| value | `any` | Any `value` to check if it's a `'symbol'` type. | +| Parameter | Type | Description | +| :-------- | :---: | :------------------- | +| value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a `symbol`. -[Example usage][is-symbol] | [How to detect `'symbol'` type][detect-symbol] +[Example usage on playground][is-symbol] | [How to detect `symbol` type][detect-symbol] + +---- ### isType -Use `isType()` or `is.type()` Check if **any** `value` is a generic `Type` type constructor, `'function'`, `'object'` or primitive type. The return value is a `boolean` value. +Use `isType()` or `is.type()` to check if **any** `value` is the [`Type`](#Type) from a `type` of the [`Types`](#Types) type. ```typescript -const isType: IsType = (value: any, type: Types): value is Type => { +const isType: IsType = (value: any, type: Types, callback: ResultCallback = resultCallback): value is T => { if (isString(type)) { switch (type) { - case 'bigint': return isBigInt(value); - case 'boolean': return isBoolean(value); - case 'function': return isFunction(value); - case 'number': return isNumber(value); - case 'object': return isObject(value); - case 'string': return isString(value); - case 'symbol': return isSymbol(value); - case 'undefined': return isUndefined(value); + // Primitives. + case 'bigint': + case 'boolean': + case 'number': + case 'null' : + case 'string': + case 'symbol': + case 'undefined': return isPrimitive(value, type, callback); + // Function. + case 'function': return isFunction(value, callback); + // Object. + case 'object': return isObject(value); } + } else if (isNotNull(type)) { + return isInstance(value, type, callback); } - return type ? isInstance(value, type) : false; + return false; }; + ``` -| Parameter | Type | Description | -|-----------| :-----------: |-------------| -| value | `any` | Any value to check it is a generic `Type` type from one of the `type`. | -| type | `Types` | Generic constructor `Type`, `'function'`, `'object'` or one of the `Primitives` `'bigint'`, `'boolean'`, `'number'`, `'symbol'`, `'string'`, `'undefined'` to check `value` type. | +| Parameter | Type | Description | +| :-------- | :------------------: | :-------------------------------------------------- | +| value | `any` | Any `value` to check if its type is from the `type` | +| type | [`Types`](#Types) | A `string` or generic `Constructor` type from the [`Types`](#Types) to check the `value` | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is the [`Type`](#Type) from a `type` of the [`Types`](#Types). -[Example usage][is-type] +[Example usage on playground][is-type] + +---- ### isUndefined -Use `isUndefined()` or `is.undefined()` to check if **any** `value` is an `'undefined'` type and equal to `undefined`. The return value is a `boolean` value. +Use `isUndefined()` or `is.undefined()` to check if **any** `value` is an `undefined` type and equal to `undefined`. ```typescript -const isUndefined: IsUndefined = (value: any): value is undefined => - typeOf(value) === 'undefined' && - typeof value === 'undefined' && - value === undefined; +const isUndefined: IsUndefined = (value: any, callback: ResultCallback = resultCallback): value is undefined => + callback(typeOf(value) === 'undefined' && typeof value === 'undefined' && value === undefined); ``` -| Parameter | Type | Description | -|-----------| :---: |-------------| -| value | `any` | Any `value` to check if it's an `'undefined'` type, and equal to `undefined`. | +| Parameter | Type | Description | +| :-------- | :---: | :------------------- | +| value | `any` | Any `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is `undefined`. -[Example usage][is-undefined] | [How to detect `'undefined'` type][detect-undefined] +[Example usage on playground][is-undefined] | [How to detect `undefined` type][detect-undefined] + +---- + +### isNot + +Object `isNot` with all **check is not** functions. + +```typescript +const isNot: IsNot = { + boolean: isNotBoolean, + defined: isNotDefined, + function: isNotFunction, + null: isNotNull, + number: isNotNumber, + string: isNotString, + undefined: isNotUndefined +}; +``` ### isNotBoolean -Use `isNotBoolean()` or `is.not.boolean()` to check if an **unknown** `value` is NOT a `'boolean'` type, NOT equal to `true` or `false` and NOT an instance of a `Boolean`. The return value is a `boolean` value. +Use `isNotBoolean()` or `is.not.boolean()` to check if an **unknown** `value` is **not** a `boolean` type, **not** equal to `true` or `false` and **not** an instance of a [`Boolean`][Boolean]. ```typescript -const isNotBoolean: IsNotBoolean = (value: unknown): boolean => - typeOf(value) !== 'boolean' && - typeof value !== 'boolean' && - value instanceof Boolean === false && - value !== true && - value !== false; +const isNotBoolean: IsNotBoolean = (value: unknown, callback: ResultCallback = resultCallback): boolean => + callback( + typeOf(value) !== 'boolean' && + typeof value !== 'boolean' && + value instanceof Boolean === false && + value !== true && + value !== false + ); ``` -| Parameter | Type | Description | -|-----------| :-------: |-------------| -| value | `unknown` | An unknown `value` to check if it's NOT a `'boolean'` type, NOT equal to `true` or `false` and NOT an instance of `Boolean`. | +| Parameter | Type | Description | +| :-------- | :-------: | :-------------------------- | +| value | `unknown` | An unknown `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is not a `boolean`. + +---- ### isNotDefined -Use `isNotDefined()` or `is.not.defined()` to check if an **unknown** `value` is an `'undefined'` type and is equal to `undefined`. The return value is a `boolean` value. +Use `isNotDefined()` or `is.not.defined()` to check if an **unknown** `value` is an `undefined` type and is equal to `undefined`. ```typescript -const isNotDefined: IsNotDefined = (value: unknown): boolean => - typeOf(value) === 'undefined' && - typeof value === 'undefined' && - value === undefined; +const isNotDefined: IsNotDefined = (value: unknown, callback: ResultCallback = resultCallback): boolean => + callback(typeOf(value) === 'undefined' && typeof value === 'undefined' && value === undefined); ``` -| Parameter | Type | Description | -|-----------| :-------: |-------------| -| value | `unknown` | An unknown `value` to check if it's an `'undefined'` type and is equal to `undefined`. | +| Parameter | Type | Description | +| :-------- | :-------: | :-------------------------- | +| value | `unknown` | An unknown `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The return value is a `boolean` indicating whether or not the `value` is not defined, is `undefined`. + +---- ### isNotFunction -Use `isNotFunction()` or `is.not.function()` to check if an **unknown** `value` is NOT a `'function'` type and NOT an instance of `Function`. The return value is a `boolean` value. +Use `isNotFunction()` or `is.not.function()` to check if an **unknown** `value` is **not** a `function` type and **not** an instance of `Function`. ```typescript -const isNotFunction: IsNotFunction = (value: unknown): boolean => - typeOf(value) !== 'function' && - typeof value !== 'function' && - value instanceof Function === false; +const isNotFunction: IsNotFunction = (value: unknown, callback: ResultCallback = resultCallback): boolean => + callback(typeOf(value) !== 'function' && typeof value !== 'function' && value instanceof Function === false); ``` -| Parameter | Type | Description | -|-----------| :-------: |-------------| -| value | `unknown` | An unknown `value` to check if it's NOT a `'function'` type and NOT an instance of `Function`. | +| Parameter | Type | Description | +| :-------- | :-------: | :-------------------------- | +| value | `unknown` | An unknown `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The return value is a `boolean` indicating whether or not the `value` is not a `function`. + +---- ### isNotNull -Use `isNotNull()` or `is.not.null()` to check if an **unknown** `value` is NOT a `'null'` type and NOT equal to `null`. The return value is a `boolean` value. +Use `isNotNull()` or `is.not.null()` to check if an **unknown** `value` is **not** a `null` type and **not** equal to `null`. ```typescript -const isNotNull: IsNotNull = (value: unknown): boolean => - typeOf(value) !== 'null' && - value !== null; +const isNotNull: IsNotNull = (value: unknown, callback: ResultCallback = resultCallback): boolean => + callback(typeOf(value) !== 'null' && value !== null); ``` -| Parameter | Type | Description | -|-----------| :-------: |-------------| -| value | `unknown` | An unknown `value` to check if it's NOT a `'null'` type and NOT equal to `null`. | +| Parameter | Type | Description | +| :-------- | :-------: | :-------------------------- | +| value | `unknown` | An unknown `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The return value is a `boolean` indicating whether or not the `value` is not `null`. + +---- ### isNotNumber -Use `isNotNumber()` or `is.not.number()` to check if an **unknown** `value` is NOT a `'number'` type and NOT an instance of `Number`. The return value is a `boolean` value. +Use `isNotNumber()` or `is.not.number()` to check if an **unknown** `value` is **not** a `number` type and **not** an instance of `Number`. ```typescript -const isNotNumber: IsNotNumber = (value: any): boolean => - typeOf(value) !== 'number' && - typeof value !== 'number' && - isFinite(value) === false && - value instanceof Number === false; +const isNotNumber: IsNotNumber = (value: any, callback: ResultCallback = resultCallback): boolean => + callback( + typeOf(value) !== 'number' && + typeof value !== 'number' && + value instanceof Number === false + ); ``` -| Parameter | Type | Description | -|-----------| :-------: |-------------| -| value | `unknown` | An unknown value to check if it's NOT a `'number'` type and NOT an instance of `Number`. | +| Parameter | Type | Description | +| :-------- | :-------: | :-------------------------- | +| value | `unknown` | An unknown `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The return value is a `boolean` indicating whether or not the `value` is not a `number`. + +---- ### isNotString -Use `isNotString()` or `is.not.string()` to check if an **unknown** `value` is NOT a `'string'` type and NOT an instance of `String`. The return value is a `boolean` value. +Use `isNotString()` or `is.not.string()` to check if an **unknown** `value` is **not** a `string` type and **not** an instance of `String`. ```typescript -const isNotString: IsNotString = (value: unknown): boolean => - typeOf(value) !== 'string' && - typeof value !== 'string' && - value instanceof String === false; +const isNotString: IsNotString = (value: unknown, callback: ResultCallback = resultCallback): boolean => + callback(typeOf(value) !== 'string' && typeof value !== 'string' && value instanceof String === false); ``` -| Parameter | Type | Description | -|-----------| :-------: |-------------| -| value | `unknown` | An unknown `value` to check if it's NOT a `'string'` type or NOT an `'object'` type and NOT an instance of `String`. | +| Parameter | Type | Description | +| :-------- | :-------: | :-------------------------- | +| value | `unknown` | An unknown `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The return value is a `boolean` indicating whether or not the `value` is not a `string`. + +---- ### isNotUndefined -Use `isNotUndefined()` or `is.not.undefined()` to check if an **unknown** `value` is NOT an `'undefined'` type and NOT equal to `undefined`. The return value is a `boolean` value. +Use `isNotUndefined()` or `is.not.undefined()` to check if an **unknown** `value` is **not** an `undefined` type and **not** equal to `undefined`. ```typescript -const isNotUndefined: IsNotUndefined = (value: unknown): boolean => - typeOf(value) !== 'undefined' && - typeof value !== 'undefined' && - value !== undefined; +const isNotUndefined: IsNotUndefined = (value: unknown, callback: ResultCallback = resultCallback): boolean => + callback(typeOf(value) !== 'undefined' && typeof value !== 'undefined' && value !== undefined); ``` -| Parameter | Type | Description | -|-----------| :-------: |-------------| -| value | `unknown` | An Unknown `value` to check if it's NOT an `'undefined'` type and NOT equal to `undefined`. | +| Parameter | Type | Description | +| :-------- | :-------: | :-------------------------- | +| value | `unknown` | An unknown `value` to check | +| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The return value is a `boolean` indicating whether or not the `value` is not `undefined`. + +---- + +## Guard + +### guard + +The object contains prefixed with `guard` functions in `is` property. + +```typescript +const guardIs: GuardIs = { + array: guardArray, + bigint: guardBigInt, + boolean: guardBoolean, + function: guardFunction, + instance: guardInstance, + key: guardKey, + number: guardNumber, + null: guardNull, + object: guardObject, + objectKey: guardObjectKey, + primitive: guardPrimitive, + string: guardString, + symbol: guardSymbol, + type: guardType, + undefined: guardUndefined +}; +const guard: Guard = { + is: guardIs +}; -## Guards +``` ### guardArray -Use `guardArray()` or `guard.is.array()` to guard the `value` to be a generic `Array` `Type`. The return value is a `boolean` value. +Use `guardArray()` or `guard.is.array()` to guard the `value` to be an [`Array`][Array] of a generic `Type`. ```typescript -const guardArray: GuardArray = (value: Array): value is Array => isArray(value); +const guardArray: GuardArray = (value: Array, callback?: ResultCallback): value is Array => + isArray(value, callback); ``` -| Parameter | Type | Description | -|-----------| :-----------: |-------------| -| value | `Array` | Array generic `Type` type `value` to guard. | +| Parameter | Type | Description | +|-----------| :---------------------------------: |-------------| +| value | `Array` | A generic `Type` `Array` `value` to guard | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is an [`Array`][Array] of a generic `Type`. + +[Example usage on playground][guard-array] + +---- + +### guardBigInt + +Use `guardBigInt()` or `guard.is.bigint()` to guard the `value` to be a `bigint`. + +```typescript +const guardBigInt: GuardBigInt = (value: bigint, callback?: ResultCallback): value is bigint => + isBigInt(value, callback); +``` + +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :------------------------------- | +| value | `bigint` | A `bigint` type `value` to guard | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a `bigint`. + +---- + +### guardBoolean -[Example usage][guard-array] +Use `guardBoolean()` or `guard.is.boolean()` to guard the `value` to be a `boolean`. + +```typescript +const guardBoolean: GuardBoolean = (value: boolean, callback?: ResultCallback): value is boolean => + isBoolean(value, callback); +``` + +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :-------------------------------- | +| value | `boolean` | A `boolean` type `value` to guard | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a `boolean`. + +---- ### guardFunction -Use `guardFunction()` or `guard.is.function()` to guard the `func` value to be a `Func` type. The return value is a `boolean` value. +Use `guardFunction()` or `guard.is.function()` to guard the `value` to be a [`Func`](#Func) type. ```typescript -const guardFunction: GuardFunction = (func: Func): func is Func => isFunction(func); +const guardFunction: GuardFunction = (value: Func, callback?: ResultCallback): value is Func => + isFunction(value, callback); ``` -| Parameter | Type | Description | -|-----------| :----: |--------------| -| func | `Func` | Type `Func` value to guard. | +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :-------------------------------------- | +| value | [`Func`](#Func) | A [`Func`](#Func) type `value` to guard | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | -[Example usage][guard-function] +The return value is a `boolean` indicating whether or not the `value` is a [`Func`](#Func). + +[Example usage on playground][guard-function] + +---- + +### guardInstance + +Use `guardInstance()` or `guard.is.instance()` to guard the `value` to be an `object` of a generic `Obj` type equal to an `instance` of [`Constructor`](#Constructor) type. + +```typescript +const guardInstance: GuardInstance = (value: Obj, instance: Constructor, callback?: ResultCallback): value is Obj => + isInstance(value, instance, callback); +``` + +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :--------------------------------------------------- | +| value | `Obj` | An `Obj` type `value` to compare with the `instance` | +| instance | [`Constructor`](#Constructor) | A generic `Obj` [`Constructor`](#Constructor) type to create an `instance` to compare with the `value` | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is an `instance` of a generic `Obj`. + +---- + +### guardKey + +Use `guardKey()` or `guard.is.key()` to guard the `value` to be one of the `string`, `number`, or `symbol`. + +```typescript +const guardKey: GuardKey = (value: Key, callback?: ResultCallback): value is Key => + isKey(value, callback); +``` + +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :------------------------------------ | +| value | [`Key`](#Key) | A [`Key`](#Key) type `value` to guard | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a [`Key`](#Key). + +---- + +### guardNull + +Use `guardNull()` or `guard.is.null()` to guard the `value` to be a `null`. + +```typescript +const guardNull: GuardNull = (value: null, callback?: ResultCallback): value is null => + isNull(value, callback); +``` + +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :----------------------------- | +| value | `null` | A `null` type `value` to guard | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a `null`. + +---- ### guardNumber -Use `guardNumber()` or `guard.is.number()` to guard the `value` to be a `number` type. The return value is a `boolean` value. +Use `guardNumber()` or `guard.is.number()` to guard the `value` to be a `number`. ```typescript -const guardNumber: GuardNumber = (value: number): value is number => isNumber(value); +const guardNumber: GuardNumber = (value: number, callback?: ResultCallback): value is number => + isNumber(value, callback); ``` -| Parameter | Type | Description | -|-----------| :------: |--------------| -| value | `number` | Type `number` value to guard. | +| Parameter | Type | Description | +|---------- | :---------------------------------: | :-------------------------------- | +| value | `number` | A `number` type `value` to guard. | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | -[Example usage][guard-number] +The **return value** is a `boolean` indicating whether or not the `value` is a `number`. + +[Example usage on playground][guard-number] + +---- ### guardObject -Use `guardObject()` or `guard.is.object()` to guard the `object` value to be a generic `Obj` type. The return value is a `boolean` value. +Use `guardObject()` or `guard.is.object()` to guard the `value` to be an `object` of a generic `Obj` type. ```typescript -const guardObject: GuardObject = (object: Obj): object is Obj => isObject(object); +const guardObject: GuardObject = (value: Obj): value is Obj => isObject(value); ``` -| Parameter | Type | Description | -|-----------| :---: |-------------| -| object | `Obj` | Generic `Obj` type value to guard. | +| Parameter | Type | Description | +| :-------- | :--------------------: | :------------------------------------ | +| value | `Obj` extends `object` | A generic `Obj` type `value` to guard | + +The **return value** is a `boolean` indicating whether or not the `value` is an `object` of a generic `Obj`. -[Example usage][guard-object] +[Example usage on playground][guard-object] + +---- ### guardObjectKey -Use `guardObjectKey()` or `guard.is.objectKey()` to guard the `object` to be a generic `Obj` type and to contains the `key` property. The return value is a `boolean` value. +Use `guardObjectKey()` or `guard.is.objectKey()` to guard the `value` to be an `object` of a generic `Obj` type that contains the `key` property of the [`Key`](#Key) type. ```typescript -const guardObjectKey: GuardObjectKey = (object: Obj, key: Key): object is Obj => - guardObject(object) ? isString(key) ? key in object : true : false; +const guardObjectKey: GuardObjectKey = (value: Obj, key: Key): value is Obj => + guardObject(value) ? isKey(key) ? key in value : true : false; ``` -| Parameter | Type | Description | -|-------------| :---: |---------------| -| object | `Obj` | Generic `Obj` type `value` that contains the `key` property to guard. | -| key | `Key` | Name of the property that the `object` contains. | +| Parameter | Type | Description | +| :---------- | :-----------: | :------------------------------------------------------------ | +| value | `Obj` | A generic `Obj` type `value` that contains the `key` to guard | +| key | `Key` | A `Key` type name of the property that the `value` contains | + +The **return value** is a `boolean` indicating whether or not the `value` is an `object` of a generic `Obj` containing the `Key`. + +[Example usage on playground][guard-object-key] -[Example usage][guard-object-key] +---- ### guardPrimitive -Use `guardPrimitive()` or `guard.is.primitive()` to guard the `value` to be a generic `Type` from one of the `Primitives`. The return value is a `boolean` value. +Use `guardPrimitive()` or `guard.is.primitive()` to guard the `value` to be the [`Primitive`](#Primitive) from a `type` of the [`Primitives`](#Primitives). ```typescript -const guardPrimitive: GuardPrimitive = (value: Type, type: Primitives): value is Type => isPrimitive(value, type); +const guardPrimitive: GuardPrimitive = + (value: Type, type: Primitives, callback?: ResultCallback): value is Type => + isPrimitive(value, type, callback); ``` -| Parameter | Type | Description | -|-------------| :----------: |--------------| -| value | `Type` | A generic `Type` type `value` to guard. | -| type | `Primitives` | One of the `Primitives` `'boolean'`, `'bigint'`, `'number'`, `'string'`, `'symbol'`, `'undefined'` to check `value`. | +| Parameter | Type | Description | +| :---------- | :--------------------------------------: | :---------------------------------- | +| value | `Type` extends [`Primitive`](#Primitive) | A `Primitive` type `value` to guard | +| type | [`Primitives`](#Primitives) | A `string` type from the [`Primitives`](#Primitives) to check the `value` | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The return value is a `boolean` indicating whether or not the `value` is the [`Primitive`](#Primitive) from the `type`. -[Example usage][guard-primitive] +[Example usage on playground][guard-primitive] + +---- ### guardString -Use `guardString()` or `guard.is.string()` to guard the `value` to be a `string` type. The return value is a `boolean` value. +Use `guardString()` or `guard.is.string()` to guard the `value` to be a `string`. ```typescript -const guardString: GuardString = (value: string): value is string => isString(value); +const guardString: GuardString = (value: string, callback?: ResultCallback): value is string => + isString(value, callback); ``` -| Parameter | Type | Description | -|-------------| :---: |---------------| -| value | `string` | String type value to guard. | +| Parameter | Type | Description | +|-------------| :---------------------------------: | :------------------------------- | +| value | `string` | A `string` type `value` to guard | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | -[Example usage][guard-string] +The return value is a `boolean` indicating whether or not the `value` is a `string`. + +[Example usage on playground][guard-string] + +---- + +### guardSymbol + +Use `guardSymbol()` or `guard.is.symbol()` to guard the `value` to be a `symbol`. + +```typescript +const guardSymbol: GuardSymbol = (value: symbol, callback?: ResultCallback): value is symbol => + isSymbol(value, callback); +``` + +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :----------------------------- | +| value | `symbol` | A `symbol` type `value` to guard | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is a `symbol`. + +---- ### guardType -Use `guardType()` or `guard.is.type()` to guard the `value` to be a generic `Type` type from one of the `Types` type. The return value is a `boolean` value. +Use `guardType()` or `guard.is.type()` to guard the `value` to be the [`Type`](#Type) from a `type` of the [`Types`](#Types). + +```typescript +const guardType: GuardType = (value: T, type: Types, callback?: ResultCallback): value is T => + isType(value, type, callback); +``` + +| Parameter | Type | Description | +| :-------- | :-------------------------: | :------------------------------------------------- | +| value | `T` extends [`Type`](#Type) | A [`Type`](#Type) `value` to guard with the `type` | +| type | [`Types`](#Types) | A `string` or generic [`Constructor`](#Constructor) type from the [`Types`](#Types) to check the `value` | +| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The return value is a `boolean` indicating whether or not the `value` is a `type` from the [`Types`](#Types). + +[Example usage on playground][guard-type] + +---- + +### guardUndefined + +Use `guardUndefined()` or `guard.is.undefined()` to guard the `value` to be `undefined`. + +```typescript +const guardUndefined: GuardUndefined = (value: undefined, callback?: ResultCallback): value is undefined => + isUndefined(value, callback); +``` + +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :---------------------------------- | +| value | `undefined` | A `undefined` type `value` to guard | +| callback | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | + +The **return value** is a `boolean` indicating whether or not the `value` is `undefined`. + +---- + +## Experimental + +### BigIntObject + +```typescript +class BigIntObject { + static set set(value: any) { + PrimitiveObject.bigint = BigInt(value); + } + static get get(): BigInt { + return PrimitiveObject.bigint; + } +} +``` + +---- + +### BooleanObject + +```typescript +class BooleanObject { + /** + * `false` when empty, 0, null, '', false + * `true` when 'true', 'false', 'Su Lin whatever', [], {}, true + */ + static set set(value: any) { + PrimitiveObject.boolean = new Boolean(value); + } + static get get(): Boolean { + return PrimitiveObject.boolean; + } +} +``` + +---- + +### NumberObject + +```typescript +class NumberObject { + static set set(value: any) { + PrimitiveObject.number = new Number(value); + } + static get get(): Number { + return PrimitiveObject.number; + } +} +``` + +---- + +### PrimitiveObject ```typescript -const guardType: GuardType = (value: Type, type: Types): value is Type => isType(value, type); +class PrimitiveObject { + static bigint: BigInt; + static boolean: Boolean; + static number: Number; + static string: String; + static symbol: Symbol; +} ``` -| Parameter | Type | Description | -|-------------| :---: |---------------| -| value | `Type` | A generic `Type ` `value` to guard. | -| type | `Types` | Constructor generic `Type`, `'function'`, `'object'` or one of the `Primitives` `'boolean'`, `'bigint'`, `'number'`, `'string'`, `'symbol'`, `'undefined'` to check `value`. | +---- -[Example usage][guard-type] +### StringObject -## Common Types +```typescript +class StringObject { + static set set(value: any) { + PrimitiveObject.string = new String(value); + } + static get get(): String { + return PrimitiveObject.string; + } +} +``` + +---- + +### SymbolObject + +```typescript +class SymbolObject { + static set set(value: string | number | undefined) { + PrimitiveObject.symbol = Symbol(value); + } + static get get(): Symbol { + return PrimitiveObject.symbol; + } +} +``` + +---- + +### isParam + +Method decorator to check the type and return `undefined` if it's not the same as expected. + +```typescript +function isParam(...param: Array): MethodDecorator { + return (target: Func | object, key: string | symbol, descriptor: any): any => { + const originalMethod = descriptor.value; + + descriptor.value = function(): void { + if (is.array(param) && is.defined(arguments)) { + param.forEach((name: string, index: number) => { + if (is.number(index) && index < arguments.length) { + if (is.defined(arguments[index])) { + switch (name) { + case 'number': + if (is.number(arguments[index]) === false) { + arguments[index] = undefined; + } + break; + case 'object': + if (is.object(arguments[index]) === false) { + arguments[index] = undefined; + } + break; + case 'string': + if (is.string(arguments[index]) === false) { + arguments[index] = undefined; + } + break; + } + } + } + }); + } + const result = originalMethod.apply(this, arguments); + return result; + }; + + return descriptor; + }; +} +``` + +Example usage. + +```typescript +// Example usage +const STRING: any = '!@#$%^&*()abcdefghijklmnoprstuwyz'; +const NUMBER: any = 10304050; +// TestClass +class TestClass { + @isParam('object', 'string', 'number') + public testMethod(object?: any, firstName?: any, age?: any): { object: any, firstName: any, age: any } { + return {object, firstName, age}; + } +} +const resultTRUE = new TestClass().testMethod({firstName: 'NoName'}, STRING, NUMBER); +const resultFALSE = new TestClass().testMethod(NUMBER, {firstName: 'NoName'}, STRING); + +resultTRUE === { + object: {firstName: 'NoName'}, + string: '!@#$%^&*()abcdefghijklmnoprstuwyz', + number: 10304050 +}; + +resultTRUE === { + object: undefined, + string: undefined, + number: undefined +}; + +``` + +---- + +## Common types ### Constructor @@ -777,24 +1685,54 @@ type CycleHook = 'ngAfterContentInit' | 'ngAfterContentChecked' | 'ngAfterViewIn ### Func +Function type. + ```typescript type Func = (...param: any) => any; ``` +### Key + +Name of the `object` property. + +```typescript +type Key = number | string | symbol; +``` + ### Primitive +All [`Primitive`][Primitive] types. + ```typescript -type Primitive = boolean | bigint | null | number | string | symbol | undefined; +type Primitive = bigint | boolean | null | number | string | symbol | undefined; ``` ### Primitives +All [`Primitive`](#Primitive) types as `string`. + +```typescript +type Primitives = 'bigint' | 'boolean' | 'null' | 'number' | 'symbol' | 'string' | 'undefined'; +``` + +### ResultCallback + ```typescript -type Primitives = 'bigint' | 'boolean' | 'number' | 'symbol' | 'string' | 'undefined'; +type ResultCallback = (result: boolean) => boolean; +``` + +### Type + +Main types. + +```typescript +type Type = Func | object | Primitive; ``` ### Types +Main types as `string`. + ```typescript type Types = Constructor | 'function' | 'object' | Primitives; ``` @@ -831,6 +1769,14 @@ How do I know when to release 1.0.0? MIT © angular-package ([license](https://github.com/angular-package/type/blob/main/LICENSE)) +[Array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array +[Boolean]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean +[Function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions +[Number]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number +[Object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object +[Primitive]: https://developer.mozilla.org/en-US/docs/Glossary/Primitive +[String]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String + [new]: https://img.shields.io/badge/-new-red [type-npm-svg]: https://badge.fury.io/js/%40angular-package%2Ftype.svg @@ -859,9 +1805,9 @@ MIT © angular-package ([license](https://github.com/angular-package/type/blob/m [is-array]: https://www.typescriptlang.org/play?jsx=0#code/MYewdgzgLgBFCeAHApgeQGYwLwwBQDcBDAGwFdkAuGQseASiugCcBLMAc2wD4ZUAjAFbJgUAHSImIKFKTJR0gMpRWHUcBLECJcnVERiLYMlwAOADQwAtAEZd0gDIgA7siYBhQhGN0A3ACgEFBgABVYAWxYoFnxkbBg+EBBiZBoYAB94lnY2WAywUmJidJh8sL5XYuY2TgyIeDKk4tIwABNkdDZkFv9A2IBJCABBJiZCeDitMkpqWjpuGCIpmBYIGGHR+AAeGnguf1BIWBX1saoBk-GcTYAVWS5J8iodhgXtWJW1kbGbu+4-GDgsgwD2Qcyw4JgAHJCF94JCYAAyBH-T4bUTHWEgsEQ5TkRHIgGLPFsaA0IwgTAXbA4ph4pEo3oU15LcE4SEgQTCKCQ-bgaAwBTXABKfQAcgBxOKQxxMZBhZaICCkMIAfh5fgO-NFAFUALIAIQAokK4gAmADsvMOMH1qFQ9kNg1FcXQJC8Vv52tFABFDQAxMWG71xZptDpgLoe2CDIVCwYATUFIolVAumyqHB4OAA2tDIRZIXx81DgJCALpRtaxhM6g3G1OwzalcpMLMwbPWCymiwAZgrGr50er8eCIt1fWufQAaoaGxtNqEWBEojE29moRn2MWLRZcbF+5rYAApBSoUUAfSng3s2sNcQA3uhElRrKaewBfD1JOTEEDsXAAAZJmK4oARYGIbLgwESnQvgwAA9PBMCusQXgDpA36iL+-4AbWRpCmByxDJieHGrBPgIUhKFeDA6EQJh2GAba9qOqKhEQWMuDMQ6TrkZRyFusgdEMX+gFer6AaikG7HEZB4n+oG3p8YhAmoUJmoiThMZxomwogTJFy4NpCbQeKylIXuwnJFhokAcZ8akQR4GyZx9mOeZcC0upfKaYB9mjn046TjOBmYv5Y4TtOhoeZZGnWYxAEnmel7XreoWQUlF5Xje0VwSp1FCUAA [is-bigint]: https://www.typescriptlang.org/play?target=7&jsx=0#code/MYewdgzgLgBFCeAHApgeQGYwLwwBQDcBDAGwFdkAuGQseASiugCcBLMAc2wD4ZUAjAFbJgUAHSImIKFKTJR0gMpRWHUcBLECJcnVERiLYMlwAOADQwAtAEZd0gDIgA7siYBhQhGN0A3ACgEFBgASQgAIRZ2YLBYHC0ySmpaOm4YIgSYFggYPki2KH9QSFgsiKiYqlCy6Ni8dPIqGnoqeuRM7Nz2fO4-GDhZDHidbCwcAHJO-LGYADIZ3v6UEExWkfHJmLHC8GgYBQAVACVggDkAcWwYMccmZABbTMQIUjuAfi2-It2TgFUAWTCAFFDpcAEwAdm2xRgYVQqHsgIAgidLugSF4obswsEzqd9pcAJwABiJ4OsBIJoIArAAWcE0okU6xgTEgYhyYggdi4AAGB2O5x5FlKkRquH5pzOdF8MAA9LKYGjiF5Pjs2RyubzfgDgUL2tUYrhtUDDtKfHKFUqVV91aJOdyebD4UiTnqReUoLgnQjkWaLYr0chVZBbfbedjcSd9m7wqLDRG8X75XAmOQ-EA [is-boolean]: https://www.typescriptlang.org/play?target=7&jsx=0#code/MYewdgzgLgBFCeAHApgeQGYwLwwBQDcBDAGwFdkAuGQseASiugCcBLMAc2wD4ZUAjAFbJgUAHSImIKFKTJR0gMpRWHUcBLECJcnVERiLYMlwAOADQwAtAEZd0gDIgA7siYBhQhGN0A3ACgEFBgASQgAIRAQYmQabDwiMkpqWjpuGATyGBYIGD5I6Jp-UEhYbIiomLAqUPKCsDitRKoaeioM5CycvIrYrC4-GDhZDEadbCwcAHJuusmYADJ5gbxlwdxVwaGUEEx28amQQWEoOcWNwb22aBojHZhayv24Jkyzzc3LkpvkO-4hESeynIGzoGwAPmCNut3hdtB0rlBvncHr0JjB0CQvAsljD0nCsl8wLdMH9jk8McQsW8YYEfrt8RMpjNKqccTDRh1Gc9MhC8YlyZjkKD3sKYL4-MVoDAFAAVABKwQAcgBxOKTRxMZAAWyyiAgpC1AH5JkVwFLFQBVACyYQAonK4gAmADsppK91QqHstoAgoq4hSvG6pWFPd6-QB9eUW21xIHIYOwUNe32KiNK2V+tyxnBgZBOe75Sq4QNC4MVUTEEDsXAAA1lCpVtYsZSLNFwDaVyrovhgAHo++jBRKzRWqzXa5abfbm50UWBcFO7XKez5+4PSyPIGPq3Xk+HFbPWz0F-vU6v19zkFuIDuJ2fI9HbUfwm3T2HU1G5TGLwOrze7z3D9IwzGUs2fFtXxPXAHzTUDwN-Qd4z8IA -[is-function]: https://www.typescriptlang.org/play?target=7&jsx=0#code/MYewdgzgLgBFCeAHApgeQGYwLwwBQDcBDAGwFdkAuGQseASiugCcBLMAc2wD4ZUAjAFbJgUAHSImIKFKTJR0gMpRWHUcBLECJcnVERiLYMlwAOADQwAtAEZd0gDIgA7siYBhQhGN0A3ACgEFBgAMVIwYGw8UWjEQiZCAFsqGnpualp-QOQYAEkIUPCoFnBIrTJKdNSsHiJymBYIELDgf2BiT0a3dohGgG8YAA9IgFYfGABfP1BIWAaCkWKwKjz5opKcMvJk2gYYWvJ6xvnuPxg4WQxN5DpsLBwAcnRmtbB7mAAyd9PzlBBMfeydweT0Kizen2+APqMxoRj+TVB6zucCYBwhZyhbGgsOQ8P4QhEtxwynIrXA0BgACFUKh7ABRACCADlIiTkGSZlScgBxHJMgAqkQAnAAGEUAdmsQqFACZhgAWcXykXS6xgDkUpkAVQAspS6QAlSLWGXijWwBT8g187mRe46+AwMCkBJ8VyHe7mkJapluKjHDYDKjO12uXYpNL9JjIKCkJhgQYwADUMFGEym5NgfMtzLcdMiYGQThgXQ6uF8GcgIGIcmIIHYuAABqWeo2LHNnotcC2IHRfDAAPQDlHkSsQau1+u4e6Unl8-n3dv5TvgXCz3kCvtjIcwdAkLxjieiOsNmc0+nMxeHVZd6m0xlMreD4d74gH6bjmvHqf3bV6w1Xh2iJgLgf76gaT47q+77kkeJ7Tpa1pMtygHLsBuCITakEvvuyCHl+8GNsEPpuG214riBxG+thI54R+cE-tm-K5nSqE3quTEsTR0HIEAA -[is-instance]: https://www.typescriptlang.org/play?target=7&jsx=0#code/C4TwDgpgBAwg9gOwM7AE4FcDGw6oDwAq4EAfFALxQIQDuUAFAHTMCGqA5kgFxQsIgBtALoBKCmSKQA3AChQkKAEkki5MD6ZolPAHkARgCsS9AG4sANugg8+IADRQAlmo3XYiFBmy5dhkmPIyM0toRyQofQNZeWhlAGU0Z3YKBmCrG34AoIsrJ3DPJOjiJSRIiGwU3yNTHLdbBwBrCBAAfh4ChHYsqDTQ8MjZTA9gKBidADMUmpCMkBF2xM7xCMNy4EYwVDgcGMYcBNQkxkwLc2mrEUYkc0dNegAOBwBaAEZLnAAZOBoIVBgWJAQegiQbDPIHJI8eKLZKUc51TI8Xp5KAdWFkegxOCTZHkPFQADkcFW2AJUAAZOSerUnC4EJpsSsDGsKVTkc4UK5GRDOmIAD580bERm4-EEtEE0FqPJlbBQ0okkbaSLGXqzRrNNqomHzakhFGRcQyKBCyATeEBMXE5mk1nG00QEU0vGUImKsmU+3sukMyaypX4tBWe0mlrgmH0JpzCiBjAQEMmqBhqO0vW5F2jOOs1I0gFMy4ACwBOhoCAACltIKhQJHmpbKEH44moDxG-aeOMLICpSg8qpOfS3Mp++pB5UVfD1bSB5oePA1F4cPgVbr2f1DEaTWF-VVVbUxJ6Td6Z47JhzR5oYw2s4fw4dOvRz64NlsdsRjsNF7hGAgWABbCB60zKxZBkTBzABcI4jgACYAgpBwgAbygAAPFIXgAJgAdikKAAF8wPg8ICBoOA4MgqBkJAFICS+VAID-JwwCQdA-0lfCZBkAB6LioAANTYRwWD0cwICQMCwTiAgACVFAAOQAcQAfT4gBBD4AFUAFEaLohimJYv8WklCTpTkjSAFkACEtOklT1O0lJsJ7EYrJ0HQPi01S5PszSdMoTtzG7Uzew0uSABEtIAMXkrTwt87SlIIAB1HQUnQBAABMIHGZwIEy2RRJGMLIpiuS4oSrSXKgOIdAsrSYA+VS4jiFJqDoaDYKI4FqpSnRGua1rKHaqASLI7qQU4oZkDgUTGHMOB2EfFQfQgPBOogciEOMPqBpahwNq2pARBBKAeKgQLARC2aIHmxblpHVx1pgzaiOMWr6r2uIDpeo6Ttw8622mpAbrupawkewdnq6yCdtSr6HDGv7TsBuMZCAA -[is-null]: https://www.typescriptlang.org/play?target=7&jsx=0#code/C4TwDgpgBAkgzgOQK4BsVQLxQBQDcCGKSEAXFPgHYgCUmAfFAUdAJZxQWooDcAUAMYB7CnGBRQkAPIAzTDibEylGmVEAnFhQDm9KJIBGAKwj9gAOjBrBwa+AhmbAZWAbtZ-oRR5CxambgoLPwQ2AAcADRQALQAjH42ADKCAO4QagDC+HAh1HxCImJsyGhk8MXoWN7MSlTUZAqs7Jxo9LxQ4nYyVb6YGFgA5M0o-VAAZKNtHZCCsg29A4JGJsAj45NzfVhDecKiUI4AKgBKMAgA4nL9SWoQALZQLGBwSLcA-P07BVAIAKoJCXJtgJdmJfgBZABCAFEjnIAEwAdk+ewhkkkCShAEEEHJpIRssixKj0ViEAB9Y4-KFyFzEQlQYkY7Fk06HbHpalbCDJBmCQQoCCUbB4lDZXLAkT8+woQRabAAA0OJ3O8siRS42CVpzO1FyUAA9PqoCLshK4FKzDK5fLfv9VQ9EBrbQlddwDUbaRAzRarQrwdCjvb1WhsP6Ya73cb8V78uaBZbZQrGaSg46Q8nsRHDVHRTHdj7E-KM+TKVDU+VsMWKUcqVmjSa85L476i2imeTWQd2WW1WmvFXO926znTUA +[is-function]: https://www.typescriptlang.org/play?target=7&jsx=0#code/MYewdgzgLgBFCeAHApgeQGYwLwwBQDcBDAGwFdkAuGQseASiugCcBLMAc2wD4ZUAjAFbJgUAHSImIKFKTJR0gMpRWHUcBLECJcnVERiLYMlwAOADQwAtAEZd0gDIgA7siYBhQhGN0A3ACgEFBgAMVIwYGw8UWjEQiZCAFsqGnpualp-QOQYAEkIUPCoFnBIrTJKdNSsHiJymBYIELDgf2BiT0a3dohGgG8YAA9IgFYfGABfP1BIWAaCkWKwKjz5opKcMvJk2gYYWvJ6xvm0rIxN5DpsLBwAcnRmtbAbmAAyF7hZEEx97Ovb+8Ki2ebz22mybGgNCMXyagPW1zgTAOIJ+9RmUOQMP4QhEVxwynIrXA0BgACFUKh7ABRACCADlIgTkESZmScgBxHJ0gAqkQAnAAGAUAdmsfL5ACZhgAWYXSgXi6xgFkkukAVQAsqSqQAlSLWCXClWwBTcnVc9mRG4a+AwMCkBJ8VyHG7GkJquluKjHDYDKj2x2uXYpNL9JjIKCkJhgQYwADUMFGEymxNgXNN9LcVMiYGQThgXQ6uF8KcgIGIcmIIHYuAABoWerWLHMHotcA2IHRfDAAPQ9xHkUsQcuV6u4G6kjlc7k3Zv5VvgXCTzk8rtjPswdAkLxDkeiKs1icU6n02eHVZt8mU2l0te9-tb4g76bDiv7sc3dVa3VnltwsC4F+2o6neG6Ps+xJ7ge46muadLsr+87-rgsEWqBD7bsgu5vtBtbBB6bhNueC4AfhnroQOWEvlBH7ptymZUohF6LnRDEUeBVGQThY61sWaTDERf4LIufHVImFFMkAA +[is-instance]: https://www.typescriptlang.org/play?target=7&jsx=0&module=6#code/PTAEBUE8AcFMDoBQAXGtQGED2A7AzsgE4CuAxsloQDxRwB8oAvKDrAO6gAU8PAhoQHM8ALlC8ckANoBdAJRMGtWAG4UaUAEk8AMWI5yAS1xMuAN14AbYrFHjI8xg3NX0BvFx7xo-XgFtbEg4MdqqocJp4GvjI4qTozFQA8gBGAFZ0nM7WAZAANKAG0bE2mLgEJOSUSWl0QaBZru4pqaHqWgDKRIUCJpmW2WKBCvX9jaDl3a3hWs2w5CbV6X0uOfkA1rCQAPyiEzgCdQ0FTWmqIKC6+shGOEikZcigYbCJAGa9DTmyu137w7PkLyELAUZ7wCidQjdeCkSwWZbWWTwPAWAxxTgADnyAFoAIxIigAGSwbFghAwvDwsE4slU92ix0uhlwoi0TOuxmYCJKdm+Ixcxw8PG8hD8X2GdmGzze3IcjGYAHJXnpmTgFaAAGQap5oLDvI7yxXKq43dVa-nWApFfSwPUXFUcnBMeVPEjoc1HQoEYp2gGPQ2u6x0h7HSHdVl4MN-LmfQb2USe9x7HqOLjPO0Gl0KrBpObIM3az3WuK+3PzD2jK3em12qMHUAAHwbOrgGcrAYVyYVwYZbj9Eb9C2aJhzqTzGVjdnWmx241+BwTlbcoGHjkQoDTaBlDTlitHeYLLdt+vbWf35EPRerJfeg4DRER643oC2ofnnA29ifz5foE-VotWBv1AUQHyAjdRFeSwqR7Ahjiia8Si0BCYhtIcam5VYq1QuJRGwaIKgoahmlqRcBWXVc6CfPsy2QRYJ1GeQtmAtx2RuTgvRw2AmOAjcry4u1OOKZ1mDAzVtTcOsOOLBBoGBUE0BhB5CMoeAcD8bjgMg6DwJA0AoIsGDEEQUgLEpdx2iwXxYAwMy8HcABvUAAA8TFxAAmAB2ZRQAAX1AUzzIgNgsFsoKnMgEwFWJQhYF8ApoDwYhfG7PzjPOAA1fgDF4ZILFgPATJDdpwAAJQ0AA5ABxAB9DKAEFCQAVQAUSimK4oSpLfC2VL6TgiqmoAWQAIRa0q6sa1qTC8nz+seEbEkSQkWvqirJuatrmAMmCApDJqKoAERa7RKpaw6NtamrwAAdUSEw9AAE1gV5ClgR7VHyx4DuO06KvOy6Wtgx52kSIaWowQl6vadoTFYDhLOssL7JpOaQ1uxJIeh2HmHh4LQrsvBUeM-qsHy+ALCwAQOMiGSqERmzCYyDGsZh-IGeRvBZFpUBzh2oDSfJynqbcFDinpqzGfMjJQfB1n2nZyXOe5nzzjAor8DJhBhZpsWbQlpGmc4FmobZ-HlZ5tW3UQIA +[is-null]: https://www.typescriptlang.org/play?target=7&jsx=0&ssl=11&ssc=21&pln=11&pc=33#code/C4TwDgpgBAkgzgOQK4BsVQLxQBQDcCGKSEAXFPgHYgCUmAfFAUdAJZxQWooDcAUAMYB7CnGBRQkAPIAzTDibEylGmVEAnFhQDm9KJIBGAKwj9gAOjBrBwa+AhmbAZWAbtZ-oRR5CxambgoLPwQ2AAcADRQALQAjH42ADKCAO4QagDC+HAh1HxCImJsyGhk8MXoWN7MSlTUZAqs7JxouhIQMlW+mBhYAOTNKL1QAGTD4naCsg3dfYJGJsBDo4w+0D1YA3nColCOACoASjAIAOJyvUlqEAC2UCxgcEjXAPy9WwVQCACqCQlymwJtmJvgBZABCAFEDnIAEwAdneOzBkkkCQhAEEEHJpIRsoixMjURiEAB9Q5fCFyFzEfFQQlozEk477THpSkbCDJOmCQQoCCUbA4lDZXKAkS8+woQRabAAA32R1OssiRS42AVxxO1FyUAA9LqoELsmK4BKzFKZbLvr9lXdEGrrQltdw9QbqRATWaLXLQZCDrbVWhsL6oc7XYbcR78qa+ebpXL6cSA-ag4nMWH9RHhVHtl747K06TyRDk+VsIWyQcKRmDUac+LY96CyiGaTmXtWSWVSmvBX252a1njUA [is-number]: https://www.typescriptlang.org/play?target=7&jsx=0#code/C4TwDgpgBAkgzgOQK4FsBGEBOUC8UAUAbgIYA2SEAXFMQHYgCUuAfFCedAJZxS2oaYA3ACgAxgHtacYFFCQA8gDNcBdhWp1G1aZk60A5iyjy0AKwijgAOjCZxwe+AhWHAZWC6DV0WVJEyFAxWcKScohD4ABwANFAAtACMQQ4AMuIA7lgAwsRwEQwiElIy3MjoWNTwZQIq-hwa9AzUalw8fOXYOMzCULJOSnWBuDh4AOTtAqNQAGTTPQTzvdwAYnqcwBEtTCN4HhQzc729+ItHLVB60nTh4srVWMN4imR5B6e955fA1xC3xmYWGQ7KDPUivWbvPqQP7nYHjfhYUanBinAA+qNOJyORzkv2UsJGUFG4gBlimEOxHwCXGKPz+906hL20AplM+tNoN2UJnMlkeskwFGR8wKYkk0igACEYABxGAIAAqKgAnAAGVUAdgSyuVACYAKwAFg1htVOoStEK4pkkvk8hSAFEAIIIFSgvJW4pQBAAVQAspKHQAlFS6jWeiW+gPBgD68tcCpdWQdKloEHS3oRmHw+tFRQlCaD8plKlGaUwEBQFzAcFQAH5RhHxKRnKRxPp8AADaVyxWd2KlLP4HvyhUMApQAD0k5BLwgYqkzdb7a7tvtzoQ-YuiCHa8dLvHginM-d8-zS6sbY7najgaDW8HHXwt+Dh+PAqF55bl5XN-9d7jBAEyTB0Hx3J8XyDQDgIQZM32nD8z3FC8ry7QtizAhl8HQhAZXgk852EYQgA [is-object]: https://www.typescriptlang.org/play?noUncheckedIndexedAccess=true&target=7&jsx=0#code/JYOwLgpgTgZghgYwgAgPICMBWEFgJLjTxLIDeyAHgFzIgCuAtutANzIC+AUKJLIiqjAALaBmy4yyAOY16TVh05gAngAcUAMTogEyALzIAFADpTquFDgMacEMoCU+gHzJbylkrUo8AZzE4wfWQAHjEnQwA3OAAbOggbOwAaZABrCGUAfhofMChQKUc9FyjYlGAfNCwPFXVkXwA5AHswerpo6KDImLiabRSQRoB3EEKXdEbG6IhbDwRGkBzkcqaWtuiaBubW9s6SnuQ+geH7GnHJ6ZBnTmRkGohUGC7SxwBCPQMAcnp2j+QAMj+12QexQbwM32is3mizuD123XirjsJ2QOTyICkzkq4jAxlUUGazS8xjAjQAyrl8sYEDFok84vZjD5osAkIYABzJAC0AEZGaSADJDaAAYTgPgghnsUIWgXKFPRmIM9MRbhRIKWFTR+Sxd0aMGBCP072QH21GI+MsW5X8uA2fiwASCoSw4RBCWUyTSmWylIx6qN5WxVxusMeIMKJo+jUduF+AKBeoNGvenxjOPjgJuGtAOVsSH12KdqduUDiQJuGU1Cvyhm9kYMuXLNxbyCr3qWlxTJqbKABRg14uxjKE4tQwwACgT1FAVHX0g3S82WzRe0CaPBohKPEDOAhouKKiLoU3cI0oCKDz4KuQKEEAKxsLhzWXIEWoepkgAqACUAKoil+qA-gA+iKAoAIJkmSQQgBAgxvieZZnheV4+FKVqBAAUmSH4gagABCWEAKKATQtr4IQfAkAYt40AAzIoL6LBof71CKNBaDonTULQjDMFAKJuFiFCYcgBGoKgArERB9RBL2O7MecxjRI0UiGAABsesrIaSqGHhpyQ2rGYDBNpaJ0Chl6HuE76fr+AFAaB4FQWS9jSsgAD0nlLhAe7QspqnqRpOF4YRJGAYZmoUaEwiiCZ4ShfU+FEaRX7uWw3m+f5CyBWpmmsexUXGTiwRcQg4SFSKGVeT5m4SjlPh5cFdnfv+gHAWBkHQQA2hQAC6xUOqV5mnnp1nXrZH5tY5nUudByQfBQHw1Vla5KVMKn5SFuHJeFaU9cog1GcNASxSIUAUYlu0pRFX6LcoK0eVl9V+RtEBbcFVV9cd0UmWV2gVYYVWLctq11TEDXvZ9mkSVJMn1ENMVuOEcPSbJ4PIK9nBAA [is-primitive]: https://www.typescriptlang.org/play?target=7&jsx=0#code/C4TwDgpgBACgTgSwLYOAgbhAzlAvFAcgCMEBzBAO2AKgB9CiB7RgGwgEMKb6CKBXJEQhxuhLCEGtRBLMEQVS0vhQAmEAGaUIKggG4AUPtCQoASSwAhZm054oACnTsWfCAC4onEAEo8APignF2gEHCZWDgoDY2hzADkBITg7R2dXDy9fXACg1yhQqH5BYWjwWKx4ZFQMaHwAHgAVMr9U4IyKEAAaKBiPSpQ0TCwsnLSQnCbIUpNzAGU5SlIU3PdPDpHAsfycWXlSafLZiSYWZbH2n39N4O2ocUkWA7MsAFVVDS0VM7a1y+zrvIFZRqTQUbQGfQAY0YFFk2wsZFMVG+6V+3g8K1uJHIyP+MUY6gBtVw+GIZEo1AM0NhwHh1kiHnMVgitnwrVRmQxWwK4RsFCu7JCNM4kIgBKgzL5UAAZNKiflhRRReKAPJEABWEEhwF8tHo9kFeBJPTgeT18pJ+HUziwEF8sp6ZXFmMtDHpnAI3ipMLhoQSxTgjKw-qSKNWnPlBSKobxTsJLuNvESwhoAH5tgAxSioCCC3xcm6UWQisWEkPCGVyzFF4Al1UarXAb007bzPZBtuLMMXdGRnYLBQC-HxraugiMBvamgO6uK5WEtWa7WVyNz0tQTsKXX0YcWxO7RZ6KE+2mhI4PDvHVjdtEFwE7K+nWOQZ2j-ePo-U32vd6g7RBt4QU+G8I2rHBgQ+MEvn+BN8Agv8vgdXdYMIeDPiPY8W1CfpqkwIMcMGWooEaZpBQubpelgRABhqYY73GKBJlqAIAG99CgfJCXsM8B1IewYm8Xw2I4jisAAd1QSEAAsHAEqBhJEjjIXYW0GHJKgCA8OAIGAPg4H5UIEVIJFgDzAxFKUlToGId0uC0nS9IMyxbLM9iLOU1SkwDTSoG03T9O2cs4FciyoA86yDwUHy-Mc1teJC9yrLED97P8pzzxOBLFPC1Df3Q1LYtCQDIO0LKoAAXzcyqOJigLrRYW0DHKiEv1pCwVRVAAZABRABBOI7HqxrMLhCxTAAcVMOIGjsABOAAGeaAHYAEZZtmgAmABWAAWJadvm9aVqiEbaTiF4AFkLG6gAlOwVo2pbmzhWYGhuqbxrsAgLpAQpk2SUJPxPKAXjiAARbqMym7qwbsNCoOe2lZgATSurq7Ay1h7AIeHtE9Z6IgAOhYRg+IAAzGybprJ7psOo3CIDqbEKRaSmpoaboyRxahBN0KAAHp+ZNVwRqJknyfarq+riGntgImo6ki0hWY6nr+s53lIk9L0BaFuQRa-MXSfsMnzqu27ZbpqpCLqaNhBaM3rpuzm7ZEXndeFiBRbYYnjbJ173ricbLYqembaVloA4+zmle1vnBc972IF98mUbRzqQ-lzBFcfSPUfazqY4-d2E-1r3DZ98WTdBiGobiGHM7DhXcZUFoa8h6Gwc5lu449svDAr5Oq9Ny6ncb62FeZqgHdH26NfUnmdYToby59I3ycdi3adDifs4j+xN+dsReN75ebVX2F15NqOg-Hmjs81zhI7e6O3RZLgS6Flek5T6+X9v7eWdGau2foHcaLt-qny-uffQQA From e7e7389a2fad838f734af3bbf255821e5575d8f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 3 May 2021 19:52:13 +0200 Subject: [PATCH 198/201] chore(guardSymbol): remove import --- packages/type/src/guard/lib/guard-symbol.func.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/type/src/guard/lib/guard-symbol.func.ts b/packages/type/src/guard/lib/guard-symbol.func.ts index 17eb6ddc..5247daff 100644 --- a/packages/type/src/guard/lib/guard-symbol.func.ts +++ b/packages/type/src/guard/lib/guard-symbol.func.ts @@ -1,6 +1,5 @@ // Function. import { isSymbol } from '../../is/lib/is-symbol.func'; -import { resultCallback } from '../../lib/result-callback.func'; // Type. import { GuardSymbol } from '../type/guard-symbol.type'; import { ResultCallback } from '../../type/result-callback.type'; From 3608fc8d40f33cf63135657da2ab4113ceac79e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 3 May 2021 19:53:47 +0200 Subject: [PATCH 199/201] chore(package): update --- packages/type/package-lock.json | 4 ++-- packages/type/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/type/package-lock.json b/packages/type/package-lock.json index 3cd4f911..964fc7dc 100644 --- a/packages/type/package-lock.json +++ b/packages/type/package-lock.json @@ -1,12 +1,12 @@ { "name": "@angular-package/type", - "version": "3.1.2", + "version": "3.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@angular-package/type", - "version": "3.1.2", + "version": "3.2.0", "license": "MIT", "dependencies": { "tslib": "^2.1.0" diff --git a/packages/type/package.json b/packages/type/package.json index 81280e25..f2a7df18 100644 --- a/packages/type/package.json +++ b/packages/type/package.json @@ -1,6 +1,6 @@ { "name": "@angular-package/type", - "version": "3.1.2", + "version": "3.2.0", "description": "Common types, type guards and type checkers.", "author": "Angular Package (https://wvvw.dev)", "homepage": "https://github.com/angular-package/type#readme", From 38bcb42635e3e29b512cfd4fd4afcb88a16c898a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 3 May 2021 20:03:54 +0200 Subject: [PATCH 200/201] docs(README.md): fix for npm --- README.md | 270 ++++++++++++++++++++-------------------- packages/type/README.md | 270 ++++++++++++++++++++-------------------- 2 files changed, 270 insertions(+), 270 deletions(-) diff --git a/README.md b/README.md index fac015f0..bf9b14b6 100644 --- a/README.md +++ b/README.md @@ -98,52 +98,52 @@ import { Constructor, CycleHook, Func, Key, Primitive, Primitives, ResultCallbac * Checks if * **any** value is - * an `Array` of any type with [`isArray()`](#isArray). - * a `bigint` type with [`isBigInt()`](#isBigInt). - * a `boolean` with [`isBoolean()`](#isBoolean). - * an `object`type and instance of [`Boolean`][Boolean] and [`Object`][Object] with [`isBooleanObject()`](#isBooleanObject). - * a `boolean` type not an instance of [`Boolean`][Boolean] and [`Object`][Object], and equal to `true` or `false` with [`isBooleanType()`](#isBooleanType). - * a `function` with [`isFunction()`](#isFunction). - * a generic type `instance` with [`isInstance()`](#isInstance). - * a [`Key`](#Key) type with [`isKey()`](#isKey). - * a `null` with [`isNull()`](#isNull). - * a `number` with [`isNumber()`](#isNumber). - * an `object` type and instance of [`Number`][Number] and [`Object`][Object] with [`isNumberObject()`](#isNumberObject). - * a `number` type and **not** instance of [`Number`][Number] and [`Object`][Object] with [`isNumberType()`](#isNumberType). - * a generic type `object` with [`isObject()`](#isObject). - * an `object` with its own specified [`Key`](#Key) with [`isObjectKey()`](#isObjectKey). + * an `Array` of any type with [`isArray()`](#isarray). + * a `bigint` type with [`isBigInt()`](#isbigint). + * a `boolean` with [`isBoolean()`](#isboolean). + * an `object`type and instance of [`Boolean`][boolean] and [`Object`][object] with [`isBooleanObject()`](#isbooleanobject). + * a `boolean` type not an instance of [`Boolean`][boolean] and [`Object`][object], and equal to `true` or `false` with [`isBooleanType()`](#isbooleantype). + * a `function` with [`isFunction()`](#isfunction). + * a generic type `instance` with [`isInstance()`](#isinstance). + * a [`Key`](#Key) type with [`isKey()`](#iskey). + * a `null` with [`isNull()`](#isnull). + * a `number` with [`isNumber()`](#isnumber). + * an `object` type and instance of [`Number`][Number] and [`Object`][object] with [`isNumberObject()`](#isnumberobject). + * a `number` type and **not** instance of [`Number`][Number] and [`Object`][object] with [`isNumberType()`](#isnumbertype). + * a generic type `object` with [`isObject()`](#isobject). + * an `object` with its own specified [`Key`](#Key) with [`isObjectKey()`](#isobjectkey). * a one of the primitive `boolean`, `bigint`, `number`, `string` with [`isPrimitive()`](#isPrimitive). - * a `string` with [`isString()`](#isString). - * an `object` type and instance of [`String`][String] and [`Object`][Object] with [`isStringObject()`](#isStringObject). - * a `string` type and **not** instance of [`String`][String] and [`Object`][Object] with [`isStringType()`](#isStringType). + * a `string` with [`isString()`](#isstring). + * an `object` type and instance of [`String`][string] and [`Object`][object] with [`isStringObject()`](#isstringobject). + * a `string` type and **not** instance of [`String`][string] and [`Object`][object] with [`isStringType()`](#isstringtype). * a `symbol` with [`isSymbol()`](#isSymbol). - * a generic type instance, `function`, `object` or primitive type with [`isType()`](#isType). - * a `undefined` type with [`isUndefined()`](#isUndefined). + * a generic type instance, `function`, `object` or primitive type with [`isType()`](#istype). + * a `undefined` type with [`isUndefined()`](#isundefined). * an **unknown** value is - * defined with [`isDefined()`](#isDefined). + * defined with [`isDefined()`](#isdefined). * an **unknown** value is **not** a - * `boolean` type with [`isNotBoolean()`](#isNotBoolean) - * `function` type with [`isNotFunction()`](#isNotFunction) - * `null` type with [`isNotNull()`](#isNotNull) - * `number` type with [`isNotNumber()`](#isNotNumber) - * `string` type with [`isNotString()`](#isNotString) - * `undefined` type with [`isNotUndefined()`](#isNotUndefined) + * `boolean` type with [`isNotBoolean()`](#isnotboolean) + * `function` type with [`isNotFunction()`](#isnotfunction) + * `null` type with [`isNotNull()`](#isnotnull) + * `number` type with [`isNotNumber()`](#isnotnumber) + * `string` type with [`isNotString()`](#isnotstring) + * `undefined` type with [`isNotUndefined()`](#isnotundefined) * Guard the value to be - * an [`Array`][Array] of a generic type with [`guardArray()`](#guardArray). - * a `bigint` with [`guardBigInt()`](#guardBigInt). - * a `boolean` with [`guardBoolean()`](#guardBoolean). - * a `function` type with [`guardFunction()`](#guardFunction). - * an instance with [`guardInstance()`](#guardInstance). - * a `null` with [`guardNull()`](#guardNull). - * a [`Key`](#Key) with [`guardKey()`](#guardKey). - * a `number` with [`guardNumber()`](#guardNumber). - * an `object` of a generic type with [`guardObject()`](#guardObject). - * an `object` of a generic type that contains `key` with [`guardObjectKey()`](#guardObjectKey). - * a one of the [`Primitives`](#Primitives) with [`guardPrimitive()`](#guardPrimitive). - * a `string` with [`guardString()`](#guardString). - * a `symbol` with [`guardSymbol()`](#guardSymbol). - * a generic type from one of the [`Types`](#types) type with [`guardType()`](#guardType). - * `undefined` with [`guardUndefined()`](#guardUndefined). + * an [`Array`][array] of a generic type with [`guardArray()`](#guardarray). + * a `bigint` with [`guardBigInt()`](#guardbigint). + * a `boolean` with [`guardBoolean()`](#guardboolean). + * a `function` type with [`guardFunction()`](#guardfunction). + * an instance with [`guardInstance()`](#guardinstance). + * a `null` with [`guardNull()`](#guardnull). + * a [`Key`](#Key) with [`guardKey()`](#guardkey). + * a `number` with [`guardNumber()`](#guardnumber). + * an `object` of a generic type with [`guardObject()`](#guardobject). + * an `object` of a generic type that contains `key` with [`guardObjectKey()`](#guardiobjectkey). + * a one of the [`Primitives`](#primitives) with [`guardPrimitive()`](#guardprimitive). + * a `string` with [`guardString()`](#guardstring). + * a `symbol` with [`guardSymbol()`](#guardsymbol). + * a generic type from one of the [`Types`](#types) type with [`guardType()`](#guardtype). + * `undefined` with [`guardUndefined()`](#guardundefined). ## How angular-package understands @@ -159,20 +159,20 @@ Guard ---- * [Installation](#installation) -* [resultCallback](#resultCallback) +* [resultCallback](#resultcallback) * [Check](#check) * [are](#are) * [is](#is) - * [isNot](#isNot) + * [isNot](#isnot) * [Guard](#guard) * [Experimental](#Experimental) - * [BigIntObject](#BigIntObject) - * [BooleanObject](#BooleanObject) - * [NumberObject](#NumberObject) - * [PrimitiveObject](#PrimitiveObject) - * [StringObject](#StringObject) - * [SymbolObject](#SymbolObject) - * [isParam()](#isParam) + * [BigIntObject](#bigintobject) + * [BooleanObject](#booleanobject) + * [NumberObject](#numberobject) + * [PrimitiveObject](#primitiveobject) + * [StringObject](#stringobject) + * [SymbolObject](#symbolobject) + * [isParam()](#isparam) * [Common types](#common-types) * [Git](#git) * [Commit](#commit) @@ -280,7 +280,7 @@ const is: Is = { ### isArray -Use `isArray()` or `is.array()` to check if **any** `value` is an [`Array`][Array], [`Array`][Array] instance, and `object` type. +Use `isArray()` or `is.array()` to check if **any** `value` is an [`Array`][array], [`Array`][array] instance, and `object` type. ```typescript const isArray: IsArray = (value: any, callback: ResultCallback = resultCallback): value is Array => @@ -295,9 +295,9 @@ const isArray: IsArray = (value: any, callback: ResultCallback = resultCal | Parameter | Type | Description | | :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | -The **return value** is a `boolean` indicating whether or not the `value` is an [`Array`][Array]. +The **return value** is a `boolean` indicating whether or not the `value` is an [`Array`][array]. ```typescript // Example usage @@ -324,7 +324,7 @@ const isBigInt: IsBigInt = (value: any, callback: ResultCallback = resultCallbac | Parameter | Type | Description | | :-------- | :---: | :---------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `bigint`. @@ -343,7 +343,7 @@ isBigInt(BIGINT); // true ### isBoolean -Use `isBoolean()` or `is.boolean()` to check if **any** `value` is a `boolean` type not instance of [`Boolean`][Boolean] and [`Object`][Object] or `object` type instance of [`Boolean`][Boolean] and [`Object`][Object]. +Use `isBoolean()` or `is.boolean()` to check if **any** `value` is a `boolean` type not instance of [`Boolean`][boolean] and [`Object`][object] or `object` type instance of [`Boolean`][boolean] and [`Object`][object]. ```typescript const isBoolean: IsBoolean = (value: any, callback: ResultCallback = resultCallback): value is boolean => @@ -353,7 +353,7 @@ const isBoolean: IsBoolean = (value: any, callback: ResultCallback = resultCallb | Parameter | Type | Description | | :---------| :---: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `boolean`. @@ -372,7 +372,7 @@ isBoolean(BOOLEAN_INSTANCE); // true ### isBooleanObject -Use `isBooleanObject()` or `is.booleanObject()` to check if **any** `value` is an `object` type and instance of [`Boolean`][Boolean] and [`Object`][Object]. +Use `isBooleanObject()` or `is.booleanObject()` to check if **any** `value` is an `object` type and instance of [`Boolean`][boolean] and [`Object`][object]. ```typescript const isBooleanObject: IsBooleanObject = (value: any, callback: ResultCallback = resultCallback): value is boolean => @@ -382,9 +382,9 @@ const isBooleanObject: IsBooleanObject = (value: any, callback: ResultCallback = | Parameter | Type | Description | | :---------| :---: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | -The **return value** is a `boolean` indicating whether or not the `value` is a [`Boolean`][Boolean] instance. +The **return value** is a `boolean` indicating whether or not the `value` is a [`Boolean`][boolean] instance. ```typescript // Example usage @@ -399,7 +399,7 @@ isBooleanObject(BOOLEAN_INSTANCE); // true ### isBooleanType -Use `isBooleanType()` or `is.booleanType()` to check if **any** `value` is a `boolean` type not an instance of [`Boolean`][Boolean] and [`Object`][Object], and equal to `true` or `false`. +Use `isBooleanType()` or `is.booleanType()` to check if **any** `value` is a `boolean` type not an instance of [`Boolean`][boolean] and [`Object`][object], and equal to `true` or `false`. ```typescript const isBooleanType: IsBooleanType = (value: any, callback: ResultCallback = resultCallback): value is boolean => @@ -414,7 +414,7 @@ const isBooleanType: IsBooleanType = (value: any, callback: ResultCallback = res | Parameter | Type | Description | | :---------| :---: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `boolean` type. @@ -441,7 +441,7 @@ const isDefined: IsDefined = (value: unknown, callback: ResultCallback = resultC | Parameter | Type | Description | | :-------- | :-------: | :---------------------------- | | value | `unknown` | An `unknown` `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is defined, not `undefined`. @@ -458,7 +458,7 @@ isDefined(defined); // false ### isFunction -Use `isFunction()` or `is.function()` to check if **any** `value` is a `function` type, an instance of [`Function`][Function] and [`Object`][Object]. +Use `isFunction()` or `is.function()` to check if **any** `value` is a `function` type, an instance of [`Function`][function] and [`Object`][object]. ```typescript const isFunction: IsFunction = (value: any, callback: ResultCallback = resultCallback): value is Func => @@ -473,7 +473,7 @@ const isFunction: IsFunction = (value: any, callback: ResultCallback = resultCal | Parameter | Type | Description | | :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `function`. @@ -514,7 +514,7 @@ const isInstance: IsInstance = ( | :-------- | :--------------------------------: | :---------- | | value | `any` | Any `value` to compare with the `instance` | | instance | [`Constructor`](#Constructor) | A generic `Obj` [`Constructor`](#Constructor) type to create an `instance` to compare with the `value` | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is an `instance` of a generic `Obj`. @@ -547,7 +547,7 @@ const isKey: IsKey = (value: any, callback: ResultCallback = resultCallback): va | Parameter | Type | Description | | :-------- | :---: |:-------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a [`Key`](#Key). @@ -583,7 +583,7 @@ const isNull: IsNull = (value: any, callback: ResultCallback = resultCallback): | Parameter | Type | Description | | :-------- | :---: |--------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is `null`. @@ -608,7 +608,7 @@ isNull(NUMBER); // false ### isNumber -Use `isNumber()` or `is.number()` to check if **any** `value` is a `number` type not an instance of [`Number`][Number] and [`Object`][Object] or `object` type instance of [`Number`][Number] and [`Object`][Object]. +Use `isNumber()` or `is.number()` to check if **any** `value` is a `number` type not an instance of [`Number`][Number] and [`Object`][object] or `object` type instance of [`Number`][Number] and [`Object`][object]. ```typescript const isNumber: IsNumber = (value: any, callback: ResultCallback = resultCallback): value is number => @@ -618,7 +618,7 @@ const isNumber: IsNumber = (value: any, callback: ResultCallback = resultCallbac | Parameter | Type | Description | | :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `number`. @@ -628,7 +628,7 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` ### isNumberObject -Use `isNumberObject()` or `is.numberObject()` to check if **any** `value` is an `object` type and instance of [`Number`][Number] and [`Object`][Object]. +Use `isNumberObject()` or `is.numberObject()` to check if **any** `value` is an `object` type and instance of [`Number`][Number] and [`Object`][object]. ```typescript const isNumberObject: IsNumberObject = (value: any, callback: ResultCallback = resultCallback): value is number => @@ -638,7 +638,7 @@ const isNumberObject: IsNumberObject = (value: any, callback: ResultCallback = r | Parameter | Type | Description | | :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a [`Number`][Number] instance. @@ -677,7 +677,7 @@ isNumberObject(NUMBER_NEW_INSTANCE); // true ### isNumberType -Use `isNumberType()` or `is.numberType()` to check if **any** `value` is a `number` type not an instance of [`Number`][Number] and [`Object`][Object]. +Use `isNumberType()` or `is.numberType()` to check if **any** `value` is a `number` type not an instance of [`Number`][Number] and [`Object`][object]. ```typescript const isNumberType: IsNumberType = (value: any, callback: ResultCallback = resultCallback): value is number => @@ -687,7 +687,7 @@ const isNumberType: IsNumberType = (value: any, callback: ResultCallback = resul | Parameter | Type | Description | | :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `number`. @@ -726,7 +726,7 @@ isNumberType(NUMBER_NEW_INSTANCE); // false ### isObject -Use `isObject()` or `is.object()` to check if **any** `value` is an `object` of a generic `Obj` type and [`Object`][Object] instance with the possibility of containing the `key`. +Use `isObject()` or `is.object()` to check if **any** `value` is an `object` of a generic `Obj` type and [`Object`][object] instance with the possibility of containing the `key`. ```typescript const isObject: IsObject = (value: any, key?: Key): value is Obj => @@ -804,7 +804,7 @@ const OBJECT_ONE: ObjectOne = { 1030405027: 'key is number', 5: 'key is also number', [NUMBER]: 'key is number', - [STRING]: 'key is string', + [string]: 'key is string', [SYMBOL_NUMBER]: 'key is symbol number', [SYMBOL_STRING]: 6, x: 3000 @@ -849,7 +849,7 @@ const isObjectKey: IsObjectKey = ( | :-------- | :------------------------------: | :---------------------------------------------------- | | value | `any` | Any `value` to check if it contains a specified `key` | | key | [`Key`](#key) \| [`Key`](#Key)[] | A [`Key`](#Key) type or an array of [`Key`](#Key) type to check in the `value` | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is an `object` with its own specified keys. @@ -857,7 +857,7 @@ The **return value** is a `boolean` indicating whether or not the `value` is an ### isPrimitive -Use `isPrimitive()` or `is.primitive()` to check if **any** `value` is the [`Primitive`](#Primitive) type from a `type` of the [`Primitives`](#Primitives) type. +Use `isPrimitive()` or `is.primitive()` to check if **any** `value` is the [`Primitive`](#primitive) type from a `type` of the [`Primitives`](#primitives) type. ```typescript const isPrimitive: IsPrimitive = ( @@ -883,10 +883,10 @@ const isPrimitive: IsPrimitive = ( | Parameter | Type | Description | | :-------- | :-------------------------: | :------------------------------------------------------------------------ | | value | `any` | Any `value` to check if it's a `Primitive` from the `type` | -| type | [`Primitives`](#Primitives) | A `string` type from the [`Primitives`](#Primitives) to check the `value` | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| type | [`Primitives`](#primitives) | A `string` type from the [`Primitives`](#primitives) to check the `value` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | -The **return value** is a `boolean` indicating whether or not the `value` is a `type` from the [`Primitives`](#Primitives). +The **return value** is a `boolean` indicating whether or not the `value` is a `type` from the [`Primitives`](#primitives). [Example usage on playground][is-primitive] @@ -894,7 +894,7 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` ### isString -Use `isString()` or `is.string()` to check if **any** `value` is a `string` type, not instance of [`Object`][Object] and [`String`][String] or `object` type and instance of [`String`][String] and [`Object`][Object]. +Use `isString()` or `is.string()` to check if **any** `value` is a `string` type, not instance of [`Object`][object] and [`String`][string] or `object` type and instance of [`String`][string] and [`Object`][object]. ```typescript const isString: IsString = (value: any, callback: ResultCallback = resultCallback): value is string => @@ -904,7 +904,7 @@ const isString: IsString = (value: any, callback: ResultCallback = resultCallbac | Parameter | Type | Description | | :-------- | :---------------------------------: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `string`. @@ -912,7 +912,7 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` ### isStringObject -Use `isStringObject()` or `is.stringObject()` to check if **any** `value` is an `object` type and instance of [`String`][String] and [`Object`][Object]. +Use `isStringObject()` or `is.stringObject()` to check if **any** `value` is an `object` type and instance of [`String`][string] and [`Object`][object]. ```typescript const isStringObject: IsStringObject = (value: any, callback: ResultCallback = resultCallback): value is string => @@ -922,15 +922,15 @@ const isStringObject: IsStringObject = (value: any, callback: ResultCallback = r | Parameter | Type | Description | | :-------- | :---------------------------------: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | -The **return value** is a `boolean` indicating whether or not the `value` is a [`String`][String] instance. +The **return value** is a `boolean` indicating whether or not the `value` is a [`String`][string] instance. ---- ### isStringType -Use `isStringType()` or `is.stringType()` to check if **any** `value` is a `string` type and **not** instance of [`String`][String] and [`Object`][Object]. +Use `isStringType()` or `is.stringType()` to check if **any** `value` is a `string` type and **not** instance of [`String`][string] and [`Object`][object]. ```typescript const isStringType: IsStringType = (value: any, callback: ResultCallback = resultCallback): value is string => @@ -940,7 +940,7 @@ const isStringType: IsStringType = (value: any, callback: ResultCallback = resul | Parameter | Type | Description | | :-------- | :---------------------------------------------------------------------: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `string`. @@ -958,7 +958,7 @@ const isSymbol: IsSymbol = (value: any, callback: ResultCallback = resultCallbac | Parameter | Type | Description | | :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `symbol`. @@ -968,7 +968,7 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` ### isType -Use `isType()` or `is.type()` to check if **any** `value` is the [`Type`](#Type) from a `type` of the [`Types`](#Types) type. +Use `isType()` or `is.type()` to check if **any** `value` is the [`Type`](#type) from a `type` of the [`Types`](#types) type. ```typescript const isType: IsType = (value: any, type: Types, callback: ResultCallback = resultCallback): value is T => { @@ -998,10 +998,10 @@ const isType: IsType = (value: any, type: Types, callback: Re | Parameter | Type | Description | | :-------- | :------------------: | :-------------------------------------------------- | | value | `any` | Any `value` to check if its type is from the `type` | -| type | [`Types`](#Types) | A `string` or generic `Constructor` type from the [`Types`](#Types) to check the `value` | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| type | [`Types`](#types) | A `string` or generic `Constructor` type from the [`Types`](#types) to check the `value` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | -The **return value** is a `boolean` indicating whether or not the `value` is the [`Type`](#Type) from a `type` of the [`Types`](#Types). +The **return value** is a `boolean` indicating whether or not the `value` is the [`Type`](#type) from a `type` of the [`Types`](#types). [Example usage on playground][is-type] @@ -1019,7 +1019,7 @@ const isUndefined: IsUndefined = (value: any, callback: ResultCallback = resultC | Parameter | Type | Description | | :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is `undefined`. @@ -1045,7 +1045,7 @@ const isNot: IsNot = { ### isNotBoolean -Use `isNotBoolean()` or `is.not.boolean()` to check if an **unknown** `value` is **not** a `boolean` type, **not** equal to `true` or `false` and **not** an instance of a [`Boolean`][Boolean]. +Use `isNotBoolean()` or `is.not.boolean()` to check if an **unknown** `value` is **not** a `boolean` type, **not** equal to `true` or `false` and **not** an instance of a [`Boolean`][boolean]. ```typescript const isNotBoolean: IsNotBoolean = (value: unknown, callback: ResultCallback = resultCallback): boolean => @@ -1061,7 +1061,7 @@ const isNotBoolean: IsNotBoolean = (value: unknown, callback: ResultCallback = r | Parameter | Type | Description | | :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is not a `boolean`. @@ -1079,7 +1079,7 @@ const isNotDefined: IsNotDefined = (value: unknown, callback: ResultCallback = r | Parameter | Type | Description | | :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The return value is a `boolean` indicating whether or not the `value` is not defined, is `undefined`. @@ -1097,7 +1097,7 @@ const isNotFunction: IsNotFunction = (value: unknown, callback: ResultCallback = | Parameter | Type | Description | | :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The return value is a `boolean` indicating whether or not the `value` is not a `function`. @@ -1115,7 +1115,7 @@ const isNotNull: IsNotNull = (value: unknown, callback: ResultCallback = resultC | Parameter | Type | Description | | :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The return value is a `boolean` indicating whether or not the `value` is not `null`. @@ -1137,7 +1137,7 @@ const isNotNumber: IsNotNumber = (value: any, callback: ResultCallback = resultC | Parameter | Type | Description | | :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The return value is a `boolean` indicating whether or not the `value` is not a `number`. @@ -1155,7 +1155,7 @@ const isNotString: IsNotString = (value: unknown, callback: ResultCallback = res | Parameter | Type | Description | | :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The return value is a `boolean` indicating whether or not the `value` is not a `string`. @@ -1173,7 +1173,7 @@ const isNotUndefined: IsNotUndefined = (value: unknown, callback: ResultCallback | Parameter | Type | Description | | :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The return value is a `boolean` indicating whether or not the `value` is not `undefined`. @@ -1211,7 +1211,7 @@ const guard: Guard = { ### guardArray -Use `guardArray()` or `guard.is.array()` to guard the `value` to be an [`Array`][Array] of a generic `Type`. +Use `guardArray()` or `guard.is.array()` to guard the `value` to be an [`Array`][array] of a generic `Type`. ```typescript const guardArray: GuardArray = (value: Array, callback?: ResultCallback): value is Array => @@ -1221,9 +1221,9 @@ const guardArray: GuardArray = (value: Array, callback?: ResultCallb | Parameter | Type | Description | |-----------| :---------------------------------: |-------------| | value | `Array` | A generic `Type` `Array` `value` to guard | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | -The **return value** is a `boolean` indicating whether or not the `value` is an [`Array`][Array] of a generic `Type`. +The **return value** is a `boolean` indicating whether or not the `value` is an [`Array`][array] of a generic `Type`. [Example usage on playground][guard-array] @@ -1241,7 +1241,7 @@ const guardBigInt: GuardBigInt = (value: bigint, callback?: ResultCallback): val | Parameter | Type | Description | | :-------- | :---------------------------------: | :------------------------------- | | value | `bigint` | A `bigint` type `value` to guard | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `bigint`. @@ -1259,7 +1259,7 @@ const guardBoolean: GuardBoolean = (value: boolean, callback?: ResultCallback): | Parameter | Type | Description | | :-------- | :---------------------------------: | :-------------------------------- | | value | `boolean` | A `boolean` type `value` to guard | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `boolean`. @@ -1277,7 +1277,7 @@ const guardFunction: GuardFunction = (value: Func, callback?: ResultCallback): v | Parameter | Type | Description | | :-------- | :---------------------------------: | :-------------------------------------- | | value | [`Func`](#Func) | A [`Func`](#Func) type `value` to guard | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The return value is a `boolean` indicating whether or not the `value` is a [`Func`](#Func). @@ -1298,7 +1298,7 @@ const guardInstance: GuardInstance = (value: Obj, instance: Constructor`](#Constructor) | A generic `Obj` [`Constructor`](#Constructor) type to create an `instance` to compare with the `value` | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is an `instance` of a generic `Obj`. @@ -1316,7 +1316,7 @@ const guardKey: GuardKey = (value: Key, callback?: ResultCallback): value is Key | Parameter | Type | Description | | :-------- | :---------------------------------: | :------------------------------------ | | value | [`Key`](#Key) | A [`Key`](#Key) type `value` to guard | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a [`Key`](#Key). @@ -1334,7 +1334,7 @@ const guardNull: GuardNull = (value: null, callback?: ResultCallback): value is | Parameter | Type | Description | | :-------- | :---------------------------------: | :----------------------------- | | value | `null` | A `null` type `value` to guard | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `null`. @@ -1352,7 +1352,7 @@ const guardNumber: GuardNumber = (value: number, callback?: ResultCallback): val | Parameter | Type | Description | |---------- | :---------------------------------: | :-------------------------------- | | value | `number` | A `number` type `value` to guard. | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `number`. @@ -1400,7 +1400,7 @@ The **return value** is a `boolean` indicating whether or not the `value` is an ### guardPrimitive -Use `guardPrimitive()` or `guard.is.primitive()` to guard the `value` to be the [`Primitive`](#Primitive) from a `type` of the [`Primitives`](#Primitives). +Use `guardPrimitive()` or `guard.is.primitive()` to guard the `value` to be the [`Primitive`](#primitive) from a `type` of the [`Primitives`](#primitives). ```typescript const guardPrimitive: GuardPrimitive = @@ -1410,11 +1410,11 @@ const guardPrimitive: GuardPrimitive = | Parameter | Type | Description | | :---------- | :--------------------------------------: | :---------------------------------- | -| value | `Type` extends [`Primitive`](#Primitive) | A `Primitive` type `value` to guard | -| type | [`Primitives`](#Primitives) | A `string` type from the [`Primitives`](#Primitives) to check the `value` | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| value | `Type` extends [`Primitive`](#primitive) | A `Primitive` type `value` to guard | +| type | [`Primitives`](#primitives) | A `string` type from the [`Primitives`](#primitives) to check the `value` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | -The return value is a `boolean` indicating whether or not the `value` is the [`Primitive`](#Primitive) from the `type`. +The return value is a `boolean` indicating whether or not the `value` is the [`Primitive`](#primitive) from the `type`. [Example usage on playground][guard-primitive] @@ -1432,7 +1432,7 @@ const guardString: GuardString = (value: string, callback?: ResultCallback): val | Parameter | Type | Description | |-------------| :---------------------------------: | :------------------------------- | | value | `string` | A `string` type `value` to guard | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The return value is a `boolean` indicating whether or not the `value` is a `string`. @@ -1452,7 +1452,7 @@ const guardSymbol: GuardSymbol = (value: symbol, callback?: ResultCallback): val | Parameter | Type | Description | | :-------- | :---------------------------------: | :----------------------------- | | value | `symbol` | A `symbol` type `value` to guard | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `symbol`. @@ -1460,20 +1460,20 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` ### guardType -Use `guardType()` or `guard.is.type()` to guard the `value` to be the [`Type`](#Type) from a `type` of the [`Types`](#Types). +Use `guardType()` or `guard.is.type()` to guard the `value` to be the [`Type`](#type) from a `type` of the [`Types`](#types). ```typescript const guardType: GuardType = (value: T, type: Types, callback?: ResultCallback): value is T => isType(value, type, callback); ``` -| Parameter | Type | Description | -| :-------- | :-------------------------: | :------------------------------------------------- | -| value | `T` extends [`Type`](#Type) | A [`Type`](#Type) `value` to guard with the `type` | -| type | [`Types`](#Types) | A `string` or generic [`Constructor`](#Constructor) type from the [`Types`](#Types) to check the `value` | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :------------------------------------------------- | +| value | `T` extends [`Type`](#type) | A [`Type`](#type) `value` to guard with the `type` | +| type | [`Types`](#types) | A `string` or generic [`Constructor`](#constructor) type from the [`Types`](#types) to check the `value` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | -The return value is a `boolean` indicating whether or not the `value` is a `type` from the [`Types`](#Types). +The return value is a `boolean` indicating whether or not the `value` is a `type` from the [`Types`](#types). [Example usage on playground][guard-type] @@ -1491,7 +1491,7 @@ const guardUndefined: GuardUndefined = (value: undefined, callback?: ResultCallb | Parameter | Type | Description | | :-------- | :---------------------------------: | :---------------------------------- | | value | `undefined` | A `undefined` type `value` to guard | -| callback | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is `undefined`. @@ -1701,7 +1701,7 @@ type Key = number | string | symbol; ### Primitive -All [`Primitive`][Primitive] types. +All [`Primitive`][primitive] types. ```typescript type Primitive = bigint | boolean | null | number | string | symbol | undefined; @@ -1709,7 +1709,7 @@ type Primitive = bigint | boolean | null | number | string | symbol | undefined; ### Primitives -All [`Primitive`](#Primitive) types as `string`. +All [`Primitive`](#primitive) types as `string`. ```typescript type Primitives = 'bigint' | 'boolean' | 'null' | 'number' | 'symbol' | 'string' | 'undefined'; @@ -1769,13 +1769,13 @@ How do I know when to release 1.0.0? MIT © angular-package ([license](https://github.com/angular-package/type/blob/main/LICENSE)) -[Array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array -[Boolean]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean -[Function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions -[Number]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number -[Object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object -[Primitive]: https://developer.mozilla.org/en-US/docs/Glossary/Primitive -[String]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String +[array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array +[boolean]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean +[function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions +[number]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number +[object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object +[primitive]: https://developer.mozilla.org/en-US/docs/Glossary/Primitive +[string]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String [new]: https://img.shields.io/badge/-new-red diff --git a/packages/type/README.md b/packages/type/README.md index fac015f0..bf9b14b6 100644 --- a/packages/type/README.md +++ b/packages/type/README.md @@ -98,52 +98,52 @@ import { Constructor, CycleHook, Func, Key, Primitive, Primitives, ResultCallbac * Checks if * **any** value is - * an `Array` of any type with [`isArray()`](#isArray). - * a `bigint` type with [`isBigInt()`](#isBigInt). - * a `boolean` with [`isBoolean()`](#isBoolean). - * an `object`type and instance of [`Boolean`][Boolean] and [`Object`][Object] with [`isBooleanObject()`](#isBooleanObject). - * a `boolean` type not an instance of [`Boolean`][Boolean] and [`Object`][Object], and equal to `true` or `false` with [`isBooleanType()`](#isBooleanType). - * a `function` with [`isFunction()`](#isFunction). - * a generic type `instance` with [`isInstance()`](#isInstance). - * a [`Key`](#Key) type with [`isKey()`](#isKey). - * a `null` with [`isNull()`](#isNull). - * a `number` with [`isNumber()`](#isNumber). - * an `object` type and instance of [`Number`][Number] and [`Object`][Object] with [`isNumberObject()`](#isNumberObject). - * a `number` type and **not** instance of [`Number`][Number] and [`Object`][Object] with [`isNumberType()`](#isNumberType). - * a generic type `object` with [`isObject()`](#isObject). - * an `object` with its own specified [`Key`](#Key) with [`isObjectKey()`](#isObjectKey). + * an `Array` of any type with [`isArray()`](#isarray). + * a `bigint` type with [`isBigInt()`](#isbigint). + * a `boolean` with [`isBoolean()`](#isboolean). + * an `object`type and instance of [`Boolean`][boolean] and [`Object`][object] with [`isBooleanObject()`](#isbooleanobject). + * a `boolean` type not an instance of [`Boolean`][boolean] and [`Object`][object], and equal to `true` or `false` with [`isBooleanType()`](#isbooleantype). + * a `function` with [`isFunction()`](#isfunction). + * a generic type `instance` with [`isInstance()`](#isinstance). + * a [`Key`](#Key) type with [`isKey()`](#iskey). + * a `null` with [`isNull()`](#isnull). + * a `number` with [`isNumber()`](#isnumber). + * an `object` type and instance of [`Number`][Number] and [`Object`][object] with [`isNumberObject()`](#isnumberobject). + * a `number` type and **not** instance of [`Number`][Number] and [`Object`][object] with [`isNumberType()`](#isnumbertype). + * a generic type `object` with [`isObject()`](#isobject). + * an `object` with its own specified [`Key`](#Key) with [`isObjectKey()`](#isobjectkey). * a one of the primitive `boolean`, `bigint`, `number`, `string` with [`isPrimitive()`](#isPrimitive). - * a `string` with [`isString()`](#isString). - * an `object` type and instance of [`String`][String] and [`Object`][Object] with [`isStringObject()`](#isStringObject). - * a `string` type and **not** instance of [`String`][String] and [`Object`][Object] with [`isStringType()`](#isStringType). + * a `string` with [`isString()`](#isstring). + * an `object` type and instance of [`String`][string] and [`Object`][object] with [`isStringObject()`](#isstringobject). + * a `string` type and **not** instance of [`String`][string] and [`Object`][object] with [`isStringType()`](#isstringtype). * a `symbol` with [`isSymbol()`](#isSymbol). - * a generic type instance, `function`, `object` or primitive type with [`isType()`](#isType). - * a `undefined` type with [`isUndefined()`](#isUndefined). + * a generic type instance, `function`, `object` or primitive type with [`isType()`](#istype). + * a `undefined` type with [`isUndefined()`](#isundefined). * an **unknown** value is - * defined with [`isDefined()`](#isDefined). + * defined with [`isDefined()`](#isdefined). * an **unknown** value is **not** a - * `boolean` type with [`isNotBoolean()`](#isNotBoolean) - * `function` type with [`isNotFunction()`](#isNotFunction) - * `null` type with [`isNotNull()`](#isNotNull) - * `number` type with [`isNotNumber()`](#isNotNumber) - * `string` type with [`isNotString()`](#isNotString) - * `undefined` type with [`isNotUndefined()`](#isNotUndefined) + * `boolean` type with [`isNotBoolean()`](#isnotboolean) + * `function` type with [`isNotFunction()`](#isnotfunction) + * `null` type with [`isNotNull()`](#isnotnull) + * `number` type with [`isNotNumber()`](#isnotnumber) + * `string` type with [`isNotString()`](#isnotstring) + * `undefined` type with [`isNotUndefined()`](#isnotundefined) * Guard the value to be - * an [`Array`][Array] of a generic type with [`guardArray()`](#guardArray). - * a `bigint` with [`guardBigInt()`](#guardBigInt). - * a `boolean` with [`guardBoolean()`](#guardBoolean). - * a `function` type with [`guardFunction()`](#guardFunction). - * an instance with [`guardInstance()`](#guardInstance). - * a `null` with [`guardNull()`](#guardNull). - * a [`Key`](#Key) with [`guardKey()`](#guardKey). - * a `number` with [`guardNumber()`](#guardNumber). - * an `object` of a generic type with [`guardObject()`](#guardObject). - * an `object` of a generic type that contains `key` with [`guardObjectKey()`](#guardObjectKey). - * a one of the [`Primitives`](#Primitives) with [`guardPrimitive()`](#guardPrimitive). - * a `string` with [`guardString()`](#guardString). - * a `symbol` with [`guardSymbol()`](#guardSymbol). - * a generic type from one of the [`Types`](#types) type with [`guardType()`](#guardType). - * `undefined` with [`guardUndefined()`](#guardUndefined). + * an [`Array`][array] of a generic type with [`guardArray()`](#guardarray). + * a `bigint` with [`guardBigInt()`](#guardbigint). + * a `boolean` with [`guardBoolean()`](#guardboolean). + * a `function` type with [`guardFunction()`](#guardfunction). + * an instance with [`guardInstance()`](#guardinstance). + * a `null` with [`guardNull()`](#guardnull). + * a [`Key`](#Key) with [`guardKey()`](#guardkey). + * a `number` with [`guardNumber()`](#guardnumber). + * an `object` of a generic type with [`guardObject()`](#guardobject). + * an `object` of a generic type that contains `key` with [`guardObjectKey()`](#guardiobjectkey). + * a one of the [`Primitives`](#primitives) with [`guardPrimitive()`](#guardprimitive). + * a `string` with [`guardString()`](#guardstring). + * a `symbol` with [`guardSymbol()`](#guardsymbol). + * a generic type from one of the [`Types`](#types) type with [`guardType()`](#guardtype). + * `undefined` with [`guardUndefined()`](#guardundefined). ## How angular-package understands @@ -159,20 +159,20 @@ Guard ---- * [Installation](#installation) -* [resultCallback](#resultCallback) +* [resultCallback](#resultcallback) * [Check](#check) * [are](#are) * [is](#is) - * [isNot](#isNot) + * [isNot](#isnot) * [Guard](#guard) * [Experimental](#Experimental) - * [BigIntObject](#BigIntObject) - * [BooleanObject](#BooleanObject) - * [NumberObject](#NumberObject) - * [PrimitiveObject](#PrimitiveObject) - * [StringObject](#StringObject) - * [SymbolObject](#SymbolObject) - * [isParam()](#isParam) + * [BigIntObject](#bigintobject) + * [BooleanObject](#booleanobject) + * [NumberObject](#numberobject) + * [PrimitiveObject](#primitiveobject) + * [StringObject](#stringobject) + * [SymbolObject](#symbolobject) + * [isParam()](#isparam) * [Common types](#common-types) * [Git](#git) * [Commit](#commit) @@ -280,7 +280,7 @@ const is: Is = { ### isArray -Use `isArray()` or `is.array()` to check if **any** `value` is an [`Array`][Array], [`Array`][Array] instance, and `object` type. +Use `isArray()` or `is.array()` to check if **any** `value` is an [`Array`][array], [`Array`][array] instance, and `object` type. ```typescript const isArray: IsArray = (value: any, callback: ResultCallback = resultCallback): value is Array => @@ -295,9 +295,9 @@ const isArray: IsArray = (value: any, callback: ResultCallback = resultCal | Parameter | Type | Description | | :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | -The **return value** is a `boolean` indicating whether or not the `value` is an [`Array`][Array]. +The **return value** is a `boolean` indicating whether or not the `value` is an [`Array`][array]. ```typescript // Example usage @@ -324,7 +324,7 @@ const isBigInt: IsBigInt = (value: any, callback: ResultCallback = resultCallbac | Parameter | Type | Description | | :-------- | :---: | :---------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `bigint`. @@ -343,7 +343,7 @@ isBigInt(BIGINT); // true ### isBoolean -Use `isBoolean()` or `is.boolean()` to check if **any** `value` is a `boolean` type not instance of [`Boolean`][Boolean] and [`Object`][Object] or `object` type instance of [`Boolean`][Boolean] and [`Object`][Object]. +Use `isBoolean()` or `is.boolean()` to check if **any** `value` is a `boolean` type not instance of [`Boolean`][boolean] and [`Object`][object] or `object` type instance of [`Boolean`][boolean] and [`Object`][object]. ```typescript const isBoolean: IsBoolean = (value: any, callback: ResultCallback = resultCallback): value is boolean => @@ -353,7 +353,7 @@ const isBoolean: IsBoolean = (value: any, callback: ResultCallback = resultCallb | Parameter | Type | Description | | :---------| :---: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `boolean`. @@ -372,7 +372,7 @@ isBoolean(BOOLEAN_INSTANCE); // true ### isBooleanObject -Use `isBooleanObject()` or `is.booleanObject()` to check if **any** `value` is an `object` type and instance of [`Boolean`][Boolean] and [`Object`][Object]. +Use `isBooleanObject()` or `is.booleanObject()` to check if **any** `value` is an `object` type and instance of [`Boolean`][boolean] and [`Object`][object]. ```typescript const isBooleanObject: IsBooleanObject = (value: any, callback: ResultCallback = resultCallback): value is boolean => @@ -382,9 +382,9 @@ const isBooleanObject: IsBooleanObject = (value: any, callback: ResultCallback = | Parameter | Type | Description | | :---------| :---: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | -The **return value** is a `boolean` indicating whether or not the `value` is a [`Boolean`][Boolean] instance. +The **return value** is a `boolean` indicating whether or not the `value` is a [`Boolean`][boolean] instance. ```typescript // Example usage @@ -399,7 +399,7 @@ isBooleanObject(BOOLEAN_INSTANCE); // true ### isBooleanType -Use `isBooleanType()` or `is.booleanType()` to check if **any** `value` is a `boolean` type not an instance of [`Boolean`][Boolean] and [`Object`][Object], and equal to `true` or `false`. +Use `isBooleanType()` or `is.booleanType()` to check if **any** `value` is a `boolean` type not an instance of [`Boolean`][boolean] and [`Object`][object], and equal to `true` or `false`. ```typescript const isBooleanType: IsBooleanType = (value: any, callback: ResultCallback = resultCallback): value is boolean => @@ -414,7 +414,7 @@ const isBooleanType: IsBooleanType = (value: any, callback: ResultCallback = res | Parameter | Type | Description | | :---------| :---: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `boolean` type. @@ -441,7 +441,7 @@ const isDefined: IsDefined = (value: unknown, callback: ResultCallback = resultC | Parameter | Type | Description | | :-------- | :-------: | :---------------------------- | | value | `unknown` | An `unknown` `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is defined, not `undefined`. @@ -458,7 +458,7 @@ isDefined(defined); // false ### isFunction -Use `isFunction()` or `is.function()` to check if **any** `value` is a `function` type, an instance of [`Function`][Function] and [`Object`][Object]. +Use `isFunction()` or `is.function()` to check if **any** `value` is a `function` type, an instance of [`Function`][function] and [`Object`][object]. ```typescript const isFunction: IsFunction = (value: any, callback: ResultCallback = resultCallback): value is Func => @@ -473,7 +473,7 @@ const isFunction: IsFunction = (value: any, callback: ResultCallback = resultCal | Parameter | Type | Description | | :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `function`. @@ -514,7 +514,7 @@ const isInstance: IsInstance = ( | :-------- | :--------------------------------: | :---------- | | value | `any` | Any `value` to compare with the `instance` | | instance | [`Constructor`](#Constructor) | A generic `Obj` [`Constructor`](#Constructor) type to create an `instance` to compare with the `value` | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is an `instance` of a generic `Obj`. @@ -547,7 +547,7 @@ const isKey: IsKey = (value: any, callback: ResultCallback = resultCallback): va | Parameter | Type | Description | | :-------- | :---: |:-------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a [`Key`](#Key). @@ -583,7 +583,7 @@ const isNull: IsNull = (value: any, callback: ResultCallback = resultCallback): | Parameter | Type | Description | | :-------- | :---: |--------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is `null`. @@ -608,7 +608,7 @@ isNull(NUMBER); // false ### isNumber -Use `isNumber()` or `is.number()` to check if **any** `value` is a `number` type not an instance of [`Number`][Number] and [`Object`][Object] or `object` type instance of [`Number`][Number] and [`Object`][Object]. +Use `isNumber()` or `is.number()` to check if **any** `value` is a `number` type not an instance of [`Number`][Number] and [`Object`][object] or `object` type instance of [`Number`][Number] and [`Object`][object]. ```typescript const isNumber: IsNumber = (value: any, callback: ResultCallback = resultCallback): value is number => @@ -618,7 +618,7 @@ const isNumber: IsNumber = (value: any, callback: ResultCallback = resultCallbac | Parameter | Type | Description | | :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `number`. @@ -628,7 +628,7 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` ### isNumberObject -Use `isNumberObject()` or `is.numberObject()` to check if **any** `value` is an `object` type and instance of [`Number`][Number] and [`Object`][Object]. +Use `isNumberObject()` or `is.numberObject()` to check if **any** `value` is an `object` type and instance of [`Number`][Number] and [`Object`][object]. ```typescript const isNumberObject: IsNumberObject = (value: any, callback: ResultCallback = resultCallback): value is number => @@ -638,7 +638,7 @@ const isNumberObject: IsNumberObject = (value: any, callback: ResultCallback = r | Parameter | Type | Description | | :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a [`Number`][Number] instance. @@ -677,7 +677,7 @@ isNumberObject(NUMBER_NEW_INSTANCE); // true ### isNumberType -Use `isNumberType()` or `is.numberType()` to check if **any** `value` is a `number` type not an instance of [`Number`][Number] and [`Object`][Object]. +Use `isNumberType()` or `is.numberType()` to check if **any** `value` is a `number` type not an instance of [`Number`][Number] and [`Object`][object]. ```typescript const isNumberType: IsNumberType = (value: any, callback: ResultCallback = resultCallback): value is number => @@ -687,7 +687,7 @@ const isNumberType: IsNumberType = (value: any, callback: ResultCallback = resul | Parameter | Type | Description | | :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `number`. @@ -726,7 +726,7 @@ isNumberType(NUMBER_NEW_INSTANCE); // false ### isObject -Use `isObject()` or `is.object()` to check if **any** `value` is an `object` of a generic `Obj` type and [`Object`][Object] instance with the possibility of containing the `key`. +Use `isObject()` or `is.object()` to check if **any** `value` is an `object` of a generic `Obj` type and [`Object`][object] instance with the possibility of containing the `key`. ```typescript const isObject: IsObject = (value: any, key?: Key): value is Obj => @@ -804,7 +804,7 @@ const OBJECT_ONE: ObjectOne = { 1030405027: 'key is number', 5: 'key is also number', [NUMBER]: 'key is number', - [STRING]: 'key is string', + [string]: 'key is string', [SYMBOL_NUMBER]: 'key is symbol number', [SYMBOL_STRING]: 6, x: 3000 @@ -849,7 +849,7 @@ const isObjectKey: IsObjectKey = ( | :-------- | :------------------------------: | :---------------------------------------------------- | | value | `any` | Any `value` to check if it contains a specified `key` | | key | [`Key`](#key) \| [`Key`](#Key)[] | A [`Key`](#Key) type or an array of [`Key`](#Key) type to check in the `value` | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is an `object` with its own specified keys. @@ -857,7 +857,7 @@ The **return value** is a `boolean` indicating whether or not the `value` is an ### isPrimitive -Use `isPrimitive()` or `is.primitive()` to check if **any** `value` is the [`Primitive`](#Primitive) type from a `type` of the [`Primitives`](#Primitives) type. +Use `isPrimitive()` or `is.primitive()` to check if **any** `value` is the [`Primitive`](#primitive) type from a `type` of the [`Primitives`](#primitives) type. ```typescript const isPrimitive: IsPrimitive = ( @@ -883,10 +883,10 @@ const isPrimitive: IsPrimitive = ( | Parameter | Type | Description | | :-------- | :-------------------------: | :------------------------------------------------------------------------ | | value | `any` | Any `value` to check if it's a `Primitive` from the `type` | -| type | [`Primitives`](#Primitives) | A `string` type from the [`Primitives`](#Primitives) to check the `value` | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| type | [`Primitives`](#primitives) | A `string` type from the [`Primitives`](#primitives) to check the `value` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | -The **return value** is a `boolean` indicating whether or not the `value` is a `type` from the [`Primitives`](#Primitives). +The **return value** is a `boolean` indicating whether or not the `value` is a `type` from the [`Primitives`](#primitives). [Example usage on playground][is-primitive] @@ -894,7 +894,7 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` ### isString -Use `isString()` or `is.string()` to check if **any** `value` is a `string` type, not instance of [`Object`][Object] and [`String`][String] or `object` type and instance of [`String`][String] and [`Object`][Object]. +Use `isString()` or `is.string()` to check if **any** `value` is a `string` type, not instance of [`Object`][object] and [`String`][string] or `object` type and instance of [`String`][string] and [`Object`][object]. ```typescript const isString: IsString = (value: any, callback: ResultCallback = resultCallback): value is string => @@ -904,7 +904,7 @@ const isString: IsString = (value: any, callback: ResultCallback = resultCallbac | Parameter | Type | Description | | :-------- | :---------------------------------: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `string`. @@ -912,7 +912,7 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` ### isStringObject -Use `isStringObject()` or `is.stringObject()` to check if **any** `value` is an `object` type and instance of [`String`][String] and [`Object`][Object]. +Use `isStringObject()` or `is.stringObject()` to check if **any** `value` is an `object` type and instance of [`String`][string] and [`Object`][object]. ```typescript const isStringObject: IsStringObject = (value: any, callback: ResultCallback = resultCallback): value is string => @@ -922,15 +922,15 @@ const isStringObject: IsStringObject = (value: any, callback: ResultCallback = r | Parameter | Type | Description | | :-------- | :---------------------------------: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | -The **return value** is a `boolean` indicating whether or not the `value` is a [`String`][String] instance. +The **return value** is a `boolean` indicating whether or not the `value` is a [`String`][string] instance. ---- ### isStringType -Use `isStringType()` or `is.stringType()` to check if **any** `value` is a `string` type and **not** instance of [`String`][String] and [`Object`][Object]. +Use `isStringType()` or `is.stringType()` to check if **any** `value` is a `string` type and **not** instance of [`String`][string] and [`Object`][object]. ```typescript const isStringType: IsStringType = (value: any, callback: ResultCallback = resultCallback): value is string => @@ -940,7 +940,7 @@ const isStringType: IsStringType = (value: any, callback: ResultCallback = resul | Parameter | Type | Description | | :-------- | :---------------------------------------------------------------------: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `string`. @@ -958,7 +958,7 @@ const isSymbol: IsSymbol = (value: any, callback: ResultCallback = resultCallbac | Parameter | Type | Description | | :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `symbol`. @@ -968,7 +968,7 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` ### isType -Use `isType()` or `is.type()` to check if **any** `value` is the [`Type`](#Type) from a `type` of the [`Types`](#Types) type. +Use `isType()` or `is.type()` to check if **any** `value` is the [`Type`](#type) from a `type` of the [`Types`](#types) type. ```typescript const isType: IsType = (value: any, type: Types, callback: ResultCallback = resultCallback): value is T => { @@ -998,10 +998,10 @@ const isType: IsType = (value: any, type: Types, callback: Re | Parameter | Type | Description | | :-------- | :------------------: | :-------------------------------------------------- | | value | `any` | Any `value` to check if its type is from the `type` | -| type | [`Types`](#Types) | A `string` or generic `Constructor` type from the [`Types`](#Types) to check the `value` | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| type | [`Types`](#types) | A `string` or generic `Constructor` type from the [`Types`](#types) to check the `value` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | -The **return value** is a `boolean` indicating whether or not the `value` is the [`Type`](#Type) from a `type` of the [`Types`](#Types). +The **return value** is a `boolean` indicating whether or not the `value` is the [`Type`](#type) from a `type` of the [`Types`](#types). [Example usage on playground][is-type] @@ -1019,7 +1019,7 @@ const isUndefined: IsUndefined = (value: any, callback: ResultCallback = resultC | Parameter | Type | Description | | :-------- | :---: | :------------------- | | value | `any` | Any `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is `undefined`. @@ -1045,7 +1045,7 @@ const isNot: IsNot = { ### isNotBoolean -Use `isNotBoolean()` or `is.not.boolean()` to check if an **unknown** `value` is **not** a `boolean` type, **not** equal to `true` or `false` and **not** an instance of a [`Boolean`][Boolean]. +Use `isNotBoolean()` or `is.not.boolean()` to check if an **unknown** `value` is **not** a `boolean` type, **not** equal to `true` or `false` and **not** an instance of a [`Boolean`][boolean]. ```typescript const isNotBoolean: IsNotBoolean = (value: unknown, callback: ResultCallback = resultCallback): boolean => @@ -1061,7 +1061,7 @@ const isNotBoolean: IsNotBoolean = (value: unknown, callback: ResultCallback = r | Parameter | Type | Description | | :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is not a `boolean`. @@ -1079,7 +1079,7 @@ const isNotDefined: IsNotDefined = (value: unknown, callback: ResultCallback = r | Parameter | Type | Description | | :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The return value is a `boolean` indicating whether or not the `value` is not defined, is `undefined`. @@ -1097,7 +1097,7 @@ const isNotFunction: IsNotFunction = (value: unknown, callback: ResultCallback = | Parameter | Type | Description | | :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The return value is a `boolean` indicating whether or not the `value` is not a `function`. @@ -1115,7 +1115,7 @@ const isNotNull: IsNotNull = (value: unknown, callback: ResultCallback = resultC | Parameter | Type | Description | | :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The return value is a `boolean` indicating whether or not the `value` is not `null`. @@ -1137,7 +1137,7 @@ const isNotNumber: IsNotNumber = (value: any, callback: ResultCallback = resultC | Parameter | Type | Description | | :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The return value is a `boolean` indicating whether or not the `value` is not a `number`. @@ -1155,7 +1155,7 @@ const isNotString: IsNotString = (value: unknown, callback: ResultCallback = res | Parameter | Type | Description | | :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The return value is a `boolean` indicating whether or not the `value` is not a `string`. @@ -1173,7 +1173,7 @@ const isNotUndefined: IsNotUndefined = (value: unknown, callback: ResultCallback | Parameter | Type | Description | | :-------- | :-------: | :-------------------------- | | value | `unknown` | An unknown `value` to check | -| callback | [`ResultCallback`](#ResultCallback)=[`resultCallback`](#resultCallback) | [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback)=[`resultCallback`](#resultcallback) | [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The return value is a `boolean` indicating whether or not the `value` is not `undefined`. @@ -1211,7 +1211,7 @@ const guard: Guard = { ### guardArray -Use `guardArray()` or `guard.is.array()` to guard the `value` to be an [`Array`][Array] of a generic `Type`. +Use `guardArray()` or `guard.is.array()` to guard the `value` to be an [`Array`][array] of a generic `Type`. ```typescript const guardArray: GuardArray = (value: Array, callback?: ResultCallback): value is Array => @@ -1221,9 +1221,9 @@ const guardArray: GuardArray = (value: Array, callback?: ResultCallb | Parameter | Type | Description | |-----------| :---------------------------------: |-------------| | value | `Array` | A generic `Type` `Array` `value` to guard | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | -The **return value** is a `boolean` indicating whether or not the `value` is an [`Array`][Array] of a generic `Type`. +The **return value** is a `boolean` indicating whether or not the `value` is an [`Array`][array] of a generic `Type`. [Example usage on playground][guard-array] @@ -1241,7 +1241,7 @@ const guardBigInt: GuardBigInt = (value: bigint, callback?: ResultCallback): val | Parameter | Type | Description | | :-------- | :---------------------------------: | :------------------------------- | | value | `bigint` | A `bigint` type `value` to guard | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `bigint`. @@ -1259,7 +1259,7 @@ const guardBoolean: GuardBoolean = (value: boolean, callback?: ResultCallback): | Parameter | Type | Description | | :-------- | :---------------------------------: | :-------------------------------- | | value | `boolean` | A `boolean` type `value` to guard | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `boolean`. @@ -1277,7 +1277,7 @@ const guardFunction: GuardFunction = (value: Func, callback?: ResultCallback): v | Parameter | Type | Description | | :-------- | :---------------------------------: | :-------------------------------------- | | value | [`Func`](#Func) | A [`Func`](#Func) type `value` to guard | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The return value is a `boolean` indicating whether or not the `value` is a [`Func`](#Func). @@ -1298,7 +1298,7 @@ const guardInstance: GuardInstance = (value: Obj, instance: Constructor`](#Constructor) | A generic `Obj` [`Constructor`](#Constructor) type to create an `instance` to compare with the `value` | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is an `instance` of a generic `Obj`. @@ -1316,7 +1316,7 @@ const guardKey: GuardKey = (value: Key, callback?: ResultCallback): value is Key | Parameter | Type | Description | | :-------- | :---------------------------------: | :------------------------------------ | | value | [`Key`](#Key) | A [`Key`](#Key) type `value` to guard | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a [`Key`](#Key). @@ -1334,7 +1334,7 @@ const guardNull: GuardNull = (value: null, callback?: ResultCallback): value is | Parameter | Type | Description | | :-------- | :---------------------------------: | :----------------------------- | | value | `null` | A `null` type `value` to guard | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `null`. @@ -1352,7 +1352,7 @@ const guardNumber: GuardNumber = (value: number, callback?: ResultCallback): val | Parameter | Type | Description | |---------- | :---------------------------------: | :-------------------------------- | | value | `number` | A `number` type `value` to guard. | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `number`. @@ -1400,7 +1400,7 @@ The **return value** is a `boolean` indicating whether or not the `value` is an ### guardPrimitive -Use `guardPrimitive()` or `guard.is.primitive()` to guard the `value` to be the [`Primitive`](#Primitive) from a `type` of the [`Primitives`](#Primitives). +Use `guardPrimitive()` or `guard.is.primitive()` to guard the `value` to be the [`Primitive`](#primitive) from a `type` of the [`Primitives`](#primitives). ```typescript const guardPrimitive: GuardPrimitive = @@ -1410,11 +1410,11 @@ const guardPrimitive: GuardPrimitive = | Parameter | Type | Description | | :---------- | :--------------------------------------: | :---------------------------------- | -| value | `Type` extends [`Primitive`](#Primitive) | A `Primitive` type `value` to guard | -| type | [`Primitives`](#Primitives) | A `string` type from the [`Primitives`](#Primitives) to check the `value` | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| value | `Type` extends [`Primitive`](#primitive) | A `Primitive` type `value` to guard | +| type | [`Primitives`](#primitives) | A `string` type from the [`Primitives`](#primitives) to check the `value` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | -The return value is a `boolean` indicating whether or not the `value` is the [`Primitive`](#Primitive) from the `type`. +The return value is a `boolean` indicating whether or not the `value` is the [`Primitive`](#primitive) from the `type`. [Example usage on playground][guard-primitive] @@ -1432,7 +1432,7 @@ const guardString: GuardString = (value: string, callback?: ResultCallback): val | Parameter | Type | Description | |-------------| :---------------------------------: | :------------------------------- | | value | `string` | A `string` type `value` to guard | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The return value is a `boolean` indicating whether or not the `value` is a `string`. @@ -1452,7 +1452,7 @@ const guardSymbol: GuardSymbol = (value: symbol, callback?: ResultCallback): val | Parameter | Type | Description | | :-------- | :---------------------------------: | :----------------------------- | | value | `symbol` | A `symbol` type `value` to guard | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is a `symbol`. @@ -1460,20 +1460,20 @@ The **return value** is a `boolean` indicating whether or not the `value` is a ` ### guardType -Use `guardType()` or `guard.is.type()` to guard the `value` to be the [`Type`](#Type) from a `type` of the [`Types`](#Types). +Use `guardType()` or `guard.is.type()` to guard the `value` to be the [`Type`](#type) from a `type` of the [`Types`](#types). ```typescript const guardType: GuardType = (value: T, type: Types, callback?: ResultCallback): value is T => isType(value, type, callback); ``` -| Parameter | Type | Description | -| :-------- | :-------------------------: | :------------------------------------------------- | -| value | `T` extends [`Type`](#Type) | A [`Type`](#Type) `value` to guard with the `type` | -| type | [`Types`](#Types) | A `string` or generic [`Constructor`](#Constructor) type from the [`Types`](#Types) to check the `value` | -| callback? | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| Parameter | Type | Description | +| :-------- | :---------------------------------: | :------------------------------------------------- | +| value | `T` extends [`Type`](#type) | A [`Type`](#type) `value` to guard with the `type` | +| type | [`Types`](#types) | A `string` or generic [`Constructor`](#constructor) type from the [`Types`](#types) to check the `value` | +| callback? | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | -The return value is a `boolean` indicating whether or not the `value` is a `type` from the [`Types`](#Types). +The return value is a `boolean` indicating whether or not the `value` is a `type` from the [`Types`](#types). [Example usage on playground][guard-type] @@ -1491,7 +1491,7 @@ const guardUndefined: GuardUndefined = (value: undefined, callback?: ResultCallb | Parameter | Type | Description | | :-------- | :---------------------------------: | :---------------------------------- | | value | `undefined` | A `undefined` type `value` to guard | -| callback | [`ResultCallback`](#ResultCallback) | Optional [`ResultCallback`](#ResultCallback) function to handle result before returns eg. to throw an `Error` | +| callback | [`ResultCallback`](#resultcallback) | Optional [`ResultCallback`](#resultcallback) function to handle result before returns eg. to throw an `Error` | The **return value** is a `boolean` indicating whether or not the `value` is `undefined`. @@ -1701,7 +1701,7 @@ type Key = number | string | symbol; ### Primitive -All [`Primitive`][Primitive] types. +All [`Primitive`][primitive] types. ```typescript type Primitive = bigint | boolean | null | number | string | symbol | undefined; @@ -1709,7 +1709,7 @@ type Primitive = bigint | boolean | null | number | string | symbol | undefined; ### Primitives -All [`Primitive`](#Primitive) types as `string`. +All [`Primitive`](#primitive) types as `string`. ```typescript type Primitives = 'bigint' | 'boolean' | 'null' | 'number' | 'symbol' | 'string' | 'undefined'; @@ -1769,13 +1769,13 @@ How do I know when to release 1.0.0? MIT © angular-package ([license](https://github.com/angular-package/type/blob/main/LICENSE)) -[Array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array -[Boolean]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean -[Function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions -[Number]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number -[Object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object -[Primitive]: https://developer.mozilla.org/en-US/docs/Glossary/Primitive -[String]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String +[array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array +[boolean]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean +[function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions +[number]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number +[object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object +[primitive]: https://developer.mozilla.org/en-US/docs/Glossary/Primitive +[string]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String [new]: https://img.shields.io/badge/-new-red From fb2a8bf6920897640bb0d2b50527314a487f08ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Mon, 3 May 2021 20:04:50 +0200 Subject: [PATCH 201/201] chore(package): update --- packages/type/package-lock.json | 4 ++-- packages/type/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/type/package-lock.json b/packages/type/package-lock.json index 964fc7dc..23eb9418 100644 --- a/packages/type/package-lock.json +++ b/packages/type/package-lock.json @@ -1,12 +1,12 @@ { "name": "@angular-package/type", - "version": "3.2.0", + "version": "3.2.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@angular-package/type", - "version": "3.2.0", + "version": "3.2.1", "license": "MIT", "dependencies": { "tslib": "^2.1.0" diff --git a/packages/type/package.json b/packages/type/package.json index f2a7df18..97c2b3cc 100644 --- a/packages/type/package.json +++ b/packages/type/package.json @@ -1,6 +1,6 @@ { "name": "@angular-package/type", - "version": "3.2.0", + "version": "3.2.1", "description": "Common types, type guards and type checkers.", "author": "Angular Package (https://wvvw.dev)", "homepage": "https://github.com/angular-package/type#readme",