mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-31 06:12:26 +00:00
improve wildcard matching for permissions
This commit is contained in:
13
packages/opencode/src/util/wildcard.ts
Normal file
13
packages/opencode/src/util/wildcard.ts
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user