diff --git a/src/utils/__tests__/is-number.spec.ts b/src/utils/__tests__/is-number.spec.ts index b80cbd68..433df5e2 100644 --- a/src/utils/__tests__/is-number.spec.ts +++ b/src/utils/__tests__/is-number.spec.ts @@ -13,7 +13,6 @@ describe('unit:utils/isNumber', () => { const cases: Parameters[] = [ [[INTEGER]], [Symbol('is-number')], - [Number.NaN], [faker.string.numeric()] ] @@ -23,7 +22,11 @@ describe('unit:utils/isNumber', () => { it('should return true if value is a number', () => { // Arrange - const cases: Parameters[] = [[FLOAT], [INTEGER]] + const cases: Parameters[] = [ + [FLOAT], + [INTEGER], + [Number.NaN] + ] // Act + Expect cases.forEach(([value]) => expect(testSubject(value)).to.be.true) diff --git a/src/utils/is-nan.ts b/src/utils/is-nan.ts index 797a8f6c..ba0e7bf5 100644 --- a/src/utils/is-nan.ts +++ b/src/utils/is-nan.ts @@ -3,7 +3,7 @@ * @module tutils/utils/isNaN */ -import equal from './equal' +import isNumber from './is-number' /** * Checks if `value` is {@linkcode Number.NaN}. @@ -13,6 +13,6 @@ import equal from './equal' * @param {unknown} value - Value to check * @return {boolean} `true` if `value` is `Number.NaN` */ -const isNaN = (value: unknown): boolean => equal(Number.NaN, value) +const isNaN = (value: unknown): boolean => isNumber(value) && value !== +value export default isNaN diff --git a/src/utils/is-number.ts b/src/utils/is-number.ts index 49d7ce34..001ef77f 100644 --- a/src/utils/is-number.ts +++ b/src/utils/is-number.ts @@ -11,12 +11,6 @@ * @param {unknown} value - Value to check * @return {value is number} `true` if `value` is a number */ -const isNumber = (value: unknown): value is number => { - try { - return Number(value) === value - } catch { - return false - } -} +const isNumber = (value: unknown): value is number => typeof value === 'number' export default isNumber diff --git a/src/utils/is-numeric.ts b/src/utils/is-numeric.ts index fd340ab3..79a04693 100644 --- a/src/utils/is-numeric.ts +++ b/src/utils/is-numeric.ts @@ -4,6 +4,7 @@ */ import type { Numeric } from '#src/types' +import isNaN from './is-nan' import isNumber from './is-number' import isString from './is-string' @@ -19,7 +20,7 @@ import isString from './is-string' * @return {value is Numeric} `true` if `value` is a numeric */ const isNumeric = (value: unknown): value is Numeric => { - return isString(value) && isNumber(+value) + return isString(value) && isNumber((value = +value)) && !isNaN(value) } export default isNumeric