// #region Imports
import { stringToRegexp } from './PathToRegexp';
// #endregion
/**
 * Returns the tail of a pathname groups object. This is the match from a
 * wildcard at the end of a pathname pattern, like `/foo/*`
 */
export const getTailGroup = (groups) => {
    let tailKey = undefined;
    for (const key of Object.keys(groups)) {
        if ((/\d+/).test(key) && (tailKey === undefined || key > tailKey)) {
            tailKey = key;
        }
    }
    return tailKey && groups[tailKey];
};
// A cache of URLPatterns created for PathRouteConfig.
// Rather than converting all given RoutConfigs to URLPatternRouteConfig, this
// Lets us make `routes` mutable so users can add new PathRouteConfigs
// Dynamically.
// eslint-disable-next-line @stylistic/object-property-newline
const PATTER_CACHE = new WeakMap();
export const getPattern = (route) => {
    let pattern = PATTER_CACHE.get(route);
    if (pattern === undefined) {
        pattern = {
            path: route.path,
            reg: stringToRegexp(route.path)
        };
        PATTER_CACHE.set(route, pattern);
    }
    return pattern;
};
//# sourceMappingURL=Utils.js.map