{"id":15828074,"url":"https://github.com/bytesleo/role-calc","last_synced_at":"2025-03-15T04:31:19.159Z","repository":{"id":65480680,"uuid":"102322991","full_name":"bytesleo/role-calc","owner":"bytesleo","description":"library to work with roles, contains calculation of times for the session, validation of required roles","archived":false,"fork":false,"pushed_at":"2018-02-24T18:39:46.000Z","size":46,"stargazers_count":4,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-24T10:10:06.172Z","etag":null,"topics":["has-role","role","role-calc","time-session"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bytesleo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-04T05:43:42.000Z","updated_at":"2019-10-22T01:55:41.000Z","dependencies_parsed_at":"2023-01-25T09:25:12.040Z","dependency_job_id":null,"html_url":"https://github.com/bytesleo/role-calc","commit_stats":null,"previous_names":["bytesleo/role-calc"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytesleo%2Frole-calc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytesleo%2Frole-calc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytesleo%2Frole-calc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytesleo%2Frole-calc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bytesleo","download_url":"https://codeload.github.com/bytesleo/role-calc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243685506,"owners_count":20330980,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["has-role","role","role-calc","time-session"],"created_at":"2024-10-05T10:21:35.140Z","updated_at":"2025-03-15T04:31:18.830Z","avatar_url":"https://github.com/bytesleo.png","language":"JavaScript","readme":"# role-calc\n\n[![NPM version](https://badge.fury.io/js/role-calc.svg)](https://npmjs.org/package/role-calc) [![Build Status](https://travis-ci.org/kevoj/role-calc.svg?branch=master)](https://travis-ci.org/kevoj/role-calc) [![dependencies Status](https://david-dm.org/kevoj/role-calc/status.svg)](https://david-dm.org/kevoj/role-calc) [![devDependencies Status](https://david-dm.org/kevoj/role-calc/dev-status.svg)](https://david-dm.org/kevoj/role-calc?type=dev)\n[![GitHub license](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://raw.githubusercontent.com/kevoj/role-calc/master/LICENSE)\n\n\u003e library to work with roles, contains calculation of times for the session, validation of required roles\n\nThis library is ideal for working with [redis-jwt](https://github.com/kevoj/redis-jwt)\n\n## Installation\n\nNpm\n\n```bash\nnpm install role-calc --save\n```\n\nYarn\n```bash\nyarn add role-calc\n```\n\n## Usage\n\n### has\n\nEvaluate if any of the required roles are met or all\n\n```javascript\n\nimport {has} from 'role-calc';\n\n// Roles required\nlet required = [\n    'Developer',\n    'Specialist',\n    'Technician',\n    'Director',\n    'Manager',\n    'Designer',\n    'Analyst',\n    'Administrator'\n];\n\n// Roles user\nlet candidates = [\n    'Developer',\n    'Administrator',\n    'Designer'\n];\n\n// if it contains one\nhas(required, candidates);         // -\u003e true\nhas(['Developer'], candidates);    // -\u003e true\nhas(required, ['Other', 'Fake']);  // -\u003e false\n\n// must meet everyone '*'\nhas(required, candidates, '*');                   // -\u003e false\nhas(['Developer', 'Designer'], candidates, '*');  // -\u003e true\nhas(['Director'], ['Director', 'Other'], '*');    // -\u003e true\n\n```\n\n### time\n\nGets the times of a list from an array of roles\n\n```javascript\n\nimport {time} from 'role-calc';\n\n// Roles with time\nlet roles = [\n    {\n        role: 'Developer',\n        ttl: '15 minutes'\n    },\n    {\n        role: 'Specialist',\n        ttl: '2 hours'\n    },\n    {\n        role: 'Manager',\n        ttl: '3 days'\n    },\n    {\n        role: 'Administrator',\n        ttl: '1 years'\n    },\n    {\n        role: 'Director',\n        ttl: '90 minutes'\n    },\n    {\n        role: 'Designer',\n        ttl: '55 hours'\n    },\n    {\n        role: 'other'\n    }\n];\n\n// Roles user\nlet candidates = [\n    'Developer',\n    'Administrator',\n    'Designer'\n];\n\ntime(roles, candidates);\n/*\n-\u003e\n[\n  { role: 'Developer', ttl: '15 minutes' },\n  { role: 'Administrator', ttl: '1 years' },\n  { role: 'Designer', ttl: '55 hours' }\n]\n*/\n\n```\n\n### calc\n\nCalculate time of multiple roles assigned to a user\n\n```javascript\n\nimport {calc} from 'role-calc';\n\n// Roles with time\nlet roles = [\n    {\n        role: 'Developer',\n        ttl: '15 minutes'\n    },\n    {\n        role: 'Specialist',\n        ttl: '2 hours'\n    },\n    {\n        role: 'Manager',\n        ttl: '3 days'\n    },\n    {\n        role: 'Administrator',\n        ttl: '1 years'\n    },\n    {\n        role: 'Director',\n        ttl: '90 minutes'\n    },\n    {\n        role: 'Designer',\n        ttl: '55 hours'\n    },\n    {\n        role: 'other'\n    }\n];\n\n/*\ntime(roles, option, format)\n\n- roles: array\n- option: max, min, sum, average\n- format(optional): milliseconds, seconds, minutes, hours, days, weeks, months, years\n*/\n\ncalc(roles, 'sum'); // -\u003e 533805 minutes\ncalc(roles, 'max', 'hours'); // -\u003e 8766 hours\ncalc(roles, 'min', 'minutes'); // -\u003e 15 minutes\ncalc(roles, 'average', 'days'); // -\u003e 61.782986111111114 days\n\n```\n\n## Development\n\n### Start\n\n`npm start`\n\n### Compile\n\n`npm run compile`\n\n### Test\n\n`npm test`\n\n## License\n\nMIT © [Leonardo Rico](https://github.com/kevoj/role-calc/blob/master/LICENSE)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytesleo%2Frole-calc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbytesleo%2Frole-calc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytesleo%2Frole-calc/lists"}