mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 09:36:01 +00:00
17 lines
576 B
TypeScript
17 lines
576 B
TypeScript
import _escapeRegExp from 'lodash/escapeRegExp';
|
|
import _isString from 'lodash/isString';
|
|
|
|
export function compilePermissions(permissions: string[] | string) {
|
|
if (!permissions) return null;
|
|
if (_isString(permissions)) permissions = permissions.split(',');
|
|
return permissions.map(x => new RegExp('^' + _escapeRegExp(x).replace(/\\\*/g, '.*') + '$'));
|
|
}
|
|
|
|
export function testPermission(tested: string, permissions: RegExp[]) {
|
|
if (!permissions) return true;
|
|
for (const permission of permissions) {
|
|
if (tested.match(permission)) return true;
|
|
}
|
|
return false;
|
|
}
|