mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-04 12:58:11 +03:00
24 lines
451 B
TypeScript
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);
|
|
}
|