Skip to content

Commit

Permalink
feat(guards): isUndefined
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Feb 1, 2023
1 parent 818d625 commit 9f3a6d7
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/guards/__tests__/is-undefined.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @file Type Tests - isUndefined
* @module tutils/guards/tests/unit-d/isUndefined
*/

import type testSubject from '../is-undefined'

describe('unit-d:guards/isUndefined', () => {
it('should guard undefined', () => {
expectTypeOf<typeof testSubject>().guards.toBeUndefined()
})
})
16 changes: 16 additions & 0 deletions src/guards/__tests__/is-undefined.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @file Unit Tests - isUndefined
* @module tutils/guards/tests/unit/isUndefined
*/

import testSubject from '../is-undefined'

describe('unit:guards/isUndefined', () => {
it('should return false if value is not undefined', () => {
expect(testSubject(faker.datatype.array())).to.be.false
})

it('should return true if value is undefined', () => {
expect(testSubject(undefined)).to.be.true
})
})
1 change: 1 addition & 0 deletions src/guards/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export { default as isNIL } from './is-nil'
export { default as isNodeEnv } from './is-node-env'
export { default as isNull } from './is-null'
export { default as isNumber } from './is-number'
export { default as isUndefined } from './is-undefined'
3 changes: 2 additions & 1 deletion src/guards/is-nil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import type { NIL } from '#src/types'
import isNull from './is-null'
import isUndefined from './is-undefined'

/**
* Checks if the given `value` is `null` or `undefined`.
Expand All @@ -13,7 +14,7 @@ import isNull from './is-null'
* @return {value is NIL} `true` if `value` is {@linkcode NIL}
*/
const isNIL = (value: unknown): value is NIL => {
return isNull(value) || value === undefined
return isNull(value) || isUndefined(value)
}

export default isNIL
14 changes: 14 additions & 0 deletions src/guards/is-undefined.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @file Type Guards - isUndefined
* @module tutils/guards/isUndefined
*/

/**
* Checks if the given `value` is `undefined`.
*
* @param {unknown} value - Value to evaluate
* @return {value is undefined} `true` if `value` is `undefined`
*/
const isUndefined = (value: unknown): value is undefined => value === undefined

export default isUndefined

0 comments on commit 9f3a6d7

Please sign in to comment.