burger-api
Version:
<div align="center"> <a href="https://burger-api.com"> <img src="https://github.com/user-attachments/assets/0d9b376e-1d89-479a-aa7f-e7ee3c6b2342" alt="BurgerAPI"/> </a> </div>
46 lines (45 loc) • 1.97 kB
TypeScript
import type { PageDefinition, RouteDefinition, TrieNode } from '../types/index';
/**
* Constants for route handling.
*/
export declare const ROUTE_CONSTANTS: {
SUPPORTED_PAGE_EXTENSIONS: string[];
PAGE_INDEX_FILES: string[];
DYNAMIC_SEGMENT_PREFIX: string;
DYNAMIC_FOLDER_START: string;
DYNAMIC_FOLDER_END: string;
GROUPING_FOLDER_START: string;
GROUPING_FOLDER_END: string;
WILDCARD_SEGMENT_PREFIX: string;
WILDCARD_SIMPLE: string;
WILDCARD_START: string;
};
/**
* Supported HTTP methods
*/
export declare const HTTP_METHODS: string[];
/**
* Calculates the specificity of a route path based on the number of static segments.
* Static segments increase the score, while dynamic segments (:param) do not.
* Wildcard segments (*) have the lowest specificity (highest penalty).
* @param path The route path to evaluate.
* @returns The specificity score (higher means more static segments, lower priority for wildcard).
*/
export declare const getRouteSpecificity: (path: string) => number;
/**
* Compares two routes for sorting, prioritizing those with higher specificity (more static segments).
* Route prioritization: Static > Dynamic > Wildcard.
* If specificity is equal, sorts alphabetically by path.
* @param a The first route to compare.
* @param b The second route to compare.
* @returns Negative if a comes before b, positive if b comes before a, zero if equal.
*/
export declare const compareRoutes: (a: PageDefinition | RouteDefinition, b: PageDefinition | RouteDefinition) => number;
/**
* Collects all routes from the trie and returns them as an array of RouteDefinition objects.
* @param node The current node in the trie.
* @param currentPath The current path being traversed.
* @param routes The array of collected routes.
* @returns An array of RouteDefinition objects.
*/
export declare function collectRoutes(node: TrieNode, currentPath?: string, routes?: RouteDefinition[]): RouteDefinition[];