- A simple argument parsing system with 0 dependencies ✨
Using yarn:
$ yarn add bargs
Using npm:
$ npm install bargs
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 isprocess.argv.slice(2)
.
/* 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
* }
*/
Feel free to use GitHub's features ✨