Perman.JS
Get support 禄
Report Bug 路 Request Feature 路 Webpage
馃攽
Perman
Permission management made easy
馃摝
Installation
- Using yarn:
yarn add perman
- Using npm:
npm i perman
馃
Usage
See API for all methods
import { Perman } from "perman";
const perman = Perman.from(["user", "verified", "admin"]);
const user = perman.serialize(["user"]);
const verified = perman.serialize(["user", "verified"]);
const admin = perman.serialize(["user", "admin"]);
perman.has(user, "user"); // true
perman.has(user, "admin"); // false;
perman.has(verified, "verified"); // true;
perman.has(verified, "admin"); // false;
perman.has(admin, "admin"); // true;
// add permissions
perman.has(user, "verified"); // false;
user = perman.add(user, "verified");
perman.has(user, "verified"); // true;
// remove permissions
perman.has(verified, "verified"); // true;
verified = perman.remove(verified, "verified");
perman.has(verified, "verified"); // false;
馃搫
License
Copyright 漏 2022 Bar谋艧 DEM陌RC陌.
Distributed under the GPL-3.0 License. See LICENSE
for more information.
馃Е
Contributing
Fell free to use GitHub's features.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/my-feature
) - Run prettier (
npm run format
) - Commit your Changes (
git commit -m 'my awesome feature my-feature'
) - Push to the Branch (
git push origin feature/my-feature
) - Open a Pull Request
馃敟
Show your support
Give a
馃摓
Contact
- Mail: [email protected]
- Discord: https://discord.gg/BjEJFwh
- Instagram: https://www.instagram.com/ben_baris.d/
- Webpage: https://338.rocks
馃摐
API
Method | Description | Usage | Output |
---|---|---|---|
from (static) |
Creates a new Perman instance | <Perman>.from(flags: string[]) |
Perman |
keys |
Returns all flag names | perman.keys() |
string[] |
values |
Returns all flag values | perman.values() |
number[] |
get |
Returns the numeric value of flag | perman.get(flag: string) |
number |
serialize |
Serializes the flags | perman.serialize(flags: string[]) |
number |
deserialize |
Deserializes the permission | perman.deserialize(permissions: number) |
string[] |
match |
Matches permissions with flags, if permissions has all flags, returns true | perman.match(permissions: number, flags: string[]) |
boolean |
matchAll (alias of match ) |
Matches permissions with flags, if permissions has all flags, returns true | perman.matchAll(permissions: number, flags: string[]) |
boolean |
hasAll (alias of match ) |
Matches permissions with flags, if permissions has all flags, returns true | perman.hasAll(permissions: number, flags: string[]) |
boolean |
some |
Matches permissions with flags, if permissions has at least one flag, returns true | perman.some(permissions: number, flags: string[]) |
boolean |
hasSome (alias of some ) |
Matches permissions with flags, if permissions has at least one flag, returns true | perman.hasSome(permissions: number, flags: string[]) |
boolean |
hasNone |
Matches permissions with flags, if permissions has at least one flag, returns false | perman.hasNone(permissions: number, flags: string[]) |
boolean |
none (alias of hasNone ) |
Matches permissions with flags, if permissions has at least one flag, returns false | perman.hasNone(permissions: number, flags: string[]) |
boolean |
has |
Checks if the given permission is granted | perman.has(permission: number, flag: (number or string)) |
boolean |
test (alias of has ) |
Checks if the given permission is granted | perman.test(permission: number, flag: (number or string)) |
boolean |
add |
Adds a new flag to given permission | perman.add(permission: number, flag: string) |
number |
remove |
Removes a flag from given permission | perman.remove(permission: number, flag: string) |
number |
full |
Creates a permission with all flags | perman.full() |
number |