parameter-reducers is a JavaScript/TypeScript library designed for building robust and type-safe command-line interface (CLI) parameter parsers. Its current stable version is 2.1.0, and it appears to follow an active development cadence with recent feature additions and a significant breaking change in version 2.0.0. A key differentiator is its immutable, reducer-based chain API, which allows for flexible composition and reuse of parameter definitions. This approach facilitates highly customizable parsing logic while leveraging TypeScript to provide strong type guarantees for parsed arguments, reducing runtime errors associated with CLI argument processing. It focuses on core parsing capabilities, intentionally leaving documentation generation to user-defined template literals.
npm install parameter-reducersVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic CLI argument parsing for help flags, strings, and integers, including default values and help text output for a simple 'repeat' command.
Review and reorder parameter definitions in `startChain().addParam(...)` calls to ensure the desired precedence. The parameter added last in the chain now wins.
Always check `if (!parseResult.valid)` and `if (parseResult.rest.length)` manually. Alternatively, use `parseResult.extract()` which handles these checks, logs errors, and exits the process if parsing fails or unrecognized options are present.
When destructuring the parsed object, provide default values like `const { help = false, message = 'hello world' } = parsedResult.extract();`.Utilize template literals or other string formatting methods within your application logic (e.g., when a `--help` flag is present) to construct and display usage information and parameter descriptions.
Ensure all possible CLI arguments are covered by `addParam` calls in your chain. If unexpected arguments are acceptable, explicitly check `parseResult.rest.length` after parsing and decide how to handle them. Using `parseResult.extract()` will automatically detect and report unrecognized options.
Provide a default value when destructuring the parsed parameters, e.g., `const { message = 'default value' } = parse(...).extract();`. Alternatively, ensure the parameter is always present in CLI invocations or add validation checks.No dependency data recorded yet.