main repo

This commit is contained in:
Basilosaurusrex
2025-11-24 18:09:40 +01:00
parent b636ee5e70
commit f027651f9b
34146 changed files with 4436636 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
import { isDynamicRoute } from "../../../shared/lib/router/utils";
import { getRouteMatcher } from "../../../shared/lib/router/utils/route-matcher";
import { getRouteRegex } from "../../../shared/lib/router/utils/route-regex";
export class RouteMatcher {
constructor(definition){
this.definition = definition;
if (isDynamicRoute(definition.pathname)) {
this.dynamic = getRouteMatcher(getRouteRegex(definition.pathname));
}
}
/**
* Identity returns the identity part of the matcher. This is used to compare
* a unique matcher to another. This is also used when sorting dynamic routes,
* so it must contain the pathname part.
*/ get identity() {
return this.definition.pathname;
}
get isDynamic() {
return this.dynamic !== undefined;
}
match(pathname) {
const result = this.test(pathname);
if (!result) return null;
return {
definition: this.definition,
params: result.params
};
}
test(pathname) {
if (this.dynamic) {
const params = this.dynamic(pathname);
if (!params) return null;
return {
params
};
}
if (pathname === this.definition.pathname) {
return {};
}
return null;
}
}
//# sourceMappingURL=route-matcher.js.map