rsnext/packages/next/next-server/lib/router/utils/route-matcher.ts
Tim Neutkens 2ba352da39 Move next-server back into next package (#8613)
* Initial move

* Make emitting work

* Update paths

* Remove leftover files

* Add correct externals configuration

* Import correct path

* Update path to work with ts-server test

* Update lib directory

* Compile next-server/lib
2019-09-04 10:00:54 -04:00

21 lines
573 B
TypeScript

import { getRouteRegex } from './route-regex'
export function getRouteMatcher(routeRegex: ReturnType<typeof getRouteRegex>) {
const { re, groups } = routeRegex
return (pathname: string | undefined) => {
const routeMatch = re.exec(pathname!)
if (!routeMatch) {
return false
}
const params: { [paramName: string]: string } = {}
Object.keys(groups).forEach((slugName: string) => {
const m = routeMatch[groups[slugName]]
if (m !== undefined) {
params[slugName] = decodeURIComponent(m)
}
})
return params
}
}