ts-can
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i ts-can

Weekly Downloads

2

Version

1.0.5

License

MIT

Unpacked Size

27.8 kB

Total Files

12

Last publish

Collaborators

  • veselin.reljic