From cc9d636dbbe62fdcf0cb3da9a25aaf97661b890c Mon Sep 17 00:00:00 2001 From: marlonpassos Date: Mon, 16 Sep 2024 19:02:10 +0000 Subject: [PATCH 1/2] fix(inNumber)!: now return true for NaN --- docs/typed/isNumber.mdx | 1 + src/typed/isNumber.ts | 4 ++-- tests/typed/isNumber.test.ts | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/typed/isNumber.mdx b/docs/typed/isNumber.mdx index 4278aa59..928a8afa 100644 --- a/docs/typed/isNumber.mdx +++ b/docs/typed/isNumber.mdx @@ -13,4 +13,5 @@ import * as _ from 'radashi' _.isNumber('hello') // => false _.isNumber(['hello']) // => false _.isNumber(12) // => true +_.isNumber(NaN) // => true ``` diff --git a/src/typed/isNumber.ts b/src/typed/isNumber.ts index 2bc475a1..eaed6b64 100644 --- a/src/typed/isNumber.ts +++ b/src/typed/isNumber.ts @@ -6,9 +6,9 @@ * ```ts * isNumber(0) // => true * isNumber('0') // => false - * isNumber(NaN) // => false + * isNumber(NaN) // => true * ``` */ export function isNumber(value: unknown): value is number { - return typeof value === 'number' && !Number.isNaN(value) + return typeof value === 'number' } diff --git a/tests/typed/isNumber.test.ts b/tests/typed/isNumber.test.ts index 3ed844ba..0527c297 100644 --- a/tests/typed/isNumber.test.ts +++ b/tests/typed/isNumber.test.ts @@ -26,9 +26,9 @@ describe('isNumber', () => { const result = _.isNumber(22.0567) expect(result).toBeTruthy() }) - test('returns false for NaN', () => { + test('returns true for NaN', () => { const result = _.isNumber(Number.NaN) - expect(result).toBeFalsy() + expect(result).toBeTruthy() }) test('returns false for array', () => { const result = _.isNumber([1, 2, 3]) From 9de9f474f950e3f0881e6eb6c84d71915b605827 Mon Sep 17 00:00:00 2001 From: marlonpassos Date: Mon, 16 Sep 2024 19:10:57 +0000 Subject: [PATCH 2/2] fix(isFloat): resolver NaN case --- src/typed/isFloat.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/typed/isFloat.ts b/src/typed/isFloat.ts index fa44892f..0b944722 100644 --- a/src/typed/isFloat.ts +++ b/src/typed/isFloat.ts @@ -11,5 +11,5 @@ import { isNumber } from 'radashi' * ``` */ export function isFloat(value: any): value is number { - return isNumber(value) && value % 1 !== 0 + return isNumber(value) && !Number.isNaN(value) && value % 1 !== 0 }