@fedify/fedify
Version:
An ActivityPub server framework
78 lines • 2.19 kB
TypeScript
/**
* Options for the {@link Router}.
* @since 0.12.0
*/
export interface RouterOptions {
/**
* Whether to ignore trailing slashes when matching paths.
*/
trailingSlashInsensitive?: boolean;
}
/**
* The result of {@link Router.route} method.
* @since 1.3.0
*/
export interface RouterRouteResult {
/**
* The matched route name.
*/
name: string;
/**
* The URL template of the matched route.
*/
template: string;
/**
* The values extracted from the URL.
*/
values: Record<string, string>;
}
/**
* URL router and constructor based on URI Template
* ([RFC 6570](https://tools.ietf.org/html/rfc6570)).
*/
export declare class Router {
#private;
/**
* Create a new {@link Router}.
* @param options Options for the router.
*/
constructor(options?: RouterOptions);
/**
* Checks if a path name exists in the router.
* @param name The name of the path.
* @returns `true` if the path name exists, otherwise `false`.
*/
has(name: string): boolean;
/**
* Adds a new path rule to the router.
* @param template The path pattern.
* @param name The name of the path.
* @returns The names of the variables in the path pattern.
*/
add(template: string, name: string): Set<string>;
/**
* Resolves a path name and values from a URL, if any match.
* @param url The URL to resolve.
* @returns The name of the path and its values, if any match. Otherwise,
* `null`.
*/
route(url: string): RouterRouteResult | null;
/**
* Constructs a URL/path from a path name and values.
* @param name The name of the path.
* @param values The values to expand the path with.
* @returns The URL/path, if the name exists. Otherwise, `null`.
*/
build(name: string, values: Record<string, string>): string | null;
}
/**
* An error thrown by the {@link Router}.
*/
export declare class RouterError extends Error {
/**
* Create a new {@link RouterError}.
* @param message The error message.
*/
constructor(message: string);
}
//# sourceMappingURL=router.d.ts.map