/** * @typedef {Record} PathParams * Represents a mapping of parameter names to their extracted values. */ export type PathParams = Record; export type SegExErrorConfig = { /** * - Custom error message used when the pathPattern is not a string. */ pathPatternErrorMsg: string; }; export type SegExData = { /** * - The extracted parameters as a key-value mapping. */ params: PathParams; /** * - Indicates whether the path successfully matched the pattern. */ match: boolean; }; export type SegExExec = (path: string) => SegExData; export type SegExIsUsed = () => boolean; export type SegExResult = { /** * - The compiled regular expression for the path pattern. */ regex: RegExp; /** * - The list of parameter names extracted from the pattern. */ paramNames: string[]; /** * - Function to extract parameters from a real path. */ exec: SegExExec; }; export type SegExReplacer = (paramNames: string[], substring: string, ...args: any) => string; export type SegExFunction = (pathPattern: string) => SegExResult; /** * @typedef {Object} SegExErrorConfig * @property {string} pathPatternErrorMsg - Custom error message used when the pathPattern is not a string. */ /** * Represents the result of a path execution, containing extracted parameters and the match status. * @typedef {Object} SegExData * @property {PathParams} params - The extracted parameters as a key-value mapping. * @property {boolean} match - Indicates whether the path successfully matched the pattern. */ /** * @callback SegExExec * @param {string} path - The URL path to be processed. * @returns {SegExData} An object containing the parameters extracted from the path. */ /** * @callback SegExIsUsed * @returns {boolean} Returns true if the template has been used to perform a match. */ /** * @typedef {Object} SegExResult * @property {RegExp} regex - The compiled regular expression for the path pattern. * @property {string[]} paramNames - The list of parameter names extracted from the pattern. * @property {SegExExec} exec - Function to extract parameters from a real path. */ /** * @callback SegExReplacer * @param {string[]} paramNames - The accumulated list of parameter names. * @param {string} substring - The original substring found by the search. * @param {...any} args - Additional arguments captured by the RegExp (capture groups). * @returns {string} The replacement value for the RegExp template. */ /** * A function that accepts a path pattern string and returns a SegExResult object. * @typedef {(pathPattern: string) => SegExResult} SegExFunction */ /** * Factory to create a path segment extractor based on a specific pattern. * * @param {string|RegExp} searchValue - The search pattern (string or RegExp) used to identify dynamic segments. * @param {SegExReplacer} replaceValue - The function defining how to transform a segment into a capture group. * @param {SegExErrorConfig} errorConfig - Optional configuration to customize error messages. * @returns {SegExFunction} A function that accepts a path pattern string and returns a SegExResult. * @throws {TypeError} If `searchValue` is not a string or RegExp, or if `replaceValue` is not a function. */ export declare const makeSegmentExtractor: (searchValue: string | RegExp, replaceValue: SegExReplacer, errorConfig: SegExErrorConfig) => SegExFunction; /** * Standard implementation for extracting parameters in the `:paramName` format (e.g., "/user/:id"). * @type {SegExFunction} */ export declare const segmentExtractorV1: SegExFunction; //# sourceMappingURL=SegmentExtractor.d.mts.map