import { pathToRegexp } from 'path-to-regexp';
export function makeMatcher() {
    const cache = {};
    const makeRegexpFn = (path, exact, strict, sensitive) => {
        const keys = [];
        const regexp = pathToRegexp(path, keys, { strict, end: exact, sensitive });
        return { keys, regexp };
    };
    const getRegexp = (pattern, exact, strict, sensitive) => {
        const key = `${exact ? 'exact' : ''}${strict ? 'strict' : ''}${sensitive ? 'sensitive' : ''}`;
        if (!cache[pattern]) {
            cache[pattern] = {};
        }
        return (cache[pattern][key] ||
            (cache[pattern][key] = makeRegexpFn(pattern, exact, strict, sensitive)));
    };
    return (location, { path, strict, exact, sensitive }) => {
        const { regexp, keys } = getRegexp(path || '', exact || true, strict || true, sensitive || false);
        const out = regexp.exec(location);
        if (!out)
            return [false, null];
        const params = keys.reduce((params, key, i) => {
            params[key.name] = out[i + 1];
            return params;
        }, {});
        return [true, params];
    };
}
//# sourceMappingURL=matcher.js.map