2ba352da39
* 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
21 lines
573 B
TypeScript
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
|
|
}
|
|
}
|