# @trenskow/arguments-parser

> Yet another arguments parser.

Latest version **0.3.166** (published 2026-10-05) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install @trenskow/arguments-parser
pnpm add @trenskow/arguments-parser
yarn add @trenskow/arguments-parser
bun add @trenskow/arguments-parser
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.3.166 |
| Published | 2026-10-05 |
| First published | 2024-12-18 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 28.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kristian Trenskow |
| Maintainers | trenskow |
| Keywords | arguments, parser, argument, parse |

## Links

- npm: https://www.npmjs.com/package/@trenskow/arguments-parser
- Repository: https://github.com/trenskow/arguments-parser
- Homepage: https://github.com/trenskow/arguments-parser#readme
- Issues: https://github.com/trenskow/arguments-parser/issues
- npm.io page: https://npm.io/package/@trenskow/arguments-parser

## Dependencies (4)

- [isvalid](https://npm.io/package/isvalid.md) ^5.0.31
- [@trenskow/print](https://npm.io/package/@trenskow/print.md) ^0.1.87
- [@trenskow/caseit](https://npm.io/package/@trenskow/caseit.md) ^1.4.34
- [@trenskow/parallel](https://npm.io/package/@trenskow/parallel.md) ^0.1.149

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.3.166 (latest) — 2026-10-05
- 0.3.165 — 2026-10-05
- 0.3.164 — 2026-10-05
- 0.3.163 — 2026-10-05
- 0.3.162 — 2026-10-05
- 0.3.161 — 2026-10-05
- 0.3.159 — 2026-09-21
- 0.3.160 — 2026-09-21
- 0.3.158 — 2026-09-21
- 0.3.157 — 2026-09-21
- 0.3.156 — 2026-09-21
- 0.3.155 — 2026-09-21
- 0.3.154 — 2026-09-18
- 0.3.153 — 2026-09-18
- 0.3.151 — 2026-09-18
- … 184 more at https://npm.io/package/@trenskow/arguments-parser/versions

## README

# @trenskow/arguments-parser

Yet another arguments parser.

# Usage

````javascript
import argumentsParser from '@trenskow/arguments-parser';

const login = async (...args) => {

	const {
		username,
		password
	} = await argumentParser(args).options({
		username: {
			type: String,
			required: true,
			len: '1-',
			description: "Username of the user"
		},
		password: {
			type: String,
			required: true,
			len: '6-',
			description: "Password of the user"
		}
	}, { login });

	// Do login logic.

};

login.description = 'Logs in a user';

const message = async (...args) => {

	const {
		message
	} = await argumentParser(args).options({
		message: {
			type: String,
			default: 'Empty message',
			description: 'Message to send'
		}
	}, { message });

	// Do message logic.

};

message.description = 'Sends a message from a user.';

await argumentsParser(/* argv (default is `process.argv.slice(2)` */)
	.command({ login, message });
````

The above example will output.

````
# ./my-script
Usage: my-script [command]

Available commands:
	login    Logs in a user.
	message  Sends a message from a user.
# ./my-script login --help
Usage: my-script login [options]

Options:
	 --username  Username of the user.
	 --password  Password of the user.
# ./my-script message --help
Usage: my-script message [options]

Options:
	--message  Message to send (default: `Empty message`).

````

> The validation schema is described in package [isvalid](https://github.com/trenskow/isvalid).

## Autocompletion

The library supports Bash and ZSH autocompletion out of the box.

To generate the completion scripts to install for the current shell - use the command below...

````
./my_script _completion
````

...or if you need to generate for another shell than the current one.

````
./my_script _completion [bash|zsh]
````

# License

See license in LICENSE.

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