const permissionBits = { DEFAULT: 1, // 00001 CALL: 2, // 00010 USERS: 4, // 00100 ADMIN: 8, // 01000 CONTACTS: 16, // 10000 } function checkPermissions(userPermissionBits) { // Default if you have no permissions let permissions = { default: false, call: false, users: false, admin: false, contacts: false, } if(userPermissionBits & permissionBits.DEFAULT) { permissions.default = true; } if(userPermissionBits & permissionBits.CALL) { permissions.call = true; } if(userPermissionBits & permissionBits.USERS) { permissions.users = true; } if(userPermissionBits & permissionBits.ADMIN) { permissions.admin = true; } if(userPermissionBits & permissionBits.CONTACTS) { permissions.contacts = true; } return permissions; } /* let userPermissionBits = permissionBits.DEFAULT; userPermissionBits |= permissionBits.CALL; // add permission userPermissionBits ^= permissionBits.ADMIN; // toggle permission userPermissionBits &= (~permissionBits.CALL); // remove permission */ export { permissionBits, checkPermissions };