JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 120
  • Score
    100M100P100Q74331F

object to parse commandline-args and options.

Package Exports

  • argparser

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (argparser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

argparser v0.0.8

[Node.js] parse commandline-args and options

Change Log


  • [0.0.2]: modify getter methods
  • [0.0.3]: enable method chaining
  • [0.0.4]: copy process.argv
  • [0.0.5]: get string expression of command with stringify()
  • [0.0.6]: exclude null or false in ArgParser.getOptionString(obj)

Overview

Installation

git clone git://github.com/shinout/argparser.git

OR

npm install argparser

Usage

const ArgParser = require('argparser');

/* the simplest use */
/* node hoge.js --long-var -s foo bar  */
var parser = new ArgParser().parse();
parser.getArgs(); // [foo, var]
parser.getOptions(); // {long-var: true, s: true}
parser.getOptions('long-var'); // true


/* set options with value */
/* node hoge.js piyo foo -h --var-with-val 392 bar  */
var parser = new ArgParser();
parser.addValueOptions(['var-with-val']);
parser.parse();
parser.getArgs(); // [piyo, foo, var]
parser.getOptions(); // {h: true, var-with-val: 392}


/* parse array */
var parser = new ArgParser();
parser.addValueOptions(['encoding', 'm', 'aaa']);
parser.parse(['-m', 110, '--encoding', 'utf-8', 'index.html']);
parser.getArgs(); // [index.html]
parser.getOptions(); // {encoding: utf-8, m: 100, aaa: false}


/* set non-value options */
parser.addOptions(['-h', '-t']);
parser.addValueOptions(['encoding', 'e', 'm']);
parser.parse(['-h', 'hoge', '--encoding', 'utf-8', 'index.html']);
parser.getArgs(); // [hoge, index.html]
parser.getOptions(); // {h: true, encoding: utf-8, m: false}
parser.getOptions('e'); // false
parser.getOptions('encoding'); // utf-8
parser.getOptions('encoding', 'e'); // utf-8
parser.getOptions('e', 'encoding'); // utf-8