Kasta
Given a JSON-based config
var config = /** * list of roles */ roles : "public" "user" "admin" /** * access levels */ accessLevels : "public" : "*" "anonymous" : "public" "user" : "user" "admin" "admin" : "admin"
var kasta = ;console;
Transform it into
userRoles: public: bitMask: 1 title: 'public' user: bitMask: 2 title: 'user' admin: bitMask: 4 title: 'admin' accessLevels: public: bitMask: 7 anonymous: bitMask: 1 user: bitMask: 6 admin: bitMask: 4
Then we can check if someone with specific roles can access a defined level
var role = userRoles"admin";var accessLevel = accessLevels"user"; var allowed = rolebitMask & accessLevelbitMask; if allowed // congratulate the user! else // throw error
License
MIT