@ideadesignmedia/arguments.js
v1.0.2
Published
A minimal, zero-dependency helper that turns Node.js command-line arguments in `key=value` form into a plain object. It is designed for simple tooling scripts where a full-featured parser would be overkill.
Readme
@ideadesignmedia/arguments.js
A minimal, zero-dependency helper that turns Node.js command-line arguments in key=value form into a plain object. It is designed for simple tooling scripts where a full-featured parser would be overkill.
Installation
npm install @ideadesignmedia/arguments.jsQuick start
// cli.js
const args = require('@ideadesignmedia/arguments.js');
console.log(args.environment);
console.log(args.debug);Run your script by passing key=value arguments after the script name:
node cli.js environment=production debug=trueOutput:
production
trueHow it works
- Reads from
process.argvstarting at index 2 (the arguments after your script name). - Splits each argument on the first
=into a key and value. - Stores the result in an object where each key maps to a string value (or
undefinedif no value is provided). - Later instances of the same key overwrite earlier ones.
Because the parser does not coerce or validate values, anything after = is kept as-is. Arguments without = (for example --flag) become keys whose value is undefined.
TypeScript support
The package ships with a Record<string, string | undefined> definition, making it straightforward to use with TypeScript without additional configuration.
License
MIT
