-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
503bd02
commit 10e807f
Showing
4 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* @file Type Tests - isNumeric | ||
* @module tutils/guards/tests/unit-d/isNumeric | ||
*/ | ||
|
||
import type { Numeric } from '#src/types' | ||
import type testSubject from '../is-numeric' | ||
|
||
describe('unit-d:guards/isNumeric', () => { | ||
it('should guard Numeric', () => { | ||
expectTypeOf<typeof testSubject>().guards.toEqualTypeOf<Numeric>() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @file Unit Tests - isNumeric | ||
* @module tutils/guards/tests/unit/isNumeric | ||
*/ | ||
|
||
import testSubject from '../is-numeric' | ||
|
||
describe('unit:guards/isNumeric', () => { | ||
it('should return false if value is not a numeric', () => { | ||
expect(testSubject(faker.string.sample())).to.be.false | ||
}) | ||
|
||
it('should return true if value is a numeric', () => { | ||
expect(testSubject(faker.string.numeric())).to.be.true | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* @file Type Guards - isNumeric | ||
* @module tutils/guards/isNumeric | ||
*/ | ||
|
||
import type { Numeric } from '#src/types' | ||
import isNumber from './is-number' | ||
import isString from './is-string' | ||
|
||
/** | ||
* Checks if the given `value` is a numeric. | ||
* | ||
* A numeric is a string that contains only numbers. | ||
* | ||
* @param {unknown} value - Value to evaluate | ||
* @return {value is Numeric} `true` if `value` is a {@linkcode Numeric} | ||
*/ | ||
const isNumeric = (value: unknown): value is Numeric => { | ||
return isString(value) && isNumber(+value) | ||
} | ||
|
||
export default isNumeric |