
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
permission-checker
Advanced tools
A permission checker for JS and TS with support for Node.js, Bun, and browsers.
A lightweight and efficient permission checking library for JavaScript and TypeScript with zero dependencies, compatible with:
# Using npm
npm install permission-checker
# Using yarn
yarn add permission-checker
# Using pnpm
pnpm add permission-checker
# Using Bun
bun add permission-checker
import { checkSingle, checkList } from 'permission-checker';
// Check a single permission
console.log(checkSingle('user.profile', 'user.profile')); // true
// Check multiple permissions
console.log(
checkList(
['user.read', 'admin.dashboard'],
['user.read', 'admin.dashboard']
)
); // true
const { checkSingle, checkList } = require('permission-checker');
// Check a single permission
console.log(checkSingle('user.profile', 'user.profile')); // true
<script type="module">
import { checkSingle, checkList } from 'https://unpkg.com/permission-checker/dist/esm/index.js';
// Use the functions
console.log(checkSingle('*', 'any.permission')); // true
console.log(
checkList(
['user.read', 'admin.*'],
['user.read', 'admin.dashboard']
)
); // true
</script>
import { checkSingle, checkList } from 'permission-checker';
// Works the same as Node.js ESM
console.log(checkSingle('app.feature', 'app.*')); // true
checkSingle(permission: string, requiredPermission: string): boolean
Checks if a single permission matches a required permission, supporting wildcards and hierarchical permissions.
permission
: The permission to check (e.g., "user.profile"
)requiredPermission
: The required permission to check against (e.g., "user.*"
)boolean
: true
if the permission is granted, false
otherwiseimport { checkSingle } from 'permission-checker';
// Exact match
checkSingle('user.profile', 'user.profile'); // true
// Wildcard matches anything
checkSingle('*', 'any.permission'); // true
// Hierarchical permissions
checkSingle('user', 'user.profile'); // true
checkSingle('user.profile', 'user'); // false
// Partial wildcards
checkSingle('user.*', 'user.profile'); // true
checkSingle('user.*', 'admin.dashboard'); // false
checkList(permissions: string[], requiredPermissions: string[]): boolean
Checks if all required permissions are satisfied by the provided permissions.
permissions
: Array of available permissionsrequiredPermissions
: Array of required permissionsboolean
: true
if all required permissions are satisfied, false
otherwiseimport { checkList } from 'permission-checker';
// All permissions present
checkList(
['user.read', 'user.write', 'admin.dashboard'],
['user.read', 'admin.dashboard']
); // true
// Some permissions missing
checkList(
['user.read'],
['user.read', 'admin.dashboard']
); // false
// Wildcard covers all
checkList(
['*'],
['user.read', 'admin.dashboard']
); // true
// Hierarchical permissions
checkList(
['user', 'admin'],
['user.profile', 'admin.settings']
); // true
With 2 values, x
and y
, the empty string, and *
Permission | Required | Result | Description |
---|---|---|---|
* | * | TRUE | Two equal permissions (e.g. a.* & a.* ) |
x | x | TRUE | Two equal permissions (e.g. a.b & a.b ) |
x | y | FALSE | Two different permissions (e.g. a.b & a.c ) |
x | TRUE | The empty string represents all permissions (e.g. a & a.b ) | |
x | FALSE | The empty string represents all permissions (e.g. a.b & a ) | |
* | TRUE | The empty string includes * (e.g. a & a.* ) | |
* | FALSE | The empty string includes * (e.g. a.* & a ) | |
* | x | TRUE | * includes all (e.g. a.* & a.b ) |
x | * | FALSE | * includes all (e.g. a.b & a.* ) |
TRUE | Do not use empty string as permission. | ||
not | x | ERROR | Do not use "not" as permission. |
x | not | FALSE | Always false. |
fill(array: string[], length: number): string[]
Pads an array with empty strings until it reaches the specified length. If the array is already longer than the specified length, it is returned unchanged.
array
: The array to pad with empty stringslength
: The desired length of the arraystring[]
: A new array with length at least length
, padded with empty strings if necessaryimport { fill } from 'permission-checker';
// Returns ['a', 'b', '']
fill(['a', 'b'], 3);
// Returns ['a', 'b']
fill(['a', 'b'], 1);
evaluate(permissions: string[], calculation: Calculation): boolean
Evaluates complex permission calculations against a set of user permissions, supporting logical AND, OR, and NOT operations.
permissions
: Array of permission strings that the user hascalculation
: The permission calculation to evaluate (can be an AND, OR, NOT operation, or a direct permission check)boolean
: true
if the calculation evaluates to true with the given permissions, false
otherwisetype And = { $and: Calculation[] };
type Or = { $or: Calculation[] };
type Not = { $not: Calculation };
type Permission = string[];
type Calculation = And | Or | Not | Permission;
import { evaluate } from 'permission-checker';
// Simple permission check
evaluate(['user.read', 'user.write'], ['user.read']); // true
// AND operation
evaluate(
['user.read', 'user.write'],
{ $and: [['user.read'], ['user.write']] }
); // true
// OR operation
evaluate(
['user.read'],
{ $or: [['user.read'], ['admin.access']] }
); // true
// NOT operation
evaluate(
['user.read'],
{ $not: ['admin.access'] }
); // true
// Complex nested operations
evaluate(
['user.read', 'admin.dashboard'],
{
$and: [
{ $or: [['user.read'], ['user.write']] },
{ $not: ['admin.settings'] }
]
}
); // true
The package includes TypeScript type definitions out of the box:
import type { PermissionChecker } from 'permission-checker';
// Type-safe usage with TypeScript
const hasPermission: boolean = checkSingle('user.profile', 'user.*');
checkSingle('user.profile', 'user.profile')
checkSingle('*', 'any.permission')
checkSingle('user', 'user.profile')
checkSingle('user.*', 'user.profile')
The library is optimized for performance with:
Contributions are welcome! Please see our Contributing Guidelines for more details.
Apache-2.0 © ThunderNetworkRaD
// Wildcard support
console.log(checkList(["*"], ["any.permission"])); // true
// Multiple required permissions
console.log(
checkList(
["user.read", "user.write"],
["user.read", "user.delete"]
)
); // false (missing user.delete)
// Sub-permission check
console.log(
checkList(
["user"],
["user.read", "user.write"]
)
); // true (user includes all sub-permissions)
Contributions are welcome! Please read our contributing guidelines to get started.
Apache-2.0 © ThunderNetworkRaD
FAQs
A permission checker for JS and TS with support for Node.js, Bun, and browsers.
We found that permission-checker demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.