Skip to main content

latest

Handle authorization in your javascript applications like a boss

JSR Score
52%
Published
4 months ago (0.0.1)

Vigia

Handle authorization in your javascript applications like a boss

Examples

import { Role } from "https://deno.land/x/vigia/mod.ts";

const userRole = new Role();

userRole.buildPermissions([
  ["can", "make", "coffee"],
  ["cannot", "make", "sandwich"],
]);

userRole.can("make", "coffee"); // true
userRole.cannot("make", "coffee"); // false

if (userRole.can("make", "coffee")) {
  // work more...
} else {
  // work to buy more coffee
}

You can choose the builder pattern to set the role permissions.

import { Role } from "https://deno.land/x/vigia/mod.ts";

const userRole = new Role();

userRole.set("can", "make", "coffee").set("cannot", "make", "sandwich");

userRole.can("make", "coffee"); // true
userRole.cannot("make", "coffee"); // false

if (userRole.can("make", "coffee")) {
  // work more...
} else {
  // work to buy more coffee
}

You can also save and/or fetch your roles by using the getRaw() method that returns an array of abilities.

const userRole = new Role();

userRole.buildPermissions([
  ["can", "make", "coffee"],
  ["cannot", "make", "sandwich"],
]);

userRole.getRaw(); // [ ["can", "make", "coffee"], ["cannot", "make", "sandwich"] ]

Add Package

deno add @sampaiol/vigia

Import symbol

import * as mod from "@sampaiol/vigia";

Add Package

npx jsr add @sampaiol/vigia

Import symbol

import * as mod from "@sampaiol/vigia";

Add Package

yarn dlx jsr add @sampaiol/vigia

Import symbol

import * as mod from "@sampaiol/vigia";

Add Package

pnpm dlx jsr add @sampaiol/vigia

Import symbol

import * as mod from "@sampaiol/vigia";

Add Package

bunx jsr add @sampaiol/vigia

Import symbol

import * as mod from "@sampaiol/vigia";