generated from sapphiredev/sapphire-template
-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(utilities): add tsdoc for filter functions
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
import { isNullOrUndefined } from './isNullOrUndefined'; | ||
import type { Nullish } from './utilityTypes'; | ||
|
||
/** | ||
* Checks whether a value is not `null` nor `undefined`. | ||
* This can be used in {@link Array.filter} to remove `null` and `undefined` from the array type | ||
* @param value The value to verify that is neither `null` nor `undefined` | ||
* @returns A boolean that is `true` if the value is neither `null` nor `undefined`, false otherwise. | ||
* @example | ||
* ```typescript | ||
* // TypeScript Type: (string | undefined | null)[] | ||
* const someArray = ['one', 'two', undefined, null, 'five']; | ||
* | ||
* // TypeScript Type: string[] | ||
* const filteredArray = someArray.filter(filterNullAndUndefined); | ||
* // Result: ['one', 'two', 'five'] | ||
* ``` | ||
*/ | ||
export function filterNullAndUndefined<TValue>(value: TValue | Nullish): value is TValue { | ||
return !isNullOrUndefined(value); | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/utilities/src/lib/filterNullAndUndefinedAndEmpty.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
import { isNullOrUndefinedOrEmpty } from './isNullOrUndefinedOrEmpty'; | ||
import type { Nullish } from './utilityTypes'; | ||
|
||
/** | ||
* Checks whether a value is not `null` nor `undefined` nor `''` (empty string). | ||
* This can be used in {@link Array.filter} to remove `null`, `undefined` from the array type | ||
* @param value The value to verify that is neither `null`, `undefined` nor `''` (empty string) | ||
* @returns A boolean that is `true` if the value is neither `null`, `undefined` nor `''` (empty string), false otherwise. | ||
* @example | ||
* ```typescript | ||
* // TypeScript Type: (string | undefined | null)[] | ||
* const someArray = ['one', 'two', undefined, null, '']; | ||
* | ||
* // TypeScript Type: string[] | ||
* const filteredArray = someArray.filter(filterNullAndUndefinedAndEmpty); | ||
* // Result: ['one', 'two'] | ||
* ``` | ||
*/ | ||
export function filterNullAndUndefinedAndEmpty<TValue>(value: TValue | Nullish | ''): value is TValue { | ||
return !isNullOrUndefinedOrEmpty(value); | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/utilities/src/lib/filterNullAndUndefinedAndZero.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
import { isNullOrUndefinedOrZero } from './isNullOrUndefinedOrZero'; | ||
import type { Nullish } from './utilityTypes'; | ||
|
||
/** | ||
* Checks whether a value is not `null` nor `undefined` nor `0`. | ||
* This can be used in {@link Array.filter} to remove `null`, `undefined` from the array type | ||
* @param value The value to verify that is neither `null`, `undefined` nor `0` | ||
* @returns A boolean that is `true` if the value is neither `null`, `undefined` nor `0`, false otherwise. | ||
* @example | ||
* ```typescript | ||
* // TypeScript Type: (string | number | undefined | null)[] | ||
* const someArray = ['one', 'two', undefined, null, 0, 1]; | ||
* | ||
* // TypeScript Type: (string | number)[] | ||
* const filteredArray = someArray.filter(filterNullAndUndefinedAndZero); | ||
* // Result: ['one', 'two', 1] | ||
* ``` | ||
*/ | ||
export function filterNullAndUndefinedAndZero<TValue>(value: TValue | Nullish | 0): value is TValue { | ||
return !isNullOrUndefinedOrZero(value); | ||
} |