/** * Filters for handling paths and routing * * They should generally come first whenever possible to prevent weird errors * * @packageDocumentation */ import { Filter as FilterType, IsInstanceOf, Tuple } from "../types"; import { Filter } from "../filter"; /** * Matches an exact path segment * @param literal - Segment to match */ export declare function segment(literal: string): Filter<[]>; /** * Matches an arbitrary string and extracts it */ export declare const string: Filter<[string]>; /** * Matches an arbitrary number and extracts it */ export declare const number: Filter<[number]>; /** * Matches an arbitrary boolean and extracts it */ export declare const boolean: Filter<[boolean]>; /** * Matches the end of a path */ export declare const end: Filter<[]>; /** * Possible types of arguments to [[`partial`]] and [[`path`]] */ declare type PathSegment = string | typeof String | typeof Number | typeof Boolean; /** * Maps [[`PathSegment`]]s to their counterpart extracted types */ declare type PathMap> = FilterType<{ [I in keyof S]: true extends IsInstanceOf ? string : true extends IsInstanceOf ? number : true extends IsInstanceOf ? boolean : null; }>; /** * Chains multiple path segments into a partial path and extracts their values * * This filter should only be used if additional path segments follow it, * in other cases prefer [[`path`]]. * * Under the hood, this filter just chains [[`segment`]]s, [[`string`]]s, [[`number`]]s and [[`boolean`]]s. * * @param segments - Path segments (must have a known length) */ export declare function partial>(...segments: S): Filter>; /** * Chains multiple path segments into a full path and extracts their values * * ```ts * // Will match /2/plus/2 * // Generic type annotation not required, only present for clarity's sake * const sum: Filter<[number, number]> = path(Number, "plus", Number); * ``` * * This filter should only be used if no other path segments follow it, * in other cases prefer [[`partial`]]. * * Under the hood, this filter just chains [[`partial`]] and [[`end`]]. * * @param segments - Path segments (must have a known length) */ export declare function path>(...segments: S): Filter>; export {};