interface RouterContext { root: Node; static: Record | undefined>; } type ParamsIndexMap = Array<[Index: number, name: string | RegExp, optional: boolean]>; type MethodData = { data: T; paramsMap?: ParamsIndexMap; paramsRegexp: RegExp[]; }; interface Node { key: string; static?: Record>; param?: Node; wildcard?: Node; hasRegexParam?: boolean; methods?: Record[] | undefined>; } type MatchedRoute = { data: T; params?: Record; }; type ExtractWildcards = TPath extends `${string}**:${infer Rest}` ? Rest extends `${infer Param}/${infer Tail}` ? Param | ExtractWildcards : Rest : TPath extends `${string}*${infer Rest}` ? Rest extends `*` ? `_` : `_${Count["length"]}` | ExtractWildcards : TPath extends `${string}/${infer Rest}` ? ExtractWildcards : never; type ExtractNamedParams = TPath extends `${infer _Start}:${infer Rest}` ? Rest extends `${infer Param}/${infer Tail}` ? Param | ExtractNamedParams<`/${Tail}`> : Rest extends `${infer Param}*${infer Tail}` ? Param | ExtractNamedParams<`/${Tail}`> : Rest : TPath extends `/${infer Rest}` ? ExtractNamedParams : never; type InferRouteParams = { [K in ExtractNamedParams | ExtractWildcards]: string }; /** * Create a new router context. */ declare function createRouter(): RouterContext; /** * Add a route to the router context. */ declare function addRoute(ctx: RouterContext, method: string | undefined, path: string, data?: T): void; /** * Find a route by path. */ declare function findRoute(ctx: RouterContext, method: string | undefined, path: string, opts?: { params?: boolean; }): MatchedRoute | undefined; /** * Remove a route from the router context. */ declare function removeRoute(ctx: RouterContext, method: string, path: string): void; /** * Find all route patterns that match the given path. */ declare function findAllRoutes(ctx: RouterContext, method: string | undefined, path: string, opts?: { params?: boolean; }): MatchedRoute[]; declare function routeToRegExp(route?: string): RegExp; declare const NullProtoObj: { new (): any; }; export { type InferRouteParams, type MatchedRoute, NullProtoObj, type RouterContext, addRoute, createRouter, findAllRoutes, findRoute, removeRoute, routeToRegExp };