0.0.6 • Published 3 years ago

minimalist-acl-test v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Minimalist ACL

Minimalistic ACL implementation for privileges management in javascript

NPM Version GitHub license

Installation

$ npm i minimalist-acl --save

or

$ yarn add minimalist-acl --save

Usage

// using ES modules
import { check } from "minimalist-acl";
// using CommonJS modules
const { check } = require("minimalist-acl");

const user = {
  get roles() {
    return ["moderator"];
  },
};

const can = check("administrator || moderator", (role) => {
  return user.roles.includes(role);
});

if (!can) {
  throw new Error("You not allowed to this resource.");
}

Syntax

and (&&) - administrator && moderator

or (||) - administrator || moderator

not (!) - administrator && !moderator

Support

Having a problem? Open an issue I will be happy to help you.

License

The MIT License (MIT). Please see License File for more information.