Files
zkldi_Tachi/client/src/util/routing.ts
T
2021-09-13 10:39:29 +01:00

20 lines
403 B
TypeScript

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