import { parse , tokensToFunction } from 'path-to-regexp' ; export function constrain ( path , constraints ) { const tokens = parse ( path ) ; for ( let token of tokens ) { if ( typeof token === 'object' && ! constraints [ token . name ] ) { constraints [ token . name ] = '' ; } } const pathFunction = tokensToFunction ( tokens ) ; const constrainedPath = pathFunction ( constraints , { encode : ( value , token ) => ':' + token . name + value } ) ; return constrainedPath ; }