@tscircuit/routematch
Version:
TypeScript route matcher with Next.js-style dynamic routes
24 lines (21 loc) • 925 B
TypeScript
interface RouteGroup {
readonly pos: number;
readonly repeat: boolean;
readonly optional: boolean;
}
interface RouteRegex {
readonly groups: Record<string, RouteGroup>;
readonly re: RegExp;
readonly namedRegex?: string;
readonly routeKeys?: Record<string, string>;
}
type RouteParams = Record<string, string | string[]>;
interface RouteMatch {
readonly matchedRoute: string;
readonly routeParams: RouteParams;
}
type RouteMatcher = (path: string) => RouteMatch | null;
declare function createRouteMatcher(routes: readonly string[]): RouteMatcher;
declare function isValidRoute(route: string): boolean;
declare function getRouteParameters(route: string): string[];
export { type RouteGroup, type RouteMatch, type RouteMatcher, type RouteParams, type RouteRegex, createRouteMatcher, createRouteMatcher as default, createRouteMatcher as getRouteMatcher, getRouteParameters, isValidRoute };