rg-express
Version:
Welcome to the **rg-express** user guide! This document will help you get started with **rg-express**, a powerful route generator for Express that simplifies route management with file-based approach. Whether you're building APIs in TypeScript or JavaScri
64 lines (59 loc) • 1.68 kB
TypeScript
import { Router, Express } from 'express';
type CodeSnippetFn = (config: {
spreadParams: string[];
slugParams: string[];
allParams: string[];
}) => string;
type RouteGenIfEmpty = Boolean | ({
codeSnippet?: string;
codeSnippetFn?: CodeSnippetFn;
}) | undefined;
/**
* Configuration options for setting up application routes.
*
* @property baseDir - The base directory where route files are located.
* @property routeGenIfEmpty - Automatically sets up startup code if the file is empty.
* @property app - An optional Express application instance to use for routing.
*/
interface RouteConfigWithApp {
baseDir: string;
routeGenIfEmpty?: RouteGenIfEmpty;
/**
* @deprecated Use `routeGenIfEmpty` instead.
*/
autoSetup?: boolean;
/**
* @deprecated skip to pass app.
*/
app: Express;
}
type RouteConfigWithoutApp = string | {
baseDir: string;
routeGenIfEmpty?: RouteGenIfEmpty;
/**
* @deprecated Use `routeGenIfEmpty` instead.
*/
autoSetup?: boolean;
app?: undefined;
};
interface RouteConfig {
baseDir: string;
routeGenIfEmpty?: RouteGenIfEmpty;
/**
* @deprecated Use `routeGenIfEmpty` instead.
*/
autoSetup?: boolean;
/**
* @deprecated skip to pass app.
*/
app?: Express;
}
type RoutesProps = string | RouteConfig;
declare function routes(config: RouteConfigWithoutApp): Router;
declare function routes(config: string): Router;
declare function routes(config: RouteConfigWithApp): void;
declare const rg: typeof routes & {
routes: typeof routes;
};
export { rg as default, routes };
export type { RouteGenIfEmpty, RoutesProps };