stremio-web/src/router/urlParamsForPath.js
2019-08-29 10:47:57 +03:00

12 lines
No EOL
403 B
JavaScript

module.exports = (routeConfig, path) => {
const matches = path.match(routeConfig.regexp);
return routeConfig.urlParamsNames.reduce((urlParams, name, index) => {
if (Array.isArray(matches) && typeof matches[index + 1] === 'string') {
urlParams[name] = matches[index + 1];
} else {
urlParams[name] = null;
}
return urlParams;
}, {});
};