parse-argsv

0.9.18 • Public • Published

ArgvParser

A simple Node.js command-line arguments parser.

Note #1 This module can be used with any existing version of node.js and npm.

How to install the module:

By using npmjs.org:

 npm install parse-argsv --global --save 

 npm install parse-argsv --save 

How to use the parse-argsv module installed:

Parsing Node.js command-line arguments

 
'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") + "\"}");
 

Constructor

.ArgvParser

.ArgvParser()

ArgvParser - constructs a command-line arguments parser object,

Methods

.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, this method will return {Not_Found}, 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'). This method returns true if the value of an argument is set and false unless otherwise.

Conclusion

That's All Folks :)

Author

Arthur V. Ratz @ Epsilon Software Development Labs.

Package Sidebar

Install

npm i parse-argsv

Weekly Downloads

0

Version

0.9.18

License

CPOL

Unpacked Size

4.79 kB

Total Files

4

Last publish

Collaborators

  • epsilon_dev