0.1.1 • Published 1 year ago

@rasch/argv v0.1.1

Weekly downloads
-
License
0BSD
Repository
-
Last release
1 year ago

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/argv
npm install @rasch/argv
yarn add @rasch/argv

license

0BSD

0.1.1

1 year ago

0.1.0

1 year ago