import * as t from 'io-ts' ; import { either } from 'fp-ts/lib/Either' ; import { getRangeTypeMessage } from './get_range_type_message' ; export function getIntegerRt ( { min = - Infinity , max = Infinity , } = { } ) { const message = getRangeTypeMessage ( min , max ) ; return new t . Type < string , string , unknown > ( 'integerRt' , t . string . is , ( input , context ) => { return either . chain ( t . string . validate ( input , context ) , ( inputAsString ) => { const inputAsInt = parseInt ( inputAsString , 10 ) ; const isValid = inputAsInt >= min && inputAsInt <= max ; return isValid ? t . success ( inputAsString ) : t . failure ( input , context , message ) ; } ) ; } , t . identity ) ; }