Skip to content

Commit

Permalink
add utility for checking if a value is null or undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
xoldd committed Dec 2, 2024
1 parent 0c2f7ec commit 7085979
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/utilities/isNotNullish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* This function is used to check nullish state of a value passed to it. Nullish means the value being either `null` or `undefined`. If the value is found to be nullish, the function returns the boolean `false`, else it returns the boolean `true`.
* @example
* Here's an example:-
* function print(str: string | null) \{
* if(isNotNullish(str)) \{
* console.log(`the string is ${str}`)
* \} else \{
* console.log(`the string is null`)
* \}
* \}
*/
export function isNotNullish<T0>(value: T0 | undefined | null): value is T0 {
return value !== undefined && value !== null;
}

0 comments on commit 7085979

Please sign in to comment.