Files
zkldi_Tachi/client/src/util/routing.ts
T
2022-10-16 18:03:11 +01:00

24 lines
451 B
TypeScript

import { EscapeStringRegexp } from "./misc";
export function DoesMatchRoute(str: string, route: string, ends = true) {
const comps = EscapeStringRegexp(route).split("/");
let regexStr = "";
for (const comp of comps) {
if (comp.startsWith(":")) {
regexStr += "[^/]*/";
} else {
regexStr += `${comp}/`;
}
}
regexStr += "?";
if (ends) {
regexStr += "$";
}
const regex = new RegExp(regexStr, "u");
return !!str.match(regex);
}