Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/barbarbar338/bargs
- Owner: barbarbar338
- License: gpl-3.0
- Created: 2020-11-17T17:42:51.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-18T16:53:55.000Z (almost 3 years ago)
- Last Synced: 2024-12-27T09:51:38.001Z (18 days ago)
- Topics: arg, args, argument, argument-parser, argument-parsing, arguments, argv, argv-parser, bargs, parse, parser, parsing, ts, typescript
- Language: TypeScript
- Homepage: https://npmjs.com/bargs
- Size: 56.6 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 ✨