improve wildcard matching for permissions

This commit is contained in:
Dax Raad
2025-07-31 20:40:05 -04:00
parent e6db1cf29d
commit 12f84f198f
2 changed files with 18 additions and 2 deletions

View File

@@ -0,0 +1,13 @@
export namespace Wildcard {
export function match(str: string, pattern: string) {
const regex = new RegExp(
"^" +
pattern
.replace(/[.+^${}()|[\]\\]/g, "\\$&") // escape special regex chars
.replace(/\*/g, ".*") // * becomes .*
.replace(/\?/g, ".") + // ? becomes .
"$",
)
return regex.test(str)
}
}