Skip to content

Commit

Permalink
feat: new function - isDef & isUndef
Browse files Browse the repository at this point in the history
  • Loading branch information
GreatAuk committed Apr 30, 2024
1 parent ee47572 commit 094e295
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ pnpm add @utopia-utils/share
* isPlainObject
* isObject
* isIntegerKey
* isUndef
* isDef
* isEmpty [source](https://github.com/GreatAuk/utopia-utils/blob/main/packages/share/src/isEmpty.ts)
* isNumberLike [source](https://github.com/GreatAuk/utopia-utils/blob/main/packages/share/src/isNumberLike.ts)
* isValidUrl [source](https://github.com/GreatAuk/utopia-utils/blob/main/packages/share/src/isValidUrl.ts)
Expand Down
4 changes: 4 additions & 0 deletions packages/share/src/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ export const isStringNumber = (val: string): boolean => {
return false
return !Number.isNaN(Number(val))
}

export const isDef = <T>(val: T): val is NonNullable<T> => val !== undefined && val !== null

export const isUndef = (val: any): val is (undefined | null) => val === undefined || val === null

0 comments on commit 094e295

Please sign in to comment.