roler

simple role manager for nodejs and browser

roler

simple and fast role manager for nodejs and browsers.

Installation

Using NPM:

--- ------- ----- ------

Getting started

  1. Install package: npm install roler

  2. Open a file in your editor and write, For example roler.js:

------ ----- ---- --------
-- --
----- ----- - -----------------

--- ----- - --- --------

------------------------------ --------
------------------------------ -------- --------------------- ---------- -----------

------ ------- ------
-- --
-------------- - ------
  1. In your app file you can use roler, For example in express app:
--- ----- - ----------------------

------------ ------------- ---- ----- -
  -- ------------------------------------------- -------- -
    -------
  - ---- -
    ----------------------
  -
---

API

Roler

Return: Roler

Create new role manager.

Example: new Roler()

Methods

new

Usage: roler.new(name)

Return: Role

Arguments:

  • name: type string, required. name for new role.

Create a new role.

get

Usage: roler.get(name)

Return: Role

Arguments:

  • name: type string, required. name of role.

Get a role.

remove

Usage: roler.remove(name)

Return: undefined

Arguments:

  • name: type string, required. name of role.

Remove a role.

Role

It will be created when you using roler.new method.

Methods

add

Usage: role.add(resource, permissions)

Return: Role

Arguments:

  • resource: type string, required. resource name for permissions.
  • permissions: type string or array, required. permissions.

With add function you can add permission for a role.

Example:

--- ----- - --- -------
------------------------------ --------

------------------------------- ---------- -------------------------- --------
isAllowed

Usage: role.isAllowed(resource, permissions)

Return: Boolean

Arguments:

  • resource: type string, required. resource name.
  • permissions: type string or array, required. permissions to check.

Check whether this role can access to the resource with specified permissions or not.

Example:

------------------------------------- ---------- -- ------ -----
------------------------------------ -------- -- ------ ----
-------------------------------------- ------- --------- -- ------ -----
whatCanDo

Usage: role.whatCando()

Return: Object

Give all resources and permissions.

removeResource

Usage: roler.removeResource(resources)

Return: Role

Arguments:

  • resources: type string or array, required. resource names to be removed.

Remove some resources from a role.

removePermission

Usage: roler.removePermission(resource, permissions)

Return: Role

Arguments:

  • resource: type string, required. resource name.
  • permissions: type string or array, required. permissions list for removing.

Remove permissions from specified resource.

CONTRIBUTING

Cool! Any ideas and pull requests is appreciated. take a look at this CONTRIBUTING.md

LICENSE

The MIT License (MIT)

Copyright (c) 2017 Ali Movahedi ali_movahedi@aol.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

HomePage

https://github.com/amovah/roler#readme

Repository

git+https://github.com/amovah/roler.git

来源:JavaScript中文网 ,转载请联系管理员! 本文地址:https://www.javascriptcn.com/post/6005607781e8991b448dea09


猜你喜欢

  • npm 包 @spartadigital/wikitude_architectview_dts 使用教程

    在前端开发中,使用第三方库和插件可以极大地提高开发效率和代码质量。其中 npm 是一个流行的包管理器,提供了许多功能强大的开源包。本文介绍了 npm 包 @spartadigital/wikitude...

    3 年前
  • npm 包 canvasso 使用教程

    前言 在前端开发中,绘制图形是我们经常需要处理的任务,通常我们需要使用画布 API 来创建和绘制图形。但是,使用纯 JavaScript 代码处理画布 API 可能会比较繁琐和复杂。

    3 年前
  • npm 包 beginpm-questions 使用教程

    简介 npm 是一个用于 Node.js 的包管理器,它允许开发者上传和分享自己的包并使用他人上传的包。在npm 上,有许多优秀的包可以帮助我们快速实现业务逻辑。beginpm-questions 就...

    3 年前
  • npm 包 revue2 使用教程

    随着前端技术的不断发展,vue框架已经成为了一种非常流行的前端框架。在使用vue框架的过程中我们常常需要对vuex进行管理,revue2 npm 包就是为了解决这个问题而开发的。

    3 年前
  • npm 包 file2html-text 使用教程

    前言 在前端开发中,我们经常需要处理文件,例如图片、音频、视频、文档等等。而有时候需要将这些文件转换成 HTML 格式来显示或者其他用途。随着技术的发展,现在我们可以使用一个叫做 file2html-...

    3 年前
  • npm 包 joi-manager 使用教程

    简介 joi-manager 是一个基于 joi 的参数校验工具,能够方便地实现参数校验,并提供了一些预设的校验规则以及自定义校验规则的方式。本文将详细介绍 joi-manager 的使用方法以及相关...

    3 年前
  • npm 包 homebridge-imp-garagedoor 使用教程

    在现代家庭,我们越来越依赖于智能家居技术来帮助我们管理各种家庭设备。尤其是在控制家门(车库门)时,智能家居技术提供了多种有效而方便的解决方案。在此,我们将介绍如何使用 npm 包 homebridge...

    3 年前
  • npm包wit-router使用教程

    在前端开发过程中,路由管理是不可或缺的一部分。为了方便开发者使用,社区中有很多优秀的路由管理工具。今天,我们要介绍的是一款名为wit-router的npm包,它能够为我们提供轻量、易用且灵活的路由管理...

    3 年前
  • npm 包 ygg-aws-s3 使用教程

    介绍 ygg-aws-s3 是一款 Node.js 的 AWS S3 上传、下载、删除的 npm 包。使用该包可以方便快捷地在前端应用中与 AWS S3 存储进行交互。

    3 年前
  • npm 包 exthost 使用教程

    什么是 exthost exthost 是一个 NPM 包,用于在浏览器中运行 JavaScript 钩子函数,可以帮助开发者在不污染原有代码的基础上扩展网站的功能。

    3 年前
  • npm 包 mohit 使用教程

    简介 mohit 是一款在 Node.js 环境下运行的命令行工具,它可以提供帮助开发者快速地将大量的数据集转换成为标准的 JSON 格式文件。这个工具可以帮助开发者轻松地处理大量的数据,并自动生成合...

    3 年前
  • npm 包 wasb-stream 使用教程

    前言 在前端开发中,我们经常需要下载文件并对其进行处理,然后将其上传到服务器。这个过程中,我们需要借助一些工具来实现这些功能。一个常用的工具是 wasb-stream,它是一个基于 Node.js 的...

    3 年前
  • npm 包 avocado-tools 使用教程

    前言 npm 是 Node.js 的包管理器,可以帮助我们快速安装、管理和发布 Node.js 应用程序或库。其中,avocado-tools 是一款常用的前端开发工具库,提供了许多实用的工具函数,如...

    3 年前
  • npm 包 javascript-utilities 使用教程

    简介 javascript-utilities 是一个常用 JavaScript 工具包,它包含了许多通用的函数和对象,可用于简化 JavaScript 开发过程中的常见任务。

    3 年前
  • npm 包 qtreact-slick 使用教程

    在前端开发中,我们经常需要使用轮播图组件来展示多张图片或者内容。qtreact-slick 是一个基于 React 的实现了多种轮播效果的组件库。本文将介绍如何使用 qtreact-slick,从使用...

    3 年前
  • npm 包 ks-gallery 使用教程

    介绍 ks-gallery 是一个轻量级、高度可定制化的前端图片库,可以实现图片的滚动、切换和放大等多种功能。它基于 Vue.js 和 Element UI 开发,易于使用和扩展。

    3 年前
  • npm 包 react-date-time 使用教程

    React-date-time 是一个 React 组件,可以方便地在你的 Web 应用程序中添加日期时间选择器。本篇文章将为您详细介绍如何使用 react-date-time,以及如何利用其强大的功...

    3 年前
  • npm 包 vuejs-colorpicker 使用教程

    在前端开发中,色彩选取组件是一个很常见的需求。而 vuejs-colorpicker 这个 npm 包就是一个非常优秀的色彩选取组件,方便易用、功能强大。本文将详细介绍如何使用 vuejs-color...

    3 年前
  • npm 包 vuejs-datatables-sui 使用教程

    概述 vuejs-datatables-sui是一款基于Vue.js和Semantic UI的数据表格组件。它提供丰富的功能和易于使用的API,同时可以自定义样式和主题。

    3 年前
  • npm 包 vuejs-sort 使用教程

    什么是 vuejs-sort? vuejs-sort 是一款基于 Vue.js 的排序组件,可以让你轻松实现表格或列表的排序功能。它通过支持所有类型的排序标签、自定义排序函数、自定义排序算法等强大功能...

    3 年前

相关推荐

    暂无文章