get-args

2.0.0 • Public • Published

get-args

npm npm npm

Light arguments parser for Node.js

Installation

You can install get-args using NPM:

$ npm install --save get-args

Usage

var getArgs = require("get-args");

arg = getArgs(args)

Returns an object with the result of parsing the array of arguments args. If no array is provided, this will parse the command line arguments passed when the Node.js process was launched, extracted from process.argv.

The output object will have the following keys:

  • arguments: an array with all the arguments that did not have an option associated with it.
  • options: an object with all the single and double hyphened arguments.
var getArgs = require("get-args");
 
//Parse a
console.log(getArgs(["run", "--file", "/path/to/file.txt", "-x", "5"]));
// { arguments: [ 'run' ],
//   options: { file: '/path/to/file.txt', x: '5' } }

Run example

There is a script called example.js to test how this module works.

$ node example.js foo bar -i 5 -jkw -y 10 --message "Hello world"
{ arguments: [ 'foo''bar' ],
  options:
   { i: '5',
     j: true,
     k: true,
     w: true,
     y: '10',
     message: 'Hello world' } }

Limitations

  • get-args can't parse arguments with the format --foo=bar.

If you implement a solution that solves anyone of the limitations listed before, feel free to submit your PR.

License

MIT © Josemi Juanes.

Package Sidebar

Install

npm i get-args

Weekly Downloads

2

Version

2.0.0

License

MIT

Unpacked Size

5.6 kB

Total Files

5

Last publish

Collaborators

  • jmjuanes