Skip to content

Commit b465963

Browse files
Merge pull request #13 from angular-package/4.0.x
4.0.0
2 parents c42e729 + 2045094 commit b465963

35 files changed

+941
-561
lines changed

README.md

Lines changed: 377 additions & 249 deletions
Large diffs are not rendered by default.

packages/type/README.md

Lines changed: 377 additions & 249 deletions
Large diffs are not rendered by default.

packages/type/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/type/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular-package/type",
3-
"version": "3.4.0",
3+
"version": "4.0.0",
44
"description": "Common types, type guards and type checkers.",
55
"author": "Angular Package <[email protected]> (https://wvvw.dev)",
66
"homepage": "https://github.com/angular-package/type#readme",

packages/type/src/guard/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export { guard } from './lib/guard.object';
44
export { guardArray } from './lib/guard-array.func';
55
export { guardBigInt } from './lib/guard-big-int.func';
66
export { guardBoolean } from './lib/guard-boolean.func';
7+
export { guardClass } from './lib/guard-class.func';
8+
export { guardDefined } from './lib/guard-defined.func';
79
export { guardFunction } from './lib/guard-function.func';
810
export { guardInstance } from './lib/guard-instance.func';
911
export { guardKey } from './lib/guard-key.func';

packages/type/src/guard/interface/guard-is.interface.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { GuardArray } from '../type/guard-array.type';
22
import { GuardBigInt } from '../type/guard-big-int.type';
33
import { GuardBoolean } from '../type/guard-boolean.type';
4+
import { GuardClass } from '../type/guard-class.type';
5+
import { GuardDefined } from '../type/guard-defined.type';
46
import { GuardFunction } from '../type/guard-function.type';
57
import { GuardKey } from '../type/guard-key.type';
68
import { GuardNumber } from '../type/guard-number.type';
@@ -18,6 +20,8 @@ export interface GuardIs {
1820
array: GuardArray;
1921
bigint: GuardBigInt;
2022
boolean: GuardBoolean;
23+
class: GuardClass;
24+
defined: GuardDefined;
2125
function: GuardFunction;
2226
instance: GuardInstance;
2327
key: GuardKey;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Function.
2+
import { isClass } from '../../is/lib/is-class.func';
3+
// Type.
4+
import { GuardClass } from '../type/guard-class.type';
5+
import { ResultCallback } from '../../type/result-callback.type';
6+
/**
7+
* Guard the `value` to be a generic `Class` type of `class`.
8+
* @param value A generic `Class` type `value` to guard.
9+
* @param callback An Optional `ResultCallback` function to handle result before returns.
10+
* @returns A `boolean` indicating whether or not the `value` is a generic `class`.
11+
*/
12+
export const guardClass: GuardClass = <Class>(value: Class, callback?: ResultCallback): value is Class =>
13+
isClass<Class>(value, callback);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Function.
2+
import { isDefined } from '../../is/lib/is-defined.func';
3+
// Type.
4+
import { Defined } from '../../type/defined.type';
5+
import { GuardDefined } from '../type/guard-defined.type';
6+
import { ResultCallback } from '../../type/result-callback.type';
7+
/**
8+
* Guard the `value` to be defined.
9+
* @param value A generic type `value` to guard.
10+
* @param callback An optional `ResultCallback` function to handle result before returns.
11+
* @returns A `boolean` indicating whether or not the `value` is defined, if `undefined` then returns `never`.
12+
*/
13+
export const guardDefined: GuardDefined = <Type>(value: Type, callback?: ResultCallback): value is Defined<Type> =>
14+
isDefined(value, callback);

packages/type/src/guard/lib/guard-is.object.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import { guardArray } from './guard-array.func';
33
import { guardBigInt } from './guard-big-int.func';
44
import { guardBoolean } from './guard-boolean.func';
5+
import { guardClass } from './guard-class.func';
6+
import { guardDefined } from './guard-defined.func';
57
import { guardFunction } from './guard-function.func';
68
import { guardInstance } from './guard-instance.func';
79
import { guardKey } from './guard-key.func';
@@ -21,6 +23,8 @@ export const guardIs: GuardIs = {
2123
array: guardArray,
2224
bigint: guardBigInt,
2325
boolean: guardBoolean,
26+
class: guardClass,
27+
defined: guardDefined,
2428
function: guardFunction,
2529
instance: guardInstance,
2630
key: guardKey,
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// Function.
2-
import { guardObject } from './guard-object.func';
3-
import { isKey } from '../../is/lib/is-key.func';
2+
import { isObjectKey } from '../../is/lib/is-object-key.func';
43
// Type.
54
import { GuardObjectKey } from '../type/guard-object-key.type';
5+
import { Key } from '../../type/key.type';
6+
import { ResultCallback } from '../../type/result-callback.type';
67
/**
78
* Guard the `value` to be an `object` of a generic `Obj` type that contains the `key` property of the `Key` type.
89
* @param value A generic `Obj` type `value` that contains the `key` to guard.
9-
* @param key A `Key` type name of the property that the `value` contains.
10+
* @param key A `Key` or `Key[]` type name of the property that the `value` contains.
11+
* @param callback An optional `ResultCallback` function to handle result before returns.
1012
* @returns A `boolean` indicating whether or not the `value` is an `object` of a generic `Obj` containing the `Key`.
1113
*/
12-
export const guardObjectKey: GuardObjectKey = <Obj extends object, Key extends keyof Obj>(value: Obj, key: Key): value is Obj =>
13-
guardObject<Obj>(value) ? isKey(key) ? key in value : true : false;
14+
export const guardObjectKey: GuardObjectKey = <Obj extends object>(value: Obj, key: Key | Key[], callback?: ResultCallback): value is Obj =>
15+
isObjectKey<Obj>(value, key, callback);

0 commit comments

Comments
 (0)