Skip to content

Commit

Permalink
Prep for stricter Flow version
Browse files Browse the repository at this point in the history
  • Loading branch information
nvie committed Jun 29, 2021
1 parent b5147d4 commit c677ea1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions src/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ const anyNumber: Decoder<number> = (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<number> = compose(
anyNumber,
predicate(Number.isFinite, 'Number must be finite')
predicate(isFinite, 'Number must be finite')
);
export const positiveNumber: Decoder<number> = compose(
number,
Expand All @@ -24,9 +27,9 @@ export const positiveNumber: Decoder<number> = compose(
// Integers
export const integer: Decoder<number> = compose(
number,
predicate(Number.isInteger, 'Number must be an integer')
predicate(isInteger, 'Number must be an integer')
);
export const positiveInteger: Decoder<number> = compose(
number,
predicate((n) => n >= 0 && Number.isInteger(n), 'Number must be an integer')
integer,
predicate((n) => n >= 0, 'Number must be positive')
);

0 comments on commit c677ea1

Please sign in to comment.