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

guantr

v2.0.0

Published

Flexible, type-safe JavaScript library for efficient authorization and permission checking

Readme

Guantr

npm version npm downloads

A flexible, type-safe JavaScript library for authorization and permission checking. Define rules with a composable builder DSL, check permissions against resource instances, and leverage context-aware conditions — all with full TypeScript support.

Install

# ✨ Auto-detect
npx nypm install guantr

# npm
npm install guantr

# yarn
yarn add guantr

# pnpm
pnpm add guantr

# bun
bun install guantr

# deno
deno install npm:guantr

ESM (Node.js, Bun, Deno)

import { createGuantr } from 'guantr';

CommonJS (Legacy Node.js)

const { createGuantr } = require('guantr');

CDN (Deno and Browsers)

import { createGuantr } from 'https://esm.sh/guantr';

Quick Start

import { createGuantr } from 'guantr';
import type { GuantrMeta } from 'guantr';

// 1. Define your resource map and context
type MyMeta = GuantrMeta<
  {
    post: {
      action: 'read' | 'create' | 'update' | 'delete';
      model: { id: number; title: string; published: boolean; authorId: number };
    };
  },
  { userId: number }
>;

// 2. Create an instance
const guantr = await createGuantr<MyMeta>({
  context: () => ({ userId: 1 }),
});

// 3. Set rules with the builder DSL
await guantr.setRules((allow, deny) => {
  allow('read', 'post');
  deny('read', ['post', ({ eq, resource, literal }) => eq(resource('published'), literal(false))]);
  allow('update', [
    'post',
    ({ eq, resource, context }) => eq(resource('authorId'), context('userId')),
  ]);
});

// 4. Check permissions
const post = { id: 1, title: 'Hello', published: false, authorId: 1 };

await guantr.can.abstract('read', 'post'); // true — any allow rule exists?
await guantr.can('read', ['post', post]); // false — denied by condition
await guantr.can('update', ['post', post]); // true — author is owner

// Batch checks — context resolved once
await guantr.can.all([
  ['read', ['post', post]],
  ['update', ['post', post]],
]);

Condition Builder DSL

Guantr v2 uses a type-safe builder DSL for conditions:

import type { MatchConditionFn } from 'guantr';

const condition: MatchConditionFn<Post, Context> = ({ and, eq, resource, literal }) =>
  and(eq(resource('status'), literal('published')), eq(resource('deleted'), literal(false)));

// Use in rule objects or callbacks:
await guantr.setRules([
  {
    effect: 'allow',
    action: 'read',
    resource: 'post',
    matchCondition: condition,
  },
]);

All conditions are serialized to a JSON-compatible AST at definition time, making them storable in any database.

API Overview

Permission Checks

| Method | Description | | ----------------------------------------- | -------------------------------------------------- | | can(action, [resourceKey, instance]) | Full evaluation against a specific instance | | cannot(action, [resourceKey, instance]) | Negated can | | can.abstract(action, resourceKey) | Any allow rule exists? (ignores conditions/denies) | | cannot.abstract(action, resourceKey) | Negated can.abstract | | can.all(checks) | All checks must pass | | can.any(checks) | Any check must pass | | cannot.all(checks) | All checks must be denied | | cannot.any(checks) | Any check must be denied |

Rule Management

| Method | Description | | ----------------------------------- | -------------------------------- | | setRules((allow, deny) => {}) | Replace rules via callback | | setRules([...]) | Replace rules via array | | getRules() | Retrieve all stored rules | | relatedRulesFor(action, resource) | Query rules by action + resource |

Storage & Context

await createGuantr<Meta>({
  storage: new MyCustomStorage(), // default: InMemoryStorage
  context: () => ({ userId: 1 }), // default: {}
  maxRuleIterations: 500, // default: 1000
});

Development

  • Clone this repository
  • Install latest LTS version of Node.js
  • Enable Corepack using corepack enable
  • Install dependencies using pnpm install
  • Run playground using pnpm play

License

Published under the MIT license. Made by community 💛


🤖 auto updated with automd