Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
201 commits
Select commit Hold shift + click to select a range
ac70cf8
refactor(isString): add callback function, use isStringObject and isS…
sciborrudnicki Apr 13, 2021
21bae23
feat(resultCallback): Function to handle callback.
sciborrudnicki Apr 13, 2021
915c01b
refactor(IsString): add callback.
sciborrudnicki Apr 13, 2021
5f783a3
refactor(isObject): Generic `Obj` equal to `object`, update description.
sciborrudnicki Apr 13, 2021
52c4837
feat(KeyName): Type for property name.
sciborrudnicki Apr 14, 2021
d0aec2b
refactor(KeyName): simplify type name to `Key`.
sciborrudnicki Apr 19, 2021
e3a2f10
feat(isKey): function to determine whether or not name is string or n…
sciborrudnicki Apr 19, 2021
f0d4d7c
refactor(isKey): parameter change to value any type and add description.
sciborrudnicki Apr 19, 2021
6e66c4c
refactor(IsObject): Obj type is by default equal to object
sciborrudnicki Apr 19, 2021
7675668
feat(guardKey): feature to guard key for objects.
sciborrudnicki Apr 19, 2021
7a63d54
fix(guardArray): fix file name.
sciborrudnicki Apr 19, 2021
170cabb
fix(guardArray): fix file name.
sciborrudnicki Apr 19, 2021
7c26fea
refactor(guardIs): add guardKey to guardIs object.
sciborrudnicki Apr 19, 2021
aa44c81
docs(guardKey): update description.
sciborrudnicki Apr 19, 2021
1c92cc1
chore(isSymbol): reorder imports, add comments to imports, update des…
sciborrudnicki Apr 19, 2021
2fea293
chore(isArray): upgrade jsdoc, reorder import.
sciborrudnicki Apr 20, 2021
a9f54c7
chore(isBigInt): update jsdoc, reorder imports.
sciborrudnicki Apr 20, 2021
c4f78fc
feat(isBooleanObject): function to check if any value is a boolean ob…
sciborrudnicki Apr 20, 2021
196e302
feat(isBooleanType): function to check if any value is a boolean type.
sciborrudnicki Apr 20, 2021
eb547ce
refactor(isBoolean): use separated functions `isBooleanObject` and `i…
sciborrudnicki Apr 20, 2021
5f746c3
chore(isDefined): reorder imports, update jsdoc.
sciborrudnicki Apr 20, 2021
18cf332
docs(README.md): update.
sciborrudnicki Apr 20, 2021
21bcdd4
docs(README.md): update.
sciborrudnicki Apr 20, 2021
1dfdd23
docs(README.md): update.
sciborrudnicki Apr 20, 2021
3199806
chore(isFunction): reorder imports, update jsdoc.
sciborrudnicki Apr 20, 2021
b9b75b8
docs(README.md): update.
sciborrudnicki Apr 20, 2021
c7daf4a
docs(isFunction): update.
sciborrudnicki Apr 20, 2021
dd5d522
chore(isFunction): move import to type.
sciborrudnicki Apr 20, 2021
989e49b
refactor(isInstance): update.
sciborrudnicki Apr 20, 2021
8720171
refactor(IsKey): change parameter name, and result boolean.
sciborrudnicki Apr 20, 2021
1a59555
refactor(isKey): update.
sciborrudnicki Apr 20, 2021
9fbc219
chore(isNull): reorders imports, update jsdoc.
sciborrudnicki Apr 20, 2021
7204cf3
refactor(isKey): check number as first.
sciborrudnicki Apr 20, 2021
c943239
docs(README.md): update.
sciborrudnicki Apr 20, 2021
64530ab
docs(README.md): update.
sciborrudnicki Apr 20, 2021
676820e
chore(isNumber): update.
sciborrudnicki Apr 20, 2021
057cf45
refactor(isObject): update.
sciborrudnicki Apr 20, 2021
d4d65c2
docs(isString): update.
sciborrudnicki Apr 20, 2021
2a49333
docs(isSymbol): update.
sciborrudnicki Apr 20, 2021
09afc7b
docs(README.md): update.
sciborrudnicki Apr 20, 2021
77f250a
refactor(IsObject): parameter key change to `Key`.
sciborrudnicki Apr 21, 2021
90105d1
feat(isObjectKey): determines if any `object` has its own specified k…
sciborrudnicki Apr 21, 2021
b59783d
docs(README.md): update.
sciborrudnicki Apr 21, 2021
80679d6
refactor(): add check, update imports, update jsdoc
sciborrudnicki Apr 22, 2021
5e38366
docs(isPrimitive): update `value` description
sciborrudnicki Apr 22, 2021
d03b9dc
refactor(Primitives): add 'null' type.
sciborrudnicki Apr 22, 2021
6e8b246
refactor(isType): update code and jsdoc
sciborrudnicki Apr 22, 2021
f171ba3
test(isType): add test
sciborrudnicki Apr 23, 2021
9ed3cd1
chore(Primitives): sort alphabetically
sciborrudnicki Apr 23, 2021
65c103b
test: update
sciborrudnicki Apr 23, 2021
e8eab02
chore(isUndefined): update jsdoc, imports
sciborrudnicki Apr 23, 2021
79e855b
chore(is): update
sciborrudnicki Apr 23, 2021
ff50628
test: move `notDefined` to proper file, order alphabetically imports
sciborrudnicki Apr 23, 2021
25c86da
chore: add `notDefined` to its own file, update path to it
sciborrudnicki Apr 23, 2021
f60a452
refactor(isObjectKey): add `Type = object` to returned value, update …
sciborrudnicki Apr 23, 2021
9560ddc
chore: add expectation for test
sciborrudnicki Apr 23, 2021
a97daa5
chore: remove unnecessary `notDefined`
sciborrudnicki Apr 23, 2021
a699102
chore: add expectation for test, use constant to create instance
sciborrudnicki Apr 23, 2021
5c592e5
chore(Class): add more properties to class
sciborrudnicki Apr 23, 2021
dd4ede9
chore: use constant to create number instance
sciborrudnicki Apr 23, 2021
109fa1c
chore(OBJECT_ONE): add properties
sciborrudnicki Apr 23, 2021
2921cae
chore: change type from any to unique symbol
sciborrudnicki Apr 23, 2021
8ae31f4
test(isObjectKey): add
sciborrudnicki Apr 23, 2021
899d948
test(isString): simplify names
sciborrudnicki Apr 23, 2021
638bc1a
test(isType): simplify names
sciborrudnicki Apr 23, 2021
9177549
test(isObjectKey): add
sciborrudnicki Apr 23, 2021
0fb76c3
refactor(isBooleanObject): update
sciborrudnicki Apr 25, 2021
fc9c174
test(isBooleanObject): add
sciborrudnicki Apr 25, 2021
8e0c186
refactor(isBooleanType): update
sciborrudnicki Apr 25, 2021
fbe2eff
refactor(IsBoolean): add `callback`
sciborrudnicki Apr 25, 2021
0c4cbb3
chore: add types
sciborrudnicki Apr 25, 2021
503b409
test(isBoolean): update
sciborrudnicki Apr 25, 2021
816f6fb
test(isBooleanType): add
sciborrudnicki Apr 25, 2021
20d7ba4
refactor(isBoolean): update
sciborrudnicki Apr 25, 2021
23afa64
docs: update jsdoc
sciborrudnicki Apr 25, 2021
9167f50
test(is): update
sciborrudnicki Apr 25, 2021
ecaeadb
refactor(isKey): change the order of checking to use string as first
sciborrudnicki Apr 25, 2021
5c9e544
docs(README.md): update
sciborrudnicki Apr 25, 2021
f2641a3
feat(isNumberObject): function to check if any value is a `Number` in…
sciborrudnicki Apr 25, 2021
90ffab1
feat(isNumberType): function to check if any `value` is a `number` type
sciborrudnicki Apr 25, 2021
227111f
refactor(isNumber): update
sciborrudnicki Apr 25, 2021
b982e83
feat(isStringObject): function to check if any `value` is a `String` …
sciborrudnicki Apr 25, 2021
0e8858d
feat(isStringType): function to check if any `value` is a `string`
sciborrudnicki Apr 25, 2021
0cdf5a2
refactor(guardArray): update
sciborrudnicki Apr 25, 2021
0968a95
refactor(guardArray): change parameter name to `value` and update jsdoc
sciborrudnicki Apr 26, 2021
953c75a
refactor(guardFunction): change parameter name to value, update jsdoc…
sciborrudnicki Apr 26, 2021
c15af04
refactor(guardKey): update
sciborrudnicki Apr 26, 2021
c0576bb
docs(guardKey): update
sciborrudnicki Apr 26, 2021
cce8679
docs(guardNumber): categorize imports and update jsdoc `returns` and …
sciborrudnicki Apr 26, 2021
c08254c
refactor(guardObject): update
sciborrudnicki Apr 26, 2021
3f8e171
refactor(guardObjectKey): update
sciborrudnicki Apr 26, 2021
a8ea20d
refactor(guardPrimitive): update
sciborrudnicki Apr 26, 2021
47f746e
docs(guardString): categorize imports, update jsdoc
sciborrudnicki Apr 26, 2021
a2a5311
refactor(isPrimitive): update
sciborrudnicki Apr 26, 2021
57b85e5
refactor(IsPrimitive): use `Primitive` type
sciborrudnicki Apr 26, 2021
85bc471
refactor(isType): update
sciborrudnicki Apr 26, 2021
625b907
refactor(IsType)L use the `Type` instead of generic `Type`
sciborrudnicki Apr 26, 2021
d6510b4
refactor(guardObject): update
sciborrudnicki Apr 26, 2021
2358217
chore(type): update
sciborrudnicki Apr 26, 2021
590e347
refactor(GuardType): change a generic `Type` to the `Type`
sciborrudnicki Apr 26, 2021
e203d5f
refactor(GuardPrimitive): change a generic `Type` to the `Primitive`
sciborrudnicki Apr 26, 2021
ad16835
refactor(GuardObject): change parameter to value, extends a generic `…
sciborrudnicki Apr 26, 2021
d5d01f8
chore(type): add jsdoc
sciborrudnicki Apr 26, 2021
ec4102c
style(isNot): sort alphabetically imports
sciborrudnicki Apr 26, 2021
b43a7d1
refactor(is): add functions
sciborrudnicki Apr 26, 2021
77dd5b5
docs(isType): update
sciborrudnicki Apr 26, 2021
1b9e239
refactor(Is): add functions
sciborrudnicki Apr 26, 2021
e95dc80
docs: update jsdoc
sciborrudnicki Apr 26, 2021
3d64d5e
chore(is): export all features
sciborrudnicki Apr 26, 2021
618d556
refactor(GuardObjectKey): change param to `value` and extends `Obj` w…
sciborrudnicki Apr 26, 2021
9664350
refactor(GuardFunction): change param name to `value`
sciborrudnicki Apr 26, 2021
9b67fb0
chore: categorize imports
sciborrudnicki Apr 26, 2021
c2ab330
chore: update jsdoc, prettier code
sciborrudnicki Apr 26, 2021
ce591c8
refactor(guardType): use `Type` instead of generic, update jsdoc
sciborrudnicki Apr 26, 2021
a37001b
refactor(guardObjectKey): extends `Obj` with `object` , update `value…
sciborrudnicki Apr 26, 2021
c84c270
docs(README.md): update
sciborrudnicki Apr 26, 2021
04a5ae5
docs(README.md): fix table of contents
sciborrudnicki Apr 26, 2021
10bd067
docs: update
sciborrudnicki Apr 26, 2021
e2c2611
refactor(IsObjectKey): change param name to `value`
sciborrudnicki Apr 26, 2021
1fe1841
refactor(isObjectKey): change param name to `value`, extends Type wit…
sciborrudnicki Apr 26, 2021
12863e5
docs(README.md): update
sciborrudnicki Apr 26, 2021
db5ba39
docs(isArray): update
sciborrudnicki Apr 27, 2021
b0bd90e
test(isBigInt): update
sciborrudnicki Apr 27, 2021
90e6df4
test(isArray): use `toBe`
sciborrudnicki Apr 27, 2021
2580220
test: style one line
sciborrudnicki Apr 27, 2021
dd5546e
refactor(isDefined): add `callback`, update jsdoc
sciborrudnicki Apr 27, 2021
bc51725
refactor(IsDefined): add `callback`
sciborrudnicki Apr 27, 2021
31e05be
test(isDefined): update
sciborrudnicki Apr 27, 2021
8900e99
refactor(isFunction): add `callback` to type and function, update jsdoc
sciborrudnicki Apr 27, 2021
ea56696
test(isFunction): update
sciborrudnicki Apr 27, 2021
ec82843
test(class): add more classes
sciborrudnicki Apr 27, 2021
79b44b8
refactor(IsInstance): add callback
sciborrudnicki Apr 27, 2021
a309e41
test: update and add `callback`
sciborrudnicki Apr 27, 2021
bc703fa
refactor(isInstance): add `callback` and update jsdoc
sciborrudnicki Apr 27, 2021
d9fbc2a
refactor(isKey): add `callback`
sciborrudnicki Apr 27, 2021
bf4d134
test(isKey): add
sciborrudnicki Apr 27, 2021
ab572c6
refactor(isNull): add `callback`
sciborrudnicki Apr 27, 2021
e87c4f9
test(isNull): use `toBe` method
sciborrudnicki Apr 27, 2021
6c394e2
chore(isNumber): add `callback` to type and update jsdoc
sciborrudnicki Apr 27, 2021
9981078
test(isNumbeR): use `toBe` method
sciborrudnicki Apr 27, 2021
6807086
test(isNumber): add comment
sciborrudnicki Apr 27, 2021
c8bbf9d
docs(isNumberObject): update main description
sciborrudnicki Apr 27, 2021
4e9863d
test(isNumberObject): add
sciborrudnicki Apr 27, 2021
95edf5b
test: remove unnecessary comment
sciborrudnicki Apr 27, 2021
ff2327c
test(isNumberType): add
sciborrudnicki Apr 27, 2021
1342123
test(is): add all functions
sciborrudnicki Apr 27, 2021
cd904b1
docs(guardObjecKey): fix `key` description
sciborrudnicki Apr 27, 2021
dedd551
docs(README.md): update
sciborrudnicki Apr 27, 2021
9692870
test: categorize imports and add semicolon
sciborrudnicki Apr 28, 2021
f7a864d
docs(isObject): update description and `key` parameter
sciborrudnicki Apr 28, 2021
269d8e6
test: add semicolon, new way if test `isObject`
sciborrudnicki Apr 28, 2021
0557983
refactor(isObjectKey): update jsdocs, add `callback`
sciborrudnicki Apr 28, 2021
b7d2121
refactor(isBigInt): add `callback`
sciborrudnicki Apr 28, 2021
0fdb10e
test: parameter`callback`
sciborrudnicki Apr 28, 2021
cdbc5a6
refactor(isSymbol): add parameter `callback
sciborrudnicki Apr 28, 2021
f0cb95e
test: update
sciborrudnicki Apr 28, 2021
993acc8
test(isSymbol): fix check string
sciborrudnicki Apr 28, 2021
d046d0e
refactor: change `errorCallback` to `resultCallback`
sciborrudnicki Apr 28, 2021
e798eb1
style(isObjectKey): move `resultCallback` up
sciborrudnicki Apr 28, 2021
a32c0f5
style(isString): reorder function imports, add comment
sciborrudnicki Apr 28, 2021
6c84516
feat(isPrimitive): add `callback` feature
sciborrudnicki Apr 28, 2021
2635f83
test: add `isPrimitive` spec and comment unnecessary `callback` check
sciborrudnicki Apr 28, 2021
19bcb58
test(isUndefined): add
sciborrudnicki Apr 28, 2021
cb90075
docs(README.md): update
sciborrudnicki Apr 28, 2021
561f4d9
refactor(api): add features
sciborrudnicki Apr 28, 2021
2744bcd
refactor(api): export all types
sciborrudnicki Apr 28, 2021
307ee24
docs(REAME.md): update
sciborrudnicki Apr 28, 2021
0604d04
test: add `isStringObject`, `isStringType`
sciborrudnicki Apr 28, 2021
e83db1b
feat(isType): add `callback` feature and test for it
sciborrudnicki Apr 28, 2021
098cab6
feat(isArray): add `ResultCallback` feature
sciborrudnicki Apr 28, 2021
605470d
test: add all `isNot`
sciborrudnicki Apr 28, 2021
9bbb5e0
feat: all `ResultCallback` feature to all functions
sciborrudnicki Apr 28, 2021
8c674cb
docs(README.md): update
sciborrudnicki Apr 30, 2021
d4aab97
docs(README.md): update
sciborrudnicki Apr 30, 2021
023bd3f
docs(README.md): update
sciborrudnicki Apr 30, 2021
becf857
refactor(isString): change the order of check by setting type as first
sciborrudnicki May 2, 2021
9b7672d
feat: add features
sciborrudnicki May 2, 2021
54a56e4
chore: add feature to exports
sciborrudnicki May 2, 2021
1fa3645
refactor: add `callback` to guard function types
sciborrudnicki May 2, 2021
42f3534
refactor: add `callback` to guard functions
sciborrudnicki May 2, 2021
433c44f
chore: categorize and sort imports
sciborrudnicki May 2, 2021
fe30bc0
refactor(GuardIs): add features to interface
sciborrudnicki May 2, 2021
cf3d95e
test: add guardBigInt and `guard` object tests
sciborrudnicki May 2, 2021
4ab26c7
feat(isParam): experimental decorator
sciborrudnicki May 3, 2021
151d3b6
refactor(isParam): remove `type`
sciborrudnicki May 3, 2021
5d57ed9
feat(BigIntObject): experimental BigIntObject
sciborrudnicki May 3, 2021
73d4667
feat(SymbolObject): experimental symbol
sciborrudnicki May 3, 2021
475faa1
feat(BooleanObject): experimental object for boolean
sciborrudnicki May 3, 2021
c579f9e
feat(NumberObject): experimental object for number
sciborrudnicki May 3, 2021
0e8b902
feat(StringObject): experimental object for string
sciborrudnicki May 3, 2021
def17e6
test(guardBigInt): update
sciborrudnicki May 3, 2021
5705965
feat(PrimitiveObject): object to hold static primitives
sciborrudnicki May 3, 2021
6904499
test(BooleanObject): fix to use boolean
sciborrudnicki May 3, 2021
a595e8f
test(BooleanObject): update
sciborrudnicki May 3, 2021
86e1ef4
docs(README.md): update
sciborrudnicki May 3, 2021
d90310b
docs(README.md): fix
sciborrudnicki May 3, 2021
b90e9bb
docs(README.md): update
sciborrudnicki May 3, 2021
e7e7389
chore(guardSymbol): remove import
sciborrudnicki May 3, 2021
3608fc8
chore(package): update
sciborrudnicki May 3, 2021
38bcb42
docs(README.md): fix for npm
sciborrudnicki May 3, 2021
fb2a8bf
chore(package): update
sciborrudnicki May 3, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,716 changes: 1,331 additions & 385 deletions README.md

Large diffs are not rendered by default.

1,716 changes: 1,331 additions & 385 deletions packages/type/README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/type/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/type/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@angular-package/type",
"version": "3.1.2",
"version": "3.2.1",
"description": "Common types, type guards and type checkers.",
"author": "Angular Package <[email protected]> (https://wvvw.dev)",
"homepage": "https://github.com/angular-package/type#readme",
Expand Down
14 changes: 11 additions & 3 deletions packages/type/src/guard/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
// `guard` object.
export { guard } from './lib/guard.object';

export { guardArray } from './lib/guard-array.func.type';
// `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';
19 changes: 15 additions & 4 deletions packages/type/src/guard/interface/guard-is.interface.ts
Original file line number Diff line number Diff line change
@@ -1,22 +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 { 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;
// TODO: Guard not
// not: GuardNotIs;
instance: GuardInstance;
key: GuardKey;
null: GuardNull;
number: GuardNumber;
object: GuardObject;
objectKey: GuardObjectKey;
primitive: GuardPrimitive;
string: GuardString;
symbol: GuardSymbol;
type: GuardType;
undefined: GuardUndefined;
}
13 changes: 13 additions & 0 deletions packages/type/src/guard/lib/guard-array.func.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Function.
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 = <Type>(value: Array<Type>, callback?: ResultCallback): value is Array<Type> =>
isArray<Type>(value, callback);
9 changes: 0 additions & 9 deletions packages/type/src/guard/lib/guard-array.func.type.ts

This file was deleted.

13 changes: 13 additions & 0 deletions packages/type/src/guard/lib/guard-big-int.func.ts
Original file line number Diff line number Diff line change
@@ -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);
13 changes: 13 additions & 0 deletions packages/type/src/guard/lib/guard-boolean.func.ts
Original file line number Diff line number Diff line change
@@ -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);
15 changes: 10 additions & 5 deletions packages/type/src/guard/lib/guard-function.func.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
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';
import { ResultCallback } from '../../type/result-callback.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 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 = (func: Func): func is Func => isFunction(func);
export const guardFunction: GuardFunction = (value: Func, callback?: ResultCallback): value is Func =>
isFunction(value, callback);
15 changes: 15 additions & 0 deletions packages/type/src/guard/lib/guard-instance.func.ts
Original file line number Diff line number Diff line change
@@ -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 = <Obj>(value: Obj, instance: Constructor<Obj>, callback?: ResultCallback): value is Obj =>
isInstance<Obj>(value, instance, callback);
27 changes: 21 additions & 6 deletions packages/type/src/guard/lib/guard-is.object.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
import { GuardIs } from '../interface/guard-is.interface';
import { guardArray } from './guard-array.func.type';
// 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 { guardUndefined } from './guard-undefined.func';
// Interface.
import { GuardIs } from '../interface/guard-is.interface';
// `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
};
14 changes: 14 additions & 0 deletions packages/type/src/guard/lib/guard-key.func.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Function.
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, callback?: ResultCallback): value is Key =>
isKey(value, callback);
13 changes: 13 additions & 0 deletions packages/type/src/guard/lib/guard-null.func.ts
Original file line number Diff line number Diff line change
@@ -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);
14 changes: 9 additions & 5 deletions packages/type/src/guard/lib/guard-number.func.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// Function.
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` 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.
* @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);
17 changes: 9 additions & 8 deletions packages/type/src/guard/lib/guard-object-key.func.ts
Original file line number Diff line number Diff line change
@@ -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` to guard.
* @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 = <Obj, Key extends keyof Obj>(object: Obj, key: Key): object is Obj =>
guardObject<Obj>(object) ? isString(key) ? key in object : true : false;
export const guardObjectKey: GuardObjectKey = <Obj extends object, Key extends keyof Obj>(value: Obj, key: Key): value is Obj =>
guardObject<Obj>(value) ? isKey(key) ? key in value : true : false;
16 changes: 10 additions & 6 deletions packages/type/src/guard/lib/guard-object.func.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { GuardObject } from '../type/guard-object.type';
// Function.
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 `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.
* @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 = <Obj>(object: Obj): object is Obj => isObject<Obj>(object);
export const guardObject: GuardObject = <Obj extends object>(value: Obj, callback?: ResultCallback): value is Obj =>
isObject<Obj>(value);
19 changes: 13 additions & 6 deletions packages/type/src/guard/lib/guard-primitive.func.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
// 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';
import { ResultCallback } from '../../type/result-callback.type';
/**
* 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 `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 = <Type>(value: Type, type: Primitives): value is Type => isPrimitive(value, type);
export const guardPrimitive: GuardPrimitive =
<Type extends Primitive>(value: Type, type: Primitives, callback?: ResultCallback): value is Type =>
isPrimitive<Type>(value, type, callback);
15 changes: 10 additions & 5 deletions packages/type/src/guard/lib/guard-string.func.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { GuardString } from '../type/guard-string.type';
// Function.
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` 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.
* @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);
13 changes: 13 additions & 0 deletions packages/type/src/guard/lib/guard-symbol.func.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Function.
import { isSymbol } from '../../is/lib/is-symbol.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);
16 changes: 11 additions & 5 deletions packages/type/src/guard/lib/guard-type.func.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
// Function.
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 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 `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 = <Type>(value: Type, type: Types<Type>): value is Type => isType<Type>(value, type);
export const guardType: GuardType = <T extends Type>(value: T, type: Types<T>, callback?: ResultCallback): value is T =>
isType<T>(value, type, callback);
13 changes: 13 additions & 0 deletions packages/type/src/guard/lib/guard-undefined.func.ts
Original file line number Diff line number Diff line change
@@ -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);
Loading