Options
All
  • Public
  • Public/Protected
  • All
Menu

ts-can

ts-can

License npm version

Small 0 dependencies TypeScript library for managing and checking user permissions

Table of Contents

Installation

npm install ts-can

Usage

import { Permissions, TestRules, checkPermissions, canAllow } from 'permissions-library';

// Define user permissions
const userPermissions: Permissions = {
  'moduleA': {
    abilities: { read: true, write: false },
    checks: { isAdmin: (target) => target.isAdmin }
  },
  'moduleB': {
    abilities: { read: true, write: true },
    checks: { hasAccess: (target) => target.isValidUser }
  },
  // ... other modules
};

// Define test rules
const testRules: TestRules = {
  'moduleA': { abilities: ['read'] },
  'moduleB': { checks: ['hasAccess'], target: { isValidUser: true } },
  // ... other test rules
};

// Check if user has required permissions for all test rules
const result = canAllow(userPermissions, testRules);
console.log(result); // Output: true

API Documentation

Please refer to the official documentation for detailed information about the API and usage examples.

Generated using TypeDoc