Nagging Penguin Matriarchs

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

    1.0.2 • Public • Published

    stars license supportServer forks issues

    Logo

    Perman.JS

    🔑 Permission management made easy
    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.

    1. Fork the Project
    2. Create your Feature Branch (git checkout -b feature/my-feature)
    3. Run prettier (npm run format)
    4. Commit your Changes (git commit -m 'my awesome feature my-feature')
    5. Push to the Branch (git push origin feature/my-feature)
    6. Open a Pull Request

    🔥 Show your support

    Give a ⭐️ if this project helped you!

    📞 Contact

    📜 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

    Install

    npm i perman

    DownloadsWeekly Downloads

    27

    Version

    1.0.2

    License

    GPL-3.0

    Unpacked Size

    88.9 kB

    Total Files

    8

    Last publish

    Collaborators

    • leydihavuc