Wondering what’s next for npm?Check out our public roadmap! »

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

    1.0.3 • Public • Published

    🦄 Bargs

    • A simple argument parsing system with 0 dependencies

    📥 Installation

    Using yarn:

    $ yarn add bargs
    

    Using npm:

    $ npm install bargs
    

    🔧 Usage

    bargs(OptionDefinitions, argv?);
    • OptionDefinitions: Where options are defined to be used when separating arguments. Structure:
    [
        {
            name: "OptionName",
            type: String, //OptionType (function)
            aliases?: [ "option", "aliases", "t" ],
            default?: false
        }
    ]
    • argv?: Arguments to parse. Default is process.argv.slice(2).

    🛠️ Example

    /* es6 */
    import { bargs } from "bargs";
    
    /* commonJS */
    const { bargs } = require("bargs");
    
    const definitions = [
    	{ name: "help", type: Boolean, aliases: ["h", "halp", "yardim", "y"] },
    	{ name: "message", type: String, default: true },
    	{ name: "page", type: Number },
    ];
    
    const argv = ["This", "is", "message", "-h", "--page", "2", "--foo", "bar"];
    
    bargs(definitions, argv);
    /*
     * {
     *     _unknown: {
     *         foo: "bar"
     *     },
     *     help: true,
     *     message: "This is message",
     *     page: 2
     * }
     */

    🔗 Contributing / Issues / Ideas

    Feel free to use GitHub's features

    Install

    npm i bargs

    DownloadsWeekly Downloads

    6

    Version

    1.0.3

    License

    GPL-3.0

    Unpacked Size

    87.6 kB

    Total Files

    10

    Last publish

    Collaborators

    • avatar