permission-scopes
v1.0.4
Published
Simple user permission manager.
Downloads
3
Maintainers
Readme
PERMISSION-SCOPES
Simple npm package to create permissions for users and convert them from an array of strings, to integers.
npm i permission-scopes
Initialization
const PermissionScopes = require('permission-scopes');
const scopes = [ // create the permissions a user in your application can have
"administrator",
"send_messages",
"delete_messages",
"upload_files"
];
const perms = new PermissionScopes(scopes); // initializes all the permissions
USAGE
Convert permission scopes to integer:
perms.toInt([ 'administrator', 'send_messages', 'upload_files' ]) // Takes array as argument | return: 11
Convert permission integer to scopes:
perms.toScopes(11) // Takes integer as argument | return: [ 'administrator', 'send_messages', 'upload_files' ]
Convert automatically:
perms.convert(3) // return: [ 'administrator', 'send_messages' ]
perms.convert([ 'administrator', 'send_messages' ]) // return: 3
Get integer for all permissions:
perms.all(); // takes no argument | return (in this case): 15
Compare permissions:
perms.compare([ 'administrator', 'send_messages' ], 3) // return: true;
Compare methods:AND - (default) Permission scopes must exactly match
OR - Only one of the compared permissions must be matching
perms.compare([ 'administrator', 'send_messages' ], [ 'administrator', 'upload_files' ], "AND") // return: false;
perms.compare([ 'administrator', 'send_messages' ], [ 'administrator', 'upload_files' ], "OR") // return: true;
If you want more features, just contact me on github :)