{"id":17726676,"url":"https://github.com/sergeysova/rolemodel","last_synced_at":"2025-07-29T15:35:10.819Z","repository":{"id":57145174,"uuid":"94887002","full_name":"sergeysova/rolemodel","owner":"sergeysova","description":null,"archived":false,"fork":false,"pushed_at":"2017-06-20T15:44:03.000Z","size":40,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-20T09:04:14.472Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://npmjs.com/rolemodel","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/sergeysova.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-06-20T12:06:07.000Z","updated_at":"2020-05-07T21:46:14.000Z","dependencies_parsed_at":"2022-09-05T08:51:06.257Z","dependency_job_id":null,"html_url":"https://github.com/sergeysova/rolemodel","commit_stats":null,"previous_names":["lestad/rolemodel"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/sergeysova/rolemodel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergeysova%2Frolemodel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergeysova%2Frolemodel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergeysova%2Frolemodel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergeysova%2Frolemodel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sergeysova","download_url":"https://codeload.github.com/sergeysova/rolemodel/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergeysova%2Frolemodel/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267709605,"owners_count":24131922,"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","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-25T17:06:31.647Z","updated_at":"2025-07-29T15:35:10.753Z","avatar_url":"https://github.com/sergeysova.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rolemodel [![Build Status](https://travis-ci.org/LestaD/rolemodel.svg?branch=master)](https://travis-ci.org/LestaD/rolemodel) [![Coverage Status](https://coveralls.io/repos/github/LestaD/rolemodel/badge.svg?branch=master)](https://coveralls.io/github/LestaD/rolemodel?branch=master)\n\n\u003e Easily juggle roles in your project\n\n\n## Install\n\n```\n$ npm install rolemodel\n```\n\n\n## Usage\n\n```js\nconst rolemodel = require('rolemodel');\n\nrolemodel('unicorns');\n//=\u003e 'unicorns \u0026 rainbows'\n```\n\n\n## API\n\n### function role(name: string) =\u003e (impl: Role[], rules: object) =\u003e Role\n\nReturn: `Role`\n\nCreate role model.\n\n#### name\n\nType: `string`\n\nSimple name of the role.\n\nExample:\n\n```js\nconst Example = role`Example`([], {})\n\nconst FooBar = role`FooBar`([], {})\n\nconst num = 1\nconst Demo1 = role`Demo${num}`([], {})\n```\n\n#### impl\n\nType: `Role[]` Array of the Roles\n\nParent roles which rules inherited from.\nRules concats from all parents.\n\nExample:\n\n```js\nconst First = role`First`([], { foo: true })\n\nconst Second = role`Second`([First], { bar: true })\n// Second has all rules from First { foo: true, bar: true }\nconst Third = role`Third`([], { baz: true })\n\nconst Total = role`Total`([Second, Third], { daf: true })\n// Total has all rules from First, Second, Third { foo: true, bar: true, baz: true, daf: true }\n```\n\n#### rules\n\nType: `object`\n\nAny object of rules with `boolean` as values.\nRules in current role overwrites rules in parent roles.\n\nExample:\n\n```js\nconst Basic = role`Basic`([], {\n  post: {\n    create: false,\n    update: false,\n    delete: false,\n    moderationAccept: false,\n    moderationDecline: false,\n  },\n})\n\nconst User = role`User`([Basic], {\n  post: {\n    create: true,\n    update: true,\n  },\n})\n\nconst Moderator = role`Moderator`([Basic], {\n  post: {\n    moderationAccept: true,\n    moderationDecline: true,\n  },\n})\n\nconst Admin = role`Admin`([User], {\n  post: {\n    delete: true,\n  },\n})\n```\n\n### Role\n\n#### .is(name)\n\nReturn: `boolean`\n\nMethod check name of the role.\n\n##### name\n\nType: `string`\n\nExpected name of the role\n\nExample:\n\n```js\nconst Role = role`Role`([], {})\n\nRole.is('Role') // true\nRole.is('Foo') // false\n```\n\n#### .can(name)\n\nReturn: `boolean`\n\nCheck if role has `true` right.\n\n##### name\n\nType: `string`\n\nName of the target rule.\nIf rule not found returns `false`.\n\n\nExample:\n\n```js\nconst Example = role`Example`([], { foo: true, bar: { baz: true } })\n\nExample.can('foo') // true\nExample.can('bar.baz') // true\nExample.can('DemoDemoDemo') // false\n\n\nconst Child = role`Child`([Example], { demo: true, bar: { foo: true } })\n\nChild.can('foo') // true\nChild.can('bar.baz') // true\nChild.can('bar.foo') // true\nChild.can('demo') // true\nChild.can('FFFFFFF') // false\n```\n\n#### .has(name)\n\nReturn: `boolean`\n\nCheck if role has right with any value.\nIf rule not found returns `false`.\n\n##### name\n\nType: `string`\n\nName of the target rule.\n\nExample:\n\n```js\nconst Example = role`Example`([], { bar: { baz: true, demo: false } })\n\nExample.has('foo') // false\nExample.has('bar.baz') // true\nExample.has('bar.demo') // true\nExample.has('DemoDemoDemo') // false\n\n\nconst Child = role`Child`([Example], { bar: { foo: true } })\n\nChild.has('foo') // false\nChild.has('bar.baz') // true\nChild.has('bar.foo') // true\nChild.has('demo') // false\nChild.has('FFFFFFF') // false\n```\n\n\n## License\n\nMIT © [Sergey Sova](https://LestaD.top)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergeysova%2Frolemodel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsergeysova%2Frolemodel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergeysova%2Frolemodel/lists"}