22 lines
430 B
TypeScript
22 lines
430 B
TypeScript
export class Permission {
|
|
/**
|
|
*
|
|
*/
|
|
list: string[];
|
|
separator: string;
|
|
level: number;
|
|
|
|
constructor(list: string[], level = 3, separator = ":") {
|
|
this.list = list;
|
|
this.level = level;
|
|
this.separator = separator;
|
|
}
|
|
|
|
isValid(str: string) {
|
|
const p = new Array(this.level).fill("\\w+?").join(this.separator);
|
|
// ^\w+?:\w+?:\w+?$
|
|
const r = new RegExp(`^${p}$`);
|
|
return r.test(str);
|
|
}
|
|
}
|