Skip to content

Commit f5dcad1

Browse files
docs(README.md): update
1 parent ed92383 commit f5dcad1

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {
2626
guardArray,
2727
guardBigInt,
2828
guardBoolean,
29+
guardClass,
30+
guardDefined,
2931
guardFunction,
3032
guardInstance,
3133
guardKey,
@@ -98,7 +100,7 @@ import { are, guard, is, isNot } from '@angular-package/type';
98100

99101
```typescript
100102
// Types.
101-
import { Constructor, CycleHook, Func, Key, Primitive, Primitives, ResultCallback, Type, Types } from '@angular-package/type';
103+
import { Constructor, CycleHook, Defined, Func, Key, Primitive, Primitives, ResultCallback, Type, Types } from '@angular-package/type';
102104
```
103105

104106
## Features
@@ -142,6 +144,7 @@ import { Constructor, CycleHook, Func, Key, Primitive, Primitives, ResultCallbac
142144
* a `bigint` with [`guardBigInt()`](#guardbigint).
143145
* a `boolean` with [`guardBoolean()`](#guardboolean).
144146
* a generic `Class` type [`class`][classes] with [`guardClass()`](#guardclass).
147+
* defined with [`guardDefined()`](#guarddefined).
145148
* a [`Func`](#func) type with [`guardFunction()`](#guardfunction).
146149
* an instance with [`guardInstance()`](#guardinstance).
147150
* a `null` with [`guardNull()`](#guardnull).
@@ -1692,6 +1695,26 @@ guardClass<Class>(FUNCTION); // type error
16921695

16931696
----
16941697

1698+
### guardDefined
1699+
1700+
![new][new]
1701+
1702+
Use `guardDefined()` or `guard.is.defined()` to guard the `value` to be defined.
1703+
1704+
```typescript
1705+
const guardDefined: GuardDefined = <Type>(value: Type, callback?: ResultCallback): value is Defined<Type> =>
1706+
isDefined(value, callback);
1707+
```
1708+
1709+
| Parameter | Type | Description |
1710+
| :-------- | :-------------------------------------: | :--------------------------------------------------- |
1711+
| value | `Type` | A generic type `value` to guard |
1712+
| callback? | [`ResultCallback`][resultcallback] | An Optional [`ResultCallback`][resultcallback] function to handle result before returns eg. to throw an `Error` |
1713+
1714+
The **return value** is A `boolean` indicating whether or not the `value` is defined, if `undefined` then returns `never`.
1715+
1716+
----
1717+
16951718
### guardFunction
16961719

16971720
![update][update]
@@ -1969,6 +1992,12 @@ type AnyString = string | String;
19691992
type Constructor<Type> = new (...args: any[]) => Type;
19701993
```
19711994

1995+
### Defined
1996+
1997+
```typescript
1998+
type Defined<T> = T extends undefined ? never : T;
1999+
```
2000+
19722001
### CycleHook
19732002

19742003
```typescript
@@ -2311,6 +2340,7 @@ How do I know when to release 1.0.0?
23112340
MIT © angular-package ([license](https://github.com/angular-package/type/blob/main/LICENSE))
23122341

23132342
[callback]: #callback
2343+
[defined]: #defined
23142344
[resultcallback]: #resultcallback
23152345
[key]: #key
23162346
[type]: #type

packages/type/README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {
2626
guardArray,
2727
guardBigInt,
2828
guardBoolean,
29+
guardClass,
30+
guardDefined,
2931
guardFunction,
3032
guardInstance,
3133
guardKey,
@@ -98,7 +100,7 @@ import { are, guard, is, isNot } from '@angular-package/type';
98100

99101
```typescript
100102
// Types.
101-
import { Constructor, CycleHook, Func, Key, Primitive, Primitives, ResultCallback, Type, Types } from '@angular-package/type';
103+
import { Constructor, CycleHook, Defined, Func, Key, Primitive, Primitives, ResultCallback, Type, Types } from '@angular-package/type';
102104
```
103105

104106
## Features
@@ -142,6 +144,7 @@ import { Constructor, CycleHook, Func, Key, Primitive, Primitives, ResultCallbac
142144
* a `bigint` with [`guardBigInt()`](#guardbigint).
143145
* a `boolean` with [`guardBoolean()`](#guardboolean).
144146
* a generic `Class` type [`class`][classes] with [`guardClass()`](#guardclass).
147+
* defined with [`guardDefined()`](#guarddefined).
145148
* a [`Func`](#func) type with [`guardFunction()`](#guardfunction).
146149
* an instance with [`guardInstance()`](#guardinstance).
147150
* a `null` with [`guardNull()`](#guardnull).
@@ -1692,6 +1695,26 @@ guardClass<Class>(FUNCTION); // type error
16921695

16931696
----
16941697

1698+
### guardDefined
1699+
1700+
![new][new]
1701+
1702+
Use `guardDefined()` or `guard.is.defined()` to guard the `value` to be defined.
1703+
1704+
```typescript
1705+
const guardDefined: GuardDefined = <Type>(value: Type, callback?: ResultCallback): value is Defined<Type> =>
1706+
isDefined(value, callback);
1707+
```
1708+
1709+
| Parameter | Type | Description |
1710+
| :-------- | :-------------------------------------: | :--------------------------------------------------- |
1711+
| value | `Type` | A generic type `value` to guard |
1712+
| callback? | [`ResultCallback`][resultcallback] | An Optional [`ResultCallback`][resultcallback] function to handle result before returns eg. to throw an `Error` |
1713+
1714+
The **return value** is A `boolean` indicating whether or not the `value` is defined, if `undefined` then returns `never`.
1715+
1716+
----
1717+
16951718
### guardFunction
16961719

16971720
![update][update]
@@ -1969,6 +1992,12 @@ type AnyString = string | String;
19691992
type Constructor<Type> = new (...args: any[]) => Type;
19701993
```
19711994

1995+
### Defined
1996+
1997+
```typescript
1998+
type Defined<T> = T extends undefined ? never : T;
1999+
```
2000+
19722001
### CycleHook
19732002

19742003
```typescript
@@ -2311,6 +2340,7 @@ How do I know when to release 1.0.0?
23112340
MIT © angular-package ([license](https://github.com/angular-package/type/blob/main/LICENSE))
23122341

23132342
[callback]: #callback
2343+
[defined]: #defined
23142344
[resultcallback]: #resultcallback
23152345
[key]: #key
23162346
[type]: #type

0 commit comments

Comments
 (0)