Rocky_Mountain_Vending/.pnpm-store/v10/files/c9/741bbf5aaff4f500112de1bc0078a705167fa96095570e9aa863450498c7c86cb9da600281fdc6d27e5778c6c253831d3345fde77f53f9777f75af55a7b835
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

44 lines
No EOL
1.8 KiB
Text

import { regexpToFunction } from 'next/dist/compiled/path-to-regexp';
import { pathToRegexp } from 'next/dist/compiled/path-to-regexp';
/**
* Generates a path matcher function for a given path and options based on
* path-to-regexp. By default the match will be case insensitive, non strict
* and delimited by `/`.
*/ export function getPathMatch(path, options) {
const keys = [];
const regexp = pathToRegexp(path, keys, {
delimiter: '/',
sensitive: typeof options?.sensitive === 'boolean' ? options.sensitive : false,
strict: options?.strict
});
const matcher = regexpToFunction(options?.regexModifier ? new RegExp(options.regexModifier(regexp.source), regexp.flags) : regexp, keys);
/**
* A matcher function that will check if a given pathname matches the path
* given in the builder function. When the path does not match it will return
* `false` but if it does it will return an object with the matched params
* merged with the params provided in the second argument.
*/ return (pathname, params)=>{
// If no pathname is provided it's not a match.
if (typeof pathname !== 'string') return false;
const match = matcher(pathname);
// If the path did not match `false` will be returned.
if (!match) return false;
/**
* If unnamed params are not allowed they must be removed from
* the matched parameters. path-to-regexp uses "string" for named and
* "number" for unnamed parameters.
*/ if (options?.removeUnnamedParams) {
for (const key of keys){
if (typeof key.name === 'number') {
delete match.params[key.name];
}
}
}
return {
...params,
...match.params
};
};
}
//# sourceMappingURL=path-match.js.map