Skip to content

Commit

Permalink
feat(guards): isFunction
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 2f6588c commit 6219e77
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/guards/__tests__/is-function.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @file Type Tests - isFunction
* @module tutils/guards/tests/unit-d/isFunction
*/

import type { Fn } from '#src/types'
import type testSubject from '../is-function'

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

import testSubject from '../is-function'

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

it('should return true if value is a function', () => {
expect(testSubject(vi.fn())).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 @@ -10,6 +10,7 @@ export { default as isBooleanish } from './is-booleanish'
export { default as isEmptyString } from './is-empty-string'
export { default as isEmptyValue } from './is-empty-value'
export { default as isFloat } from './is-float'
export { default as isFunction } from './is-function'
export { default as isInt } from './is-int'
export { default as isJwtType } from './is-jwt-type'
export { default as isNIL } from './is-nil'
Expand Down
16 changes: 16 additions & 0 deletions src/guards/is-function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @file Type Guards - isFunction
* @module tutils/guards/isFunction
*/

import type { Fn } from '#src/types'

/**
* Checks if the given `value` is a function.
*
* @param {unknown} value - Value to evaluate
* @return {value is Fn} `true` if `value` is a function
*/
const isFunction = (value: unknown): value is Fn => typeof value === 'function'

export default isFunction

0 comments on commit 6219e77

Please sign in to comment.