UNPKG

url-pattern-list

Version:

Efficiently match URLs against a collection of URL patterns

39 lines 1.37 kB
/** * The return type of `URLPatternList.match()`. * * Includes the result of `pattern.exec()` and the matching pattern's associated * metadata value. */ export interface URLPatternListMatch<T> { result: URLPatternResult; value: T; } /** * A collection of URL patterns and associated values, with methods for adding * patterns and matching URLs against those patterns. * * This is an optimized collection where patterns are stored in a prefix * tree instead of a flat list. Matching patterns are searched for on the tree * and shared prefixes of patterns are only checked for a match once. * * The implementation maintains first-match-wins semantics - patterns are tested * in the order they were added to the collection. This implementation should be * a drop-in replacement for a linear search. */ export declare class URLPatternList<T> { #private; constructor(); /** * Add a URL pattern to the collection. */ addPattern(pattern: URLPattern, value: T): void; /** * Match a URL against the URLPatterns, returning the first match found and * its associated value. * * @param url - The URL to match * @param baseUrl - Optional base URL for relative path resolution */ match(url: string | URL, baseUrl?: string): URLPatternListMatch<T> | null; } //# sourceMappingURL=index.d.ts.map