From 10be546bad27258165c453e9cf180acc112e6a38 Mon Sep 17 00:00:00 2001 From: JUSTIVE Date: Sun, 10 Mar 2024 18:28:40 +0900 Subject: [PATCH 1/3] feat: added G.isFinite, G.isInfinite --- __tests__/Guards/isFinite.test.ts | 9 +++++++++ __tests__/Guards/isInfinite.test.ts | 11 +++++++++++ src/Guards/Guards.ts | 2 ++ src/Guards/index.js | 3 +++ src/Guards/index.ts | 3 +++ 5 files changed, 28 insertions(+) create mode 100644 __tests__/Guards/isFinite.test.ts create mode 100644 __tests__/Guards/isInfinite.test.ts diff --git a/__tests__/Guards/isFinite.test.ts b/__tests__/Guards/isFinite.test.ts new file mode 100644 index 00000000..50b842ce --- /dev/null +++ b/__tests__/Guards/isFinite.test.ts @@ -0,0 +1,9 @@ +import { G } from '../..' + +describe('isFinite', () => { + + it('determines whether the provided value is finite', () => { + expect(G.isFinite(0)).toEqual(true) + expect(G.isFinite(Infinity)).toEqual(false) + }) +}) \ No newline at end of file diff --git a/__tests__/Guards/isInfinite.test.ts b/__tests__/Guards/isInfinite.test.ts new file mode 100644 index 00000000..6466eeed --- /dev/null +++ b/__tests__/Guards/isInfinite.test.ts @@ -0,0 +1,11 @@ +import { G } from '../..' + +describe('isInFinite', () => { + + it('determines whether the provided value is finite', () => { + expect(G.isInfinite(0)).toEqual(false) + expect(G.isInfinite(Infinity)).toEqual(true) + expect(G.isInfinite(1/0)).toEqual(true) + }) + +}) \ No newline at end of file diff --git a/src/Guards/Guards.ts b/src/Guards/Guards.ts index e54ac0ba..f48f2b38 100644 --- a/src/Guards/Guards.ts +++ b/src/Guards/Guards.ts @@ -61,3 +61,5 @@ export declare function isNot( predicateFn: (value: A) => any, ): boolean export declare function isDate(value: A): value is Extract +export declare function isFinite(value: number): boolean +export declare function isInfinite(value: number): boolean \ No newline at end of file diff --git a/src/Guards/index.js b/src/Guards/index.js index c89c35e9..f328a0af 100644 --- a/src/Guards/index.js +++ b/src/Guards/index.js @@ -1 +1,4 @@ export * from './Guards.bs.js' + +export const isFinite = value => Number.isFinite(value) +export const isInfinite = value => !Number.isFinite(value) \ No newline at end of file diff --git a/src/Guards/index.ts b/src/Guards/index.ts index b9d69ae7..f6eddcfd 100644 --- a/src/Guards/index.ts +++ b/src/Guards/index.ts @@ -23,6 +23,9 @@ export declare type Guard = Extract extends never ? V : Extract +export declare function isFinite(value: number): boolean +export declare function isInfinite(value: number): boolean + export declare function isString( value: A | string, ): value is Guard From 5ab18f92e214e6813298171d20d2525acee81e94 Mon Sep 17 00:00:00 2001 From: Minsang Kim Date: Sun, 10 Mar 2024 18:34:49 +0900 Subject: [PATCH 2/3] chore: added trailing newline --- __tests__/Guards/isFinite.test.ts | 2 +- __tests__/Guards/isInfinite.test.ts | 3 +-- src/Guards/Guards.ts | 2 +- src/Guards/index.js | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/__tests__/Guards/isFinite.test.ts b/__tests__/Guards/isFinite.test.ts index 50b842ce..cabab2ba 100644 --- a/__tests__/Guards/isFinite.test.ts +++ b/__tests__/Guards/isFinite.test.ts @@ -6,4 +6,4 @@ describe('isFinite', () => { expect(G.isFinite(0)).toEqual(true) expect(G.isFinite(Infinity)).toEqual(false) }) -}) \ No newline at end of file +}) diff --git a/__tests__/Guards/isInfinite.test.ts b/__tests__/Guards/isInfinite.test.ts index 6466eeed..090c1e75 100644 --- a/__tests__/Guards/isInfinite.test.ts +++ b/__tests__/Guards/isInfinite.test.ts @@ -7,5 +7,4 @@ describe('isInFinite', () => { expect(G.isInfinite(Infinity)).toEqual(true) expect(G.isInfinite(1/0)).toEqual(true) }) - -}) \ No newline at end of file +}) diff --git a/src/Guards/Guards.ts b/src/Guards/Guards.ts index f48f2b38..904c11bc 100644 --- a/src/Guards/Guards.ts +++ b/src/Guards/Guards.ts @@ -62,4 +62,4 @@ export declare function isNot( ): boolean export declare function isDate(value: A): value is Extract export declare function isFinite(value: number): boolean -export declare function isInfinite(value: number): boolean \ No newline at end of file +export declare function isInfinite(value: number): boolean diff --git a/src/Guards/index.js b/src/Guards/index.js index f328a0af..c7a2adea 100644 --- a/src/Guards/index.js +++ b/src/Guards/index.js @@ -1,4 +1,4 @@ export * from './Guards.bs.js' export const isFinite = value => Number.isFinite(value) -export const isInfinite = value => !Number.isFinite(value) \ No newline at end of file +export const isInfinite = value => !Number.isFinite(value) From d2b9143cbd7eb409bcedda864999cc286c35ee9f Mon Sep 17 00:00:00 2001 From: JUSTIVE Date: Mon, 11 Mar 2024 18:47:01 +0900 Subject: [PATCH 3/3] fix: updated type signature match to isNumber --- src/Guards/Guards.ts | 4 ++-- src/Guards/index.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Guards/Guards.ts b/src/Guards/Guards.ts index 904c11bc..608aa40a 100644 --- a/src/Guards/Guards.ts +++ b/src/Guards/Guards.ts @@ -61,5 +61,5 @@ export declare function isNot( predicateFn: (value: A) => any, ): boolean export declare function isDate(value: A): value is Extract -export declare function isFinite(value: number): boolean -export declare function isInfinite(value: number): boolean +export declare function isFinite(value: A | number): value is Guard +export declare function isInfinite(value: A | number): value is Guard diff --git a/src/Guards/index.ts b/src/Guards/index.ts index f6eddcfd..f0ee4ca0 100644 --- a/src/Guards/index.ts +++ b/src/Guards/index.ts @@ -23,8 +23,12 @@ export declare type Guard = Extract extends never ? V : Extract -export declare function isFinite(value: number): boolean -export declare function isInfinite(value: number): boolean +export declare function isFinite( + value: A | number, +): value is Guard +export declare function isInfinite( + value: A | number, +): value is Guard export declare function isString( value: A | string,