Skip to content

barbarbar338/bargs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🦄 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 ✨