1234567891011121314151617181920212223242526272829303132333435363738394041 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.getPathMatch = getPathMatch;
- var _extends = require("@swc/helpers/lib/_extends.js").default;
- var _pathToRegexp = require("next/dist/compiled/path-to-regexp");
- function getPathMatch(path, options) {
- const keys = [];
- const regexp = (0, _pathToRegexp).pathToRegexp(path, keys, {
- delimiter: '/',
- sensitive: false,
- strict: options == null ? void 0 : options.strict
- });
- const matcher = (0, _pathToRegexp).regexpToFunction((options == null ? void 0 : 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)=>{
- const res = pathname == null ? false : matcher(pathname);
- if (!res) {
- 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 == null ? void 0 : options.removeUnnamedParams) {
- for (const key of keys){
- if (typeof key.name === 'number') {
- delete res.params[key.name];
- }
- }
- }
- return _extends({}, params, res.params);
- };
- }
- //# sourceMappingURL=path-match.js.map
|