A flexible and powerful command line argument parser, powered by Funish.
- 🚀 Simple and intuitive API
- 💪 Supports both long and short options
- 🎯 Automatic type conversion (numbers, booleans)
- 🔄 Option aliases support
- ⚙️ Default values configuration
- 🔧 Multiple parsing strategies (regexp or split)
- 📦 Zero dependencies
- 🌟 TypeScript support
# npm
$ npm install @funish/argv
# yarn
$ yarn add @funish/argv
# pnpm
$ pnpm add @funish/argvimport { parseArgv } from "@funish/argv";
const args = parseArgv([
"-b",
"--bool",
"--no-meep",
"--multi=baz",
"--foo",
"bar",
]);
// => { _: [], b: true, bool: true, meep: false, multi: "baz", foo: "bar" }const args = parseArgv(["--port", "3000"], {
alias: { p: "port" },
default: { port: 8080 },
});
// => { _: [], port: 3000, p: 3000 }// Using regexp parser
const args1 = parseArgv(["--name=value"], { parser: "regexp" });
// Using split parser (default)
const args2 = parseArgv(["--name", "value"], { parser: "split" });- Long options with values:
--name=valueor--name value - Long boolean flags:
--flag - Negated flags:
--no-flag - Short options with values:
-n=valueor-n value - Short boolean flags:
-f - Multiple short flags:
-abc(equivalent to-a -b -c) - Positional arguments:
command arg1 arg2
Main function to parse command line arguments.
argv(string[]): Array of command line arguments to parseoptions(object, optional):alias(object): Map of option aliases (e.g.,{ p: 'port' })default(object): Default values for optionsparser('split' | 'regexp'): Parser to use (default: 'split')
Returns an object containing:
_: Array of positional arguments- Named properties for each option with their parsed values
Please read our Contributing Guide before submitting a Pull Request to the project.