role-calc

library to work with roles, contains calculation of times for the session, validation of required roles
This library is ideal for working with redis-jwt
Installation
Npm
npm install role-calc --save
Yarn
yarn add role-calc
Usage
has
Evaluate if any of the required roles are met or all
import {has} from 'role-calc';
let required = [
'Developer',
'Specialist',
'Technician',
'Director',
'Manager',
'Designer',
'Analyst',
'Administrator'
];
let candidates = [
'Developer',
'Administrator',
'Designer'
];
has(required, candidates);
has(['Developer'], candidates);
has(required, ['Other', 'Fake']);
has(required, candidates, '*');
has(['Developer', 'Designer'], candidates, '*');
has(['Director'], ['Director', 'Other'], '*');
time
Gets the times of a list from an array of roles
import {time} from 'role-calc';
let roles = [
{
role: 'Developer',
ttl: '15 minutes'
},
{
role: 'Specialist',
ttl: '2 hours'
},
{
role: 'Manager',
ttl: '3 days'
},
{
role: 'Administrator',
ttl: '1 years'
},
{
role: 'Director',
ttl: '90 minutes'
},
{
role: 'Designer',
ttl: '55 hours'
},
{
role: 'other'
}
];
let candidates = [
'Developer',
'Administrator',
'Designer'
];
time(roles, candidates);
calc
Calculate time of multiple roles assigned to a user
import {calc} from 'role-calc';
let roles = [
{
role: 'Developer',
ttl: '15 minutes'
},
{
role: 'Specialist',
ttl: '2 hours'
},
{
role: 'Manager',
ttl: '3 days'
},
{
role: 'Administrator',
ttl: '1 years'
},
{
role: 'Director',
ttl: '90 minutes'
},
{
role: 'Designer',
ttl: '55 hours'
},
{
role: 'other'
}
];
calc(roles, 'sum');
calc(roles, 'max', 'hours');
calc(roles, 'min', 'minutes');
calc(roles, 'average', 'days');
Development
Start
npm start
Compile
npm run compile
Test
npm test
License
MIT © Leonardo Rico