npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@marianmeres/rbac

v2.0.4

Published

[![JSR version](https://jsr.io/badges/@marianmeres/rbac)](https://jsr.io/@marianmeres/rbac) [![NPM version](https://img.shields.io/npm/v/@marianmeres/rbac.svg)](https://www.npmjs.com/package/@marianmeres/rbac) [![License: MIT](https://img.shields.io/badge

Readme

@marianmeres/rbac

JSR version NPM version License: MIT

Lightweight, type-safe Role-Based Access Control (RBAC) library for managing permissions through roles and groups. Includes optional Attribute-Based Access Control (ABAC) for fine-grained resource and context-based permissions.

Features

  • Simple API - Fluent, chainable interface for easy configuration
  • Groups & Roles - Organize permissions hierarchically with group inheritance
  • ABAC Support - Optional rule-based conditional access control
  • Type-safe - Full TypeScript support with strict typing
  • Serializable - Export and restore configurations as JSON
  • Zero dependencies - Minimal footprint
  • Runtime agnostic - Works with Deno, Node.js, and browsers

Installation

Deno:

deno add jsr:@marianmeres/rbac

Node.js:

npm install @marianmeres/rbac

Concepts

  • Permission - A string representing an action (e.g., "article:read", "user:delete")
  • Role - A named set of permissions assigned to users (e.g., "editor", "admin")
  • Group - A reusable set of permissions that roles can inherit from (e.g., "editors")

Roles can have both direct permissions and inherit permissions from groups they belong to.

Quick Start

import { Rbac } from "@marianmeres/rbac";

const rbac = new Rbac();

// Define groups with shared permissions
rbac
    .addGroup("admins", ["*:*"])
    .addGroup("editors", ["article:read", "article:update"]);

// Define roles with direct permissions and group memberships
rbac
    .addRole("admin", [], ["admins"])
    .addRole("editor", [], ["editors"])
    .addRole("user", ["article:read"], []);

// Check permissions
rbac.hasPermission("admin", "*:*");             // true
rbac.hasPermission("editor", "article:update"); // true
rbac.hasPermission("user", "article:update");   // false

// Check for any matching permission (OR logic)
const canRead = rbac.hasSomePermission("user", [
    "*:*",
    "article:*",
    "article:read"
]); // true

API Overview

For complete API documentation with all parameters, return types, and examples, see API.md.

Role Management

| Method | Description | |--------|-------------| | addRole(name, permissions?, groups?) | Create/update a role | | removeRole(name) | Remove a role entirely | | removeRolePermissions(name, permissions?) | Remove specific permissions | | hasRole(name) | Check if a role exists | | getRoles() | Get all role names |

Group Management

| Method | Description | |--------|-------------| | addGroup(name, permissions?) | Create/update a group | | removeGroup(name) | Remove a group entirely | | removeGroupPermissions(name, permissions?) | Remove specific permissions | | hasGroup(name) | Check if a group exists | | getGroups() | Get all group names |

Role-Group Association

| Method | Description | |--------|-------------| | addRoleToGroup(role, group) | Add a role to a group | | removeRoleFromGroup(role, group) | Remove a role from a group |

Permission Checks

| Method | Description | |--------|-------------| | hasPermission(role, permission) | Check if a role has a permission | | hasSomePermission(role, permissions) | Check if a role has any of the permissions | | getPermissions(role) | Get all permissions for a role |

ABAC (Attribute-Based)

| Method | Description | |--------|-------------| | can(subject, permission, resource?, context?) | Check with optional rule evaluation | | addRule(permission, ruleFn) | Add a conditional rule | | removeRule(permission) | Remove a rule | | hasRule(permission) | Check if a rule exists | | getRules() | Get all permissions with rules |

Serialization

| Method | Description | |--------|-------------| | dump() | Export configuration as JSON string | | Rbac.restore(dump) | Create instance from dump | | toJSON() | Get configuration as plain object |

ABAC Example

// Authors can only edit their own drafts
rbac
    .addRole("author", ["article:update"])
    .addRule("article:update", (subject, resource) => {
        if (subject.role === "author") {
            return resource?.authorId === subject.id && resource?.status === "draft";
        }
        return true; // Other roles can edit anything
    });

// Check with resource attributes
rbac.can(
    { role: "author", id: "user123" },
    "article:update",
    { authorId: "user123", status: "draft" }
); // true

Persistence

// Save
const dump = rbac.dump();
localStorage.setItem("rbac-config", dump);

// Restore
const rbac2 = Rbac.restore(localStorage.getItem("rbac-config"));

// Note: Rules are NOT serialized - re-add them after restore
rbac2.addRule("article:update", ownershipRule);

Notes

  • Permission matching is exact (no wildcard expansion)
  • Groups must exist before adding roles to them
  • Removing a group automatically removes it from all roles
  • Roles can belong to multiple groups
  • Duplicate permissions are automatically deduplicated
  • Rules are not serialized - re-add them after restore()

License

MIT