@gati-framework/runtime
Version:
Gati runtime execution engine for running handler-based applications
60 lines • 1.81 kB
TypeScript
/**
* @module runtime/route-parser
* @description Route pattern parsing and compilation for Gati framework
*/
import type { RoutePattern } from './types/route.js';
/**
* Parse a route path pattern and compile it into a RoutePattern
*
* @param path - Route path pattern (e.g., /users/:id/posts/:postId)
* @returns Compiled route pattern
*
* @example
* ```typescript
* const pattern = parseRoute('/users/:id');
* // pattern.regex matches paths like /users/123
* // pattern.paramNames = ['id']
* ```
*/
export declare function parseRoute(path: string): RoutePattern;
/**
* Normalize a route path
* - Ensures path starts with /
* - Removes trailing slash (unless it's the root path)
* - Removes duplicate slashes
*
* @param path - Path to normalize
* @returns Normalized path
*/
export declare function normalizePath(path: string): string;
/**
* Extract path parameters from a matched path
*
* @param path - Actual request path
* @param pattern - Compiled route pattern
* @returns Extracted parameters or null if no match
*
* @example
* ```typescript
* const pattern = parseRoute('/users/:id');
* const params = extractParams('/users/123', pattern);
* // params = { id: '123' }
* ```
*/
export declare function extractParams(path: string, pattern: RoutePattern): Record<string, string> | null;
/**
* Check if a path matches a route pattern
*
* @param path - Request path to test
* @param pattern - Route pattern to match against
* @returns true if path matches pattern
*
* @example
* ```typescript
* const pattern = parseRoute('/users/:id');
* matchPath('/users/123', pattern); // true
* matchPath('/posts/123', pattern); // false
* ```
*/
export declare function matchPath(path: string, pattern: RoutePattern): boolean;
//# sourceMappingURL=route-parser.d.ts.map