all files / modules/ getRouteParams.js

100% Statements 13/13
100% Branches 6/6
100% Functions 1/1
100% Lines 9/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24            103×   103× 29×   74×   74× 14× 74×              
import { getParamNames } from './PatternUtils'
 
/**
 * Extracts an object of params the given route cares about from
 * the given params object.
 */
function getRouteParams(route, params) {
  const routeParams = {}
 
  if (!route.path)
    return routeParams
 
  const paramNames = getParamNames(route.path)
 
  for (const p in params)
    if (params.hasOwnProperty(p) && paramNames.indexOf(p) !== -1)
      routeParams[p] = params[p]
 
  return routeParams
}
 
export default getRouteParams