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 🙏

© 2025 – Pkg Stats / Ryan Hefner

permissible

v1.1.0

Published

Fast, space-effective node.js permissions library

Downloads

6

Readme

Introduction

Permissible lets you define a schema for you permissions object.

It uses bitwise math and bigints to store permissions as a bitmask.These operations are very fast. Currently, supported types: boolean and enum.

Converting the permissions object to base64 is useful because of its size. If you need to send permissions over jwt or smaller storage in database, assuming you don't need to query permissions.

Usage

Define you schema. To define a boolean value use key: boolean where the value is the default value. To define an enum use { default: string, fields: string[] }, where fields is the array of available types and default is a value from the array.

const jsonSchema = {
  sendMessage: true,
  readMessageHistory: true,
  deleteMessages: false,
  createThreads: true,
  sendEmoji: true,
  sendFiles: true,
  editChannels: false,
  createChannels: false,
  deleteChannels: false,
  kickUsers: false,
  banUsers: false,
  inviteUsers: true,
  type: {
    default: 'user',
    fields: [
      'user',
      'moderator',
      'admin',
      'owner',
    ],
  },
};

Create your schema

const schema: Schema<typeof jsonSchema> = new Schema(jsonSchema);

You can create a Permissions object from base64 string

const pString = 'OwgA';
const pFromString: Permissions<typeof jsonSchema> = Permissions.fromBase64(pString, schema);

Check permissions using .is(field, [value])

if (pFromString.is(schema.fields.sendMessage)) {
  console.log('This user can send messages');
}

if (pFromString.is(schema.fields.type, schema.fields.type.admin)) {
  console.log('This user is admin');
}
This user can send messages

Set permissions using .set(field, value)

console.log('Checking permissions')
if (pFromString.is(schema.fields.type, schema.fields.type.admin)) {
  console.log('This user is admin');
}

if (pFromString.is(schema.fields.kickUsers)) {
  console.log('This user can kick users');
}

if (pFromString.is(schema.fields.banUsers)) {
  console.log('This user can ban users');
}

console.log('Setting permissions')
pFromString.set(schema.fields.kickUsers, true);
pFromString.set(schema.fields.banUsers, true);
pFromString.set(schema.fields.type, schema.fields.type.admin);

console.log('Checking permissions');
if (pFromString.is(schema.fields.type, schema.fields.type.admin)) {
  console.log('This user is admin');
}

if (pFromString.is(schema.fields.kickUsers)) {
  console.log('This user can kick users');
}

if (pFromString.is(schema.fields.banUsers)) {
  console.log('This user can ban users');
}

if (pFromString.is(schema.fields.type, schema.fields.type.admin)) {
  console.log('This user is admin');
}
Checking permissions
Setting permissions
Checking permissions
This user is admin
This user can kick users
This user can ban users

Create permissions from schema defaults

const defaultPermissions: Permissions<typeof jsonSchema> = schema.createDefault();
console.log(defaultPermissions.toJson());
{
  sendMessage: true,
  readMessageHistory: true,
  deleteMessages: false,
  createThreads: true,
  sendEmoji: true,
  sendFiles: true,
  editChannels: false,
  createChannels: false,
  deleteChannels: false,
  kickUsers: false,
  banUsers: false,
  inviteUsers: true,
  type: 'user'
}

Create permissions from json

const json: JsonPermissions = {
  sendMessage: true,
  readMessageHistory: true,
  deleteMessages: false,
  createThreads: true,
  sendEmoji: true,
  sendFiles: true,
  editChannels: false,
  createChannels: false,
  deleteChannels: false,
  kickUsers: false,
  banUsers: false,
  inviteUsers: true,
  type: 'user',
};

const pFromJson: Permissions<typeof jsonSchema> = Permissions.fromJson(json, schema);

const pJson: JsonPermissions = pFromJson.toJson();
console.log(pJson);
{
  sendMessage: true,
  readMessageHistory: true,
  deleteMessages: false,
  createThreads: true,
  sendEmoji: true,
  sendFiles: true,
  editChannels: false,
  createChannels: false,
  deleteChannels: false,
  kickUsers: false,
  banUsers: false,
  inviteUsers: true,
  type: 'user'
}

You can make empty permissions using the Permissions constructor

const pFromCtor: Permissions<typeof jsonSchema> = new Permissions(0n, schema);
console.log(pFromCtor.toJson());
{
  sendMessage: false,
  readMessageHistory: false,
  deleteMessages: false,
  createThreads: false,
  sendEmoji: false,
  sendFiles: false,
  editChannels: false,
  createChannels: false,
  deleteChannels: false,
  kickUsers: false,
  banUsers: false,
  inviteUsers: false,
  type: 'user'
}

You can format as base64 or json

const defaultPermissions: Permissions<typeof jsonSchema> = schema.createDefault();
console.log(defaultPermissions.toJson());
console.log(defaultPermissions.toBase64());
{
  sendMessage: true,
  readMessageHistory: true,
  deleteMessages: false,
  createThreads: true,
  sendEmoji: true,
  sendFiles: true,
  editChannels: false,
  createChannels: false,
  deleteChannels: false,
  kickUsers: false,
  banUsers: false,
  inviteUsers: true,
  type: 'user'
}
OwgA

Type inference

Types can be inferred, this is valid typescript.

const newJsonSchema = {
  a: true,
  b: false,
};

const newSchema = new Schema(newJsonSchema);
console.log(newSchema.createDefault().toJson());