JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 9
  • Score
    100M100P100Q55842F
  • License MIT

library to work with roles, contains calculation of times for the session, validation of required roles

Package Exports

  • role-calc

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (role-calc) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

role-calc

NPM version Build Status dependencies Status devDependencies Status GitHub license

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

import {has} from 'role-calc';

// Roles required
let required = [
    'Developer',
    'Specialist',
    'Technician',
    'Director',
    'Manager',
    'Designer',
    'Analyst',
    'Administrator'
];

// Roles user
let candidates = [
    'Developer',
    'Administrator',
    'Designer'
];

// if it contains one
has(required, candidates);						// -> true
has(['Developer', 'Director'], candidates);		// -> true
has(required, ['Other', 'Fake']);				// -> false

// must meet everyone '*'
has(required, candidates, '*');					// -> true
has(['Developer', 'Analyst'], candidates, '*');	// -> false
has(required, ['Developer', 'Other'], '*');		// -> false
has(required, ['Developer', 'Developer'], '*');	// -> true

time

import {time} from 'role-calc';

// Roles with time
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'
    }
];

/*
time(roles, option, format)

- roles: array
- option: max, min, sum, average
- format(optional): milliseconds, seconds, minutes, hours, days, weeks, months, years
*/

time(roles, 'sum');				// -> 533805 minutes
time(roles, 'max', 'hours');	// -> 8766 hours
time(roles, 'min', 'minutes');	// -> 15 minutes
time(roles, 'average', 'days');	// -> 61.782986111111114 days

Development

Start

npm start

Serve

npm run serve

Build

npm run build

Test

npm test

License

MIT © Leonardo Rico