0.1.2 • Published 11 months ago
@rasch/argv v0.1.2
argv
a command-line argument parser for ECMAScript CLI applications
This argv module accepts an array of strings containing the command line
arguments and reduces them to an object of key-value pairs. Any arguments that
don't have an option associated with them are appended to an array on the _
(underscore) key. Arguments appearing after "--" are also appended to the array
on the _ key. Negated arguments such as, --no-opt will set opt: false on
the argv object. All of the values in the argv object are strings or
booleans.
// example.js
import { argv } from "@rasch/argv"
console.log(argv(process.argv.slice(2)))node example.js serve -v 3 -xyz --host=127.0.0.1 -p80 --no-debug -q{
_: ["serve"],
v: "3",
x: true,
y: true,
z: true,
host: "127.0.0.1"
p: "80",
debug: false,
q: true,
}Additional usage examples are available in the unit tests.
install
pnpm add @rasch/argvnpm install @rasch/argvyarn add @rasch/argv