Skip to Content
Nextra 4.0 is released 🎉

Welcome to tsargp

Get started with:

Argument parser for TypeScript. -h, --help A help option. Prints this help message. Uses the next argument as the name of a subcommand. Uses the remaining arguments as option filter. -v, --version A version option. Prints the package version. -f, --no-flag A flag option. Deprecated for some reason. hello ... A subcommand. Logs the arguments passed after it. -b, --boolean <param> A boolean option with: * a paragraph - inline styles 1. and a list Values must be one of {'yes', 'no'}. Reads environment data from BOOLEAN. Requires (-sc or (-sa == ['a', 'b'] and -na != [1, 2])). Defaults to false. String options: -sr, --strRegex <my str> A string option. Can be clustered with 's'. Values must match the regex /^\d+$/. Defaults to '123456789'. -sc, --strChoice 'one' A string option. Disallows inline parameters. Values must be one of {'one', 'two'}. -sa, --strArray [<param>...] A string array option. Accepts multiple parameters. Values can be delimited with ','. Defaults to ['one']. --strArrayLimit ['one'...] A string array option. Accepts multiple parameters. Accepts positional arguments that may be preceded by --. Element count is limited to 3. Number options: -nr, --numRange <my num> A number option. The minimum accepted value is -2. Can be clustered with 'n'. Defaults to -1.23. -nc, --numChoice =1 A number option. Requires inline parameters. Values must be one of {'1', '2'}. -na, --numArray [<param>...] A number array option. Accepts multiple parameters. Defaults to [1, 2]. --numArrayUnique ['1,2'...] A number array option. Accepts multiple parameters. Values can be delimited with ','. Can be specified multiple times. Duplicate values will be removed. Usage: demo.js [(-h|--help)] [(-v|--version)] # get help demo.js hello ... # execute the hello command demo.js [(-f|--no-flag)] [[(-b|--boolean) <param>] (-sc|--strChoice) 'one'] [(-sr|--strRegex) <my str>] [(-nr|--numRange) <my num>] [(-nc|--numChoice)=1] [(-sa|--strArray) [<param>...]] [(-na|--numArray) [<param>...]] [[(--strArrayLimit|--)] ['one'...]] [--numArrayUnique ['1,2'...]] MIT License. Copyright (c) 2024-2025 Diego Sogari Report a bug: https://github.com/dsogari/tsargp/issues

“Several of them would have protested if they could have found the right arguments.”

— George Orwell, Animal Farm

Last updated on