From c677ea162f1d308f87b5a34979d10330882e2417 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Tue, 29 Jun 2021 22:11:00 +0200 Subject: [PATCH] Prep for stricter Flow version --- src/__tests__/number.test.js | 4 ++-- src/number.js | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/__tests__/number.test.js b/src/__tests__/number.test.js index 802c87c2..257dc087 100644 --- a/src/__tests__/number.test.js +++ b/src/__tests__/number.test.js @@ -7,7 +7,7 @@ import { INPUTS } from './fixtures'; describe('number', () => { const decoder = number; - const [okay, not_okay] = partition(INPUTS, Number.isFinite); + const [okay, not_okay] = partition(INPUTS, (n) => Number.isFinite(n)); it('valid', () => { expect(okay.length).not.toBe(0); @@ -48,7 +48,7 @@ describe('positiveNumber', () => { describe('integer', () => { const decoder = integer; - const [okay, not_okay] = partition(INPUTS, Number.isInteger); + const [okay, not_okay] = partition(INPUTS, (n) => Number.isInteger(n)); it('valid', () => { expect(okay.length).not.toBe(0); diff --git a/src/number.js b/src/number.js index 4bf127f9..0f7840e8 100644 --- a/src/number.js +++ b/src/number.js @@ -12,9 +12,12 @@ const anyNumber: Decoder = (blob: mixed) => { : Err(annotate(blob, 'Must be number')); }; +const isInteger = (n: number) => Number.isInteger(n); +const isFinite = (n: number) => Number.isFinite(n); + export const number: Decoder = compose( anyNumber, - predicate(Number.isFinite, 'Number must be finite') + predicate(isFinite, 'Number must be finite') ); export const positiveNumber: Decoder = compose( number, @@ -24,9 +27,9 @@ export const positiveNumber: Decoder = compose( // Integers export const integer: Decoder = compose( number, - predicate(Number.isInteger, 'Number must be an integer') + predicate(isInteger, 'Number must be an integer') ); export const positiveInteger: Decoder = compose( - number, - predicate((n) => n >= 0 && Number.isInteger(n), 'Number must be an integer') + integer, + predicate((n) => n >= 0, 'Number must be positive') );