import { pathToRegexp , Key } from 'path-to-regexp' ; import { ParametricRegExp } from './http.router.interface' ; export const factorizeRegExpWithParams = ( path ) : ParametricRegExp => { const keys = [ ] ; const preparedPath = path . replace ( /\/\*/g , '/(.*)' ) . replace ( /\/\/+/g , '/' ) . replace ( /\/$/ , '' ) ; const regExp = pathToRegexp ( preparedPath , keys , { strict : false } ) ; const regExpParameters = keys . filter ( key => key . name !== 0 ) . map ( key => String ( key . name ) ) ; return { regExp , parameters : regExpParameters . length > 0 ? regExpParameters : undefined , path : preparedPath , } ; } ;