# tiny-parse-argv

> A tiny function for parsing process.argv, a modern rewrite of minimist.

Latest version **2.8.2** (published 2025-02-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install tiny-parse-argv
pnpm add tiny-parse-argv
yarn add tiny-parse-argv
bun add tiny-parse-argv
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 2.8.2 |
| Published | 2025-02-20 |
| First published | 2022-11-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 19.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Maintainers | fabiospampinato |
| Keywords | tiny, parse, argv |

## Links

- npm: https://www.npmjs.com/package/tiny-parse-argv
- Repository: https://github.com/fabiospampinato/tiny-parse-argv
- Homepage: https://github.com/fabiospampinato/tiny-parse-argv#readme
- Issues: https://github.com/fabiospampinato/tiny-parse-argv/issues
- npm.io page: https://npm.io/package/tiny-parse-argv

## 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

- 2.8.2 (latest) — 2025-02-20
- 2.8.1 — 2025-01-12
- 2.8.0 — 2024-09-12
- 2.7.0 — 2024-09-01
- 2.6.0 — 2024-08-31
- 2.5.1 — 2024-05-27
- 2.5.0 — 2024-05-27
- 2.4.0 — 2023-12-13
- 2.3.0 — 2023-11-20
- 2.2.0 — 2023-02-20
- 2.1.2 — 2023-02-09
- 2.1.1 — 2023-02-09
- 2.1.0 — 2023-02-08
- 2.0.1 — 2023-02-08
- 2.0.0 — 2023-02-04
- … 3 more at https://npm.io/package/tiny-parse-argv/versions

## README

# Tiny Parse Argv

A tiny function for parsing `process.argv`, a modern rewrite of [`minimist`](https://github.com/minimistjs/minimist).

## Features

The following features are provided:

- Built-in TypeScript types, and pretty clean and understandable code.
- Single/multiple implicit/explicit shorthand flags: `-f`, `-f some`, `-f 123`, `-f123`, `-abc`, `-abc 123`, `-abc123`, `-f some -f other`.
- Single/multiple implicit/explicit longhand flags: `--foo`, `--foo some`, `--foo 123`, `--foo=123`, `--foo=some`, `--foo some --foo other`.
- Explicitly negated flags are `false` by default: `--no-foo`, `--no-bar`.
- Eager flags consume multiple consecutive values: `-f one two three`, `--foo one two three`.
- Arguments: `./app.sh with some list of arguments`.
- Values that would be interpreted as numbers if they were JavaScript are coerced to numbers automatically.
- Flags that could lead to prototype pollution issues are safely ignored.
- `options.boolean`: the value for the listed flags will always be coerced to a boolean.
- `options.integer`: the value for the listed flags will always be coerced to a integer.
- `options.number`: the value for the listed flags will always be coerced to a number.
- `options.string`: the value for the listed flags will always be coerced to a string.
- `options.eager`: the listed flags are considered to be eager, and will consume multiple consecutive non-flag values.
- `options.unary`: the listed flags are considered to be unary, and if multiple values are provided only the last one will be considered.
- `options.variadic`: the listed flags are considered to be variadic, and their value, if present, will always be an array.
- `options.required`: the listed flags are considered to be required, if some are missing `options.onMissing` will be called.
- `options.alias`: if any aliased flag is assigned then all the aliases for it will be assigned too, automatically.
- `options.default`: an object containing default values, which will be used if not overridded by the `argv` array.
- `options.incompatible`: an object mapping flags with other flags they are incompatible with.
- `options.validators`: an object mapping flags to custom validation functions for them, returning a boolean.
- `options.onIncompatible`: a function that will be called if any pairs of flags that are incompatible with each other is detected.
- `options.onInvalid`: a function that will be called if any of the provided flags have an invalid value, e.g. a boolean value for a string flag.
- `options.onMissing`: a function that will be called if any of the required flags is missing. If a default value is provided for a flag it won't be considered as missing.
- `options.onUnknown`: a function that will be called if any of the flags are unknown, i.e. not listed as either a boolean, a string, or an alias. If a default value is provided for a flag it won't be considered as unknown.
- `--`: a special flag that stops parsing, everything after it will be copied, untouched, into the `--` property of the return object.

## Differences with `minimist`

The following differences exist compared to `minimist`:

- `option['--']` set to `false` is not supported, it's as if it's always set to `true`.
- `option.boolean` set to `true` is not supported, you should always explicitly list all your supported boolean flags instead.
- `option.boolean` set to a single string is not supported, always provide an array of flags instead.
- `option.string` set to a single string is not supported, always provide an array of flags instead.
- `option.alias` mapping to a single string is not supported, always provide an array of aliases instead.
- `option.stopEarly` is not supported, it's as if it's always set to `false`.
- Dotted flags are not supported, so their paths will not be expanded, you can use [`path-prop`](https://github.com/fabiospampinato/path-prop)'s `unflat` function for that.

Other than that it should work pretty much identically, since we are basically using the same tests.

## Install

```sh
npm install tiny-parse-argv
```

## Usage

```ts
import parseArgv from 'tiny-parse-argv';

// Let's parse some arguments

parseArgv ([ '-f', '--foo', 'some', 'argument', '--', '--app-flag' ]);
// => { f: true, foo: 'some', _: ['argument'], '--': ['--app-flag'] }
```

## License

MIT © Fabio Spampinato

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