A simple and reliable Node.js command-line arguments parser
npm install parse-argsvA simple Node.js command-line arguments parser.
Note #1 This module can be used with any existing version of node.js and npm.
By using npmjs.org:
npm install parse-argsv --global --save
npm install parse-argsv --save
parse-argsv module installed:``js
'use strict'
var ArgsParser = require('parse-argsv');
var argsv = new ArgsParser();
// Retrieve an array of command-line arguments and its values
console.log("\nCommand line arguments: " + JSON.stringify(argsv.parseArgs("=")));
// Get value of a single command-line argument by its name
console.log("\nParam: { \"hello\" } Value: {\"" + argsv.getParam("hello") + "\"}");
console.log("\nParam: { \"oops\" } Value: {\"" + argsv.getParam("oops") + "\"}");
// Verify if a command-line argument exists
console.log("\nParam: { \"grand\" } Is Set: {\"" + argsv.isSet("grand") + "\"}");
`
.ArgvParser
#####.ArgvParser()
ArgvParser - constructs a command-line arguments parser object,
##### .parseArgs( delimiter = 0 )
parses the command-line and returns an associative array of arguments and its values separated by a delimiter.
Warning: The using of all other ArgvParser object's methods is only possible after calling parseArgs method.
##### .getParam( param )
returns a value of an argument with a specific param name. If an argument with the given name does not exists, {Not_Found}
this method will return , and {Not_Set}, in case when the value of an argument is missing.
##### .isSet( param )
performs a verification whether a value of an argument with the given name is set. This method can only be used when
the command-line contains at least one argument which pair of its name and value are separated by the delimiter (e.g. mode='open').true
This method returns if the value of an argument is set and false` unless otherwise.
That's All Folks :)
Arthur V. Ratz @ Epsilon Software Development Labs.