summaryrefslogtreecommitdiffhomepage
path: root/packages/core/src/permission/wildcard.ts
blob: 78746803a8fa27a7579a02fcc66347cf07f4b192 (plain)
1
2
3
4
5
6
7
8
9
10
export const Wildcard = {
	match(pattern: string, value: string): boolean {
		// Escape regex special chars except * and ?
		const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&");
		// Convert wildcards
		const regexStr = escaped.replace(/\*/g, ".*").replace(/\?/g, ".");
		const regex = new RegExp(`^${regexStr}$`, "s");
		return regex.test(value);
	},
};