# argentum

> Command line arguments parser

Latest version **0.6.0** (published 2016-07-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install argentum
pnpm add argentum
yarn add argentum
bun add argentum
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.0 |
| Published | 2016-07-29 |
| First published | 2015-11-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | rumkin |
| Keywords | cli, opts, getopt, parse, arguments, argv, args |

## Links

- npm: https://www.npmjs.com/package/argentum
- Repository: https://github.com/rumkin/argentum
- Homepage: https://github.com/rumkin/argentum#readme
- Issues: https://github.com/rumkin/argentum/issues
- npm.io page: https://npm.io/package/argentum

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 0.6.0 (latest) — 2016-07-29
- 0.5.5 — 2016-07-28
- 0.5.4 — 2016-06-17
- 0.5.3 — 2016-06-16
- 0.5.2 — 2016-06-08
- 0.4.1 — 2016-05-26
- 0.4.0 — 2016-03-23
- 0.3.0 — 2016-03-21
- 0.2.3 — 2016-03-21
- 0.2.2 — 2016-03-21
- 0.1.3 — 2015-12-08
- 0.1.2 — 2015-12-07
- 0.1.1 — 2015-12-01
- 0.1.0 — 2015-11-26

## README

Argentum
---

![Build](https://img.shields.io/travis/rumkin/argentum.svg)
[![Coverage Status](https://coveralls.io/repos/rumkin/argentum/badge.svg?branch=master&service=github)](https://coveralls.io/github/rumkin/argentum?branch=master)


Argentum is a unified command line arguments parser. It parses arguments into
JS values boolean, number, date, string or array of values. Argentum has no
schema like other parsers it just try to parse all passed values.

It has several rules to parse values:
* Rule could be `--name`, `--name=value`, `--name[]` and `--name[]=value`.
* Kebab case converts into camel case `--some-name` becomes `someName`.
* Empty property value is true: `--bool` mean `true`.
* Arrays overwrite previous value: `--arr=1 --arr[]` has empty array with name `arr`.

Note that parsed values pull out from passed array.

## Example

Argentum converts command line arguments into appropriate JS types.

```shell
node app.js --host=localhost --port=8080 --dirs[] public build
```

Result of parsing is:

```javascript
{
  host: 'localhost',
  port: 8080,
  dirs: ['public', 'build']
}
```

## Usage

```javascript
var argentum = require('argentum');

// Parsing
argentum.parse(['--hello=world']); // -> {hello: "world"}

// Splicing
var args = ['-x', 'value', '-d'];
argentum.parse(args); // -> {x: true, d: true}
args; // -> ['value']
```

Parsing schema

| Cli               | JavaScript         |
|:------------------|:-------------------|
| `-v`              | `{v: true}`        |
| `--hello=world`   | `{hello: 'world'}` |
| `--number=1`      | `{number: 1}`      |
| `--bool`          | `{bool: true}`     |
| `--a[] 1 2`       | `{a: [1,2]}`       |
| `--a[]=1 --a[]=2` | `{a: [1,2]}`       |


## Interface

Package require interface.

## parse(string[], options{}) -> object

Parse array of strings and return an object of properties.

### options.defaults -> object

Default values dictionary. Example:

```javascript
var args = argentum.parse(
    ['--verbose'],
    {defaults:{
        debug: true
    }}
);
args; // -> {debug: true, verbose: true}
```

### options.aliases -> object

Aliases dictionary where key is alias and value is the property. Example:

```javascript
var args = argentum.parse(
    ['-d'],
    {aliases:{
        d: 'debug'
    }}
);
args; // -> {debug: true}
```

### options.eval -> bool

If passed then all string values in source array will be converted in their js
equivalent:

```javascript
var argv = ['1', '10.99', 'true', 'false', 'hello'];
argentum.parse(argv, {eval: true});
argv; // => [1, 10.99, true, false, 'hello']
```

## parseValue(string) -> boolean|number|string

Parse string value to match `true`, `false` or number patterns otherwise return
string.

## split(args string[],limit number) -> string[][]

Split array into two arrays with double hyphen as separator. Limit should match
count of found separators.

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