Skip to content

Commit

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

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

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

import testSubject from '../is-int'

describe('unit:guards/isInt', () => {
it('should return false if value is not an integer', () => {
expect(testSubject(faker.number.float({ min: 0.13 }))).to.be.false
})

it('should return true if value is an integer', () => {
expect(testSubject(faker.number.int())).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 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'
Expand Down
18 changes: 18 additions & 0 deletions src/guards/is-int.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @file Type Guards - isInt
* @module tutils/guards/isInt
*/

import isNumber from './is-number'

/**
* Checks if the given `value` is an integer.
*
* @param {unknown} value - Value to evaluate
* @return {value is number} `true` if `value` is an integer
*/
const isInt = (value: unknown): value is number => {
return isNumber(value) && value % 1 === 0
}

export default isInt

0 comments on commit 2f6588c

Please sign in to comment.