@riogz/router
Version:
A simple, lightweight, powerful, view-agnostic, modular and extensible router
40 lines (39 loc) • 1.23 kB
TypeScript
import { Options, Router } from '../types/router';
/**
* Enhances a router with configuration options management.
*
* This module provides functionality to:
* - Set default router options
* - Override specific options
* - Retrieve current configuration
* - Update options at runtime
*
* Options control various aspects of router behavior including:
* - URL parsing and generation
* - Route matching behavior
* - Query parameter handling
* - Trailing slash processing
* - Case sensitivity
* - Cleanup behavior
*
* @template Dependencies - Type of dependencies available in the router
* @param options - Partial options object to override defaults
* @returns Function that enhances a router with options management
*
* @example
* ```typescript
* const router = createRouter(routes, {
* trailingSlashMode: 'never',
* caseSensitive: true,
* defaultRoute: 'home',
* defaultParams: { lang: 'en' }
* })
*
* // Update options at runtime
* router.setOption('allowNotFound', true)
*
* // Get current options
* const currentOptions = router.getOptions()
* ```
*/
export default function withOptions<Dependencies>(options: Partial<Options>): (router: Router<Dependencies>) => Router<Dependencies>;