@rasch/argv
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

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

npm install @rasch/argv
yarn

yarn add @rasch/argv

license

0BSD

Package Sidebar

Install

npm i @rasch/argv

Weekly Downloads

1

Version

0.1.2

License

0BSD

Unpacked Size

7.24 kB

Total Files

5

Last publish

Collaborators

  • rasch