import { IncomingMessage } from 'http' ; import { Path } from 'path-to-regexp' ; import { pathParser } from './pathParser' ; const match = < P , T , C > ( pathPattern , fn ) => { const matcher = pathParser ( pathPattern ) ; return ( context , { url } ) => { const params = matcher < P > ( url ) ; return params != null ? fn ( context , params ) : null ; } ; } ; const execOrNext = < A extends unknown [ ] , R1 , R2 > ( h1 , h2 ) => ( ... args ) => h1 ( ... args ) ?? h2 ( ... args ) ; export const firstOf = < C > ( ... handlers ) => handlers . length > 0 ? handlers . reduce ( execOrNext ) : ( ) => null ; export default match ;