import { Options } from './types' ; const allowedOperators = [ '<' , '>' , '=' , '>=' , '<=' ] as const ; type Operator = typeof allowedOperators [ number ] ; function assertOperator ( operator ) { if ( ! allowedOperators . includes ( operator as Operator ) ) { throw new TypeError ( `Invalid breakpoint operator: ${ operator }` ) ; } } example export function breakpoints ( breakpointsMap ) { const bp = Object . keys ( breakpointsMap ) . map ( ( key ) => { const [ operator , breakpointString ] = key . split ( ' ' ) ; assertOperator ( operator ) ; const breakpoint = Number . parseInt ( breakpointString , 10 ) ; if ( Number . isNaN ( breakpoint ) ) { throw new TypeError ( `Invalid breakpoint value: ${ breakpointString }` ) ; } const value = breakpointsMap [ key ] ; return { operator , breakpoint , value , } ; } ) . sort ( ( a , b ) => b . breakpoint - a . breakpoint ) ; return ( stdoutColumns ) => bp . find ( ( { operator , breakpoint } ) => ( ( operator === '=' && stdoutColumns === breakpoint ) || ( operator === '>' && stdoutColumns > breakpoint ) || ( operator === '<' && stdoutColumns < breakpoint ) || ( operator === '>=' && stdoutColumns >= breakpoint ) || ( operator === '<=' && stdoutColumns <= breakpoint ) ) ) ?. value ; }