JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2302
  • Score
    100M100P100Q115873F
  • License MIT

Simple ACL library for the browser inspired by Laravel's guards and policies.

Package Exports

  • browser-acl

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (browser-acl) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

browser-acl

build status Known Vulnerabilities NPM version

Simple ACL library for the browser inspired by Laravel's guards and policies.

Install

yarn add browser-acl

Usage

import Acl from 'browser-acl'
const acl = new Acl()

// Attach acl function to user class/constructor
// Adds: user.can() function
acl.attach(User)

acl.rule('view', Post)
acl.rule(['edit', 'delete'], Post, (user, post) => post.id === user.id)

if (user.can('edit', post)) {
  // code for when user has permission
}

Policies are also supported:

acl.policy({
    view: () => true,
    edit: (user, post) => post.id === user.id),
}, Post)

if (user.can('edit', post)) {
  // code for when user has permission
}

Note: policies takes precedence over rules.

API