# n-arg-parser

> [![npm version](https://badge.fury.io/js/n-arg-parser.svg)](https://badge.fury.io/js/n-arg-parser) [![npm downloads](https://img.shields.io/npm/dt/n-arg-parser.svg?style=flat)](https://www.npmjs.com/package/n-arg-parser)

Latest version **1.0.2** (published 2020-05-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install n-arg-parser
pnpm add n-arg-parser
yarn add n-arg-parser
bun add n-arg-parser
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2020-05-04 |
| First published | 2020-05-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | w4rlock |

## Links

- npm: https://www.npmjs.com/package/n-arg-parser
- npm.io page: https://npm.io/package/n-arg-parser

## Recent versions

- 1.0.2 (latest) — 2020-05-04
- 1.0.0 — 2020-05-03
- 0.0.1 — 2020-05-02

## README

[![npm version](https://badge.fury.io/js/n-arg-parser.svg)](https://badge.fury.io/js/n-arg-parser)
[![npm downloads](https://img.shields.io/npm/dt/n-arg-parser.svg?style=flat)](https://www.npmjs.com/package/n-arg-parser)

### DESCRIPTION
A simple and easy command line arguments parser for Node js.


### INSTALLATION
```bash
npm i -E n-arg-parser
```

### FEATURES
```yaml
Auto Parser Argument Value.
- Int.
- Float.
- String.
- Regular Expresion (custom).

- Auto Generate Help.
- Required fields.
- Fail on Unknown options and show help.
- Friendly messages.
- No externals libs.
- Easy Builder User Model Configuration.
```

### USAGE
```js
const { ArgParser, Option } = require('n-arg-parser');

const opts = new ArgParser()
  .setDescription('Test Argument Parser')
  .addOption(new Option('--arg-int').desc('test int').int().isRequired())
  .addOption(new Option('--arg-float') .desc('test float').float())
  .addOption(new Option('--arg-string').string().short('-s'))
  .addOption(new Option('--arg-regexp').regexp(/\d{2}/).desc('test 2 numbers regexpr').isRequired())
  .parse();

console.log(JSON.stringify(opts));


```


### RUN EXAMPLE

```bash
$ node example.js --help

  DESCRIPTION:
        Test Argument Parser


  USAGE:
        ./example.js <OPTION>


  OPTIONS:

        --arg-int             test int
        --arg-float           test float
        --arg-regexp          test 2 numbers regexpr
        --arg-string    -s
        --help          -h

```
### VALIDATIONS

```bash
$ node example.js --arg-idsad
  ERROR: unknown option "--arg-idsad"


$ node example.js --arg-int aaa
  ERROR: parameter "--arg-int" requires a valid int number.


$ node example.js --arg-int 22
  ERROR: parameter "--arg-regexp" is required.


$ node example.js --arg-int 12 --arg-regexp aa
  ERROR: parameter "--arg-regexp" requires a valid Regular Expression for "/\d{2}/".

$ node example.js --arg-int 12 --arg-regexp 22
{
  "argint": 12,
  "argregexp": [ "22" ]
}
```

---
_Source: https://npm.io/package/n-arg-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
