# easyrole

> Role Based Access Control

Latest version **0.0.5** (published 2015-03-01) · mit license · 0 weekly downloads

## Install

```sh
npm install easyrole
pnpm add easyrole
yarn add easyrole
bun add easyrole
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2015-03-01 |
| First published | 2015-02-20 |
| Weekly downloads | 0 |
| License | mit |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | wwwy3y3 |
| Maintainers | wwwy3y3 |
| Keywords | role, permission, access, RBAC, hierarchical, privacy |

## Links

- npm: https://www.npmjs.com/package/easyrole
- Repository: https://github.com/wwwy3y3/easyrole
- Issues: https://github.com/wwwy3y3/easyrole/issues
- npm.io page: https://npm.io/package/easyrole

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^3.3.1

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 0.0.5 (latest) — 2015-03-01
- 0.0.4 — 2015-03-01
- 0.0.3 — 2015-03-01
- 0.0.2 — 2015-02-25
- 0.0.1 — 2015-02-21
- 0.0.0 — 2015-02-20

## README

# easyrole
Easy Role Based Access Control

# Install
``` javascript
npm install easyrole
```

# Example
``` javascript
var Rbac= require('easyrole');
var rbac= new Rbac();
rbac.setRoles(['admins', 'editors', 'developers', 'users']);

// admins
rbac.admins.allow('*');

// editors
rbac.editors.allow({
	blogs: ['create', 'read', 'update', 'delete'],
	settings: ['read']
})

// developers
rbac.developers.extend(rbac.editors)
			   .allow({
			   		settings: ['read', 'update']
			   })

// users
rbac.users.allow({
	blogs: ['read']
})

// can admin creare blog
rbac.can('admins').do('blogs.create') //return true

// can editor update settings
rbac.can('editors').do('settings.update') //return false
```

# Getting Start
## set roles first
``` javascript
var Rbac= require('easyrole');
var rbac= new Rbac();
rbac.setRoles(['admins', 'editors', 'developers', 'users']);
```

## set permissions to roles
``` javascript
// give admins all permissions
rbac.admins.allow('*');

// editors
rbac.editors.allow({
	blogs: ['create', 'read', 'update', 'delete'],
	settings: ['read']
})

// extend editors permissoins to developers
rbac.developers.extend(rbac.editors)
			   .allow({
			   		settings: ['read', 'update']
			   })
```

## use it
``` javascript
rbac.can('admins').do('blogs.create') //return true
```

# Api
## rbac.setRoles([roles..])
set roles for your rbac

## rbac[role].allow(permissions)
add permissions to role

## rbac[role].extend(role object)
inherit a role permission

## rbac.can('role').do('resource.action')
return boolean
``` javascript
rbac.can('admins').do('blogs.create') //return true
```
## rbac.getRoles('role')
return a role object
``` javascript
var admin= rbac.getRoles('admins');
admin.can('blogs.create') // return true
```

# Todo
- [x] use merge instead of replace in permission extend

---
_Source: https://npm.io/package/easyrole · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
