Important
Utilities are used internally and not exported to projects.
findMatchingURLPart
declare function findMatchingURLPart(pathname: string, pattern: URLPattern): string;
The findMatchingURLPart is a helper that gradually check for the match of the provided pathname with the provided pattern.
In case of a non-full match, it tries to find the max possible match segment by segment.
const patternProduct = new URLPattern({ pathname: '/:language?/p/:productId(d+)' });
const matchedFullPath = findMatchingURLPart('/de/p/87033', patternProduct); // "/de/p/87033"
const patternLanguage = new URLPattern({ pathname: '/:language' });
const matchedPath = findMatchingURLPart('/de/p/87033', patternProduct); // "/de"