Skip to content

Commit 094e295

Browse files
committed
feat: new function - isDef & isUndef
1 parent ee47572 commit 094e295

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ pnpm add @utopia-utils/share
144144
* isPlainObject
145145
* isObject
146146
* isIntegerKey
147+
* isUndef
148+
* isDef
147149
* isEmpty [source](https://github.com/GreatAuk/utopia-utils/blob/main/packages/share/src/isEmpty.ts)
148150
* isNumberLike [source](https://github.com/GreatAuk/utopia-utils/blob/main/packages/share/src/isNumberLike.ts)
149151
* isValidUrl [source](https://github.com/GreatAuk/utopia-utils/blob/main/packages/share/src/isValidUrl.ts)

packages/share/src/is.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,7 @@ export const isStringNumber = (val: string): boolean => {
4848
return false
4949
return !Number.isNaN(Number(val))
5050
}
51+
52+
export const isDef = <T>(val: T): val is NonNullable<T> => val !== undefined && val !== null
53+
54+
export const isUndef = (val: any): val is (undefined | null) => val === undefined || val === null

0 commit comments

Comments
 (0)