Registry / http-networking / parameter-reducers

parameter-reducers

JSON →
library2.1.0jsnpmunverified

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-reducers
INSTALL
IMPORT
SIG · PARAMETER-REDUCERS
P
parameter-reducers
http-networkingjavascriptv2.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

startChain
import { startChain } from 'parameter-reducers';
const { startChain } = require('parameter-reducers');
Preferred modern ESM import. CommonJS `require` might work if your environment is correctly configured, but ESM is recommended and shown in examples.
param
import { param } from 'parameter-reducers';
import param from 'parameter-reducers';
`param` is a named export containing utility methods (e.g., `param.string`, `param.flag`), not a default export.
parse
import { parse } from 'parameter-reducers';
import parse from 'parameter-reducers';
`parse` is a named export for initiating the parsing process against a parameter chain.

Demonstrates basic CLI argument parsing for help flags, strings, and integers, including default values and help text output for a simple 'repeat' command.

import {startChain, param, parse} from 'parameter-reducers'; const params = startChain() .addParam(param.flag(['-h', '--help'], 'help')) .addParam(param.string(['-m', '--message'], 'message')) .addParam(param.integer(['-c', '--count'], 'count')); const {help = false, message = 'hello world', count = 1} = parse( params, process.argv.slice(2), ).extract(); if (help) { console.log(`Usage: repeat -m "My Message" -c 10\n\nparameters:\n\n-h --help Print this help\n-m --message The message to print\n-c --count How many times to print the message`); } for (let i = 0; i < count; i++) { console.log(message); } // Example execution: node your-script.ts -m "Hello CLI" -c 3
Debug
Known issues
breakingIn version 2.0.0, the order of precedence for parameters was reversed. If you previously defined a parameter twice (e.g., a string and then a flag with the same name), the last defined parameter now takes precedence, whereas previously it was the first. This can change the effective type and value of parameters.
fix
Review and reorder parameter definitions in `startChain().addParam(...)` calls to ensure the desired precedence. The parameter added last in the chain now wins.
affects: >=2.0.0
gotchaThe `parse()` function returns an object that can represent either a valid parsing result or an error. Users must explicitly check `parseResult.valid` and `parseResult.rest.length` to ensure all arguments were parsed successfully and without errors. Failing to do so can lead to silent errors or incorrect processing of unhandled arguments.
fix
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.
affects: >=1.0.0
gotchaDefault values for parameters are not set within the `param` definition itself. Instead, they are applied through JavaScript's object destructuring assignment when extracting the parsed results.
fix
When destructuring the parsed object, provide default values like `const { help = false, message = 'hello world' } = parsedResult.extract();`.
affects: >=1.0.0
gotchaThe library explicitly does not provide built-in functionality for generating help documentation for your CLI. Developers are expected to manage and render help text manually.
fix
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.
affects: >=1.0.0
Errors
Common errors & fixes
🚨 Unrecognized option --some-unexpected-flag.
The CLI was invoked with an option or argument that was not defined in the parameter chain, and the `parseResult.rest` array was not properly handled or `extract()` was not used.
fix
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.
TypeError: Cannot read properties of undefined (reading 'message')
Attempting to access a parsed parameter (e.g., `message`) that was not provided on the command line, and no default value was assigned during destructuring.
fix
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.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
26 hits · last 30 days
node
22
OpenAI (training)
1
Resources
parameter-reducers — npm install parameter-reducers · libregistry