Skip to content

Commit

Permalink
feat(guards): isNull
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 6219e77 commit 818d625
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-null.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @file Type Tests - isNull
* @module tutils/guards/tests/unit-d/isNull
*/

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

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

import testSubject from '../is-null'

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

it('should return true if value is null', () => {
expect(testSubject(null)).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 @@ -15,4 +15,5 @@ export { default as isInt } from './is-int'
export { default as isJwtType } from './is-jwt-type'
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'
3 changes: 2 additions & 1 deletion src/guards/is-nil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

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

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

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

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

export default isNull

0 comments on commit 818d625

Please sign in to comment.