Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/barbarbar338/bargs

✨ A simple argument parsing system
https://github.com/barbarbar338/bargs

arg args argument argument-parser argument-parsing arguments argv argv-parser bargs parse parser parsing ts typescript

Last synced: 9 days ago
JSON representation

✨ A simple argument parsing system

Awesome Lists containing this project

README

        

# 🦄 Bargs

- A simple argument parsing system with 0 dependencies ✨

# 📥 Installation

Using yarn:

```
$ yarn add bargs
```

Using npm:

```
$ npm install bargs
```

# 🔧 Usage

```js
bargs(OptionDefinitions, argv?);
```

- `OptionDefinitions`: Where options are defined to be used when separating arguments. Structure:

```js
[
{
name: "OptionName",
type: String, //OptionType (function)
aliases?: [ "option", "aliases", "t" ],
default?: false
}
]
```

- `argv?`: Arguments to parse. Default is `process.argv.slice(2)`.

# 🛠️ Example

```js
/* 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 ✨