Note that this project is still in preview stage
Master | Develop |
---|---|
Parse the opts feeding from environment variables or arguments.
Supported cases:
- Short/long named options is set/unset
- Short/long named options with value
Won't handle --test-opt="value"
(delimiter) case, which using =
in the middle of the option name and value.
Supporting NodeJS 6 and above. Basic unit test powered by Mocha/Chai/Sinon;
Table of Contents
# command format
npm install --save github:unknownmoon/utility-node-opts-parser#<version>
# example
npm i -S github:unknownmoon/utility-node-opts-parser#v0.0.4
Reference to the JSDoc. Generate JSDoc Documentation
-
Get options values from environment variables
// import functions from the module. import { getOptsFromArgv } from 'utility-node-opts-parser'; let opts = getOptsFromArgv(...['OPT1', 'OPT2']); // value of OPT1 opts.get('OPT1'); // value of OPT2 opts.get('OPT2');
-
Get options values from arguments
// import functions from the module. import { getOptsFromEnv } from 'utility-node-opts-parser'; let opts = getOptsFromEnv(...['OPT1', 'OPT2']); // value of OPT1 opts.get('OPT1'); // value of OPT2 opts.get('OPT2');
-
Get options values from either environment variables or arguments
// import functions from the module. import { getOpts } from 'utility-node-opts-parser'; let opts = getOpts(...['OPT1', 'OPT2']); // value of OPT1 opts.get('OPT1'); // value of OPT2 opts.get('OPT2');
-
Has options APIs
hasOpts
,hasOptsInEnv
,hasOptsInArgv
are following the save pattern, but returntrue
/false
# Have Node ^6.0.0 & NPM ^3.8.6 installed
# install dependencies
npm install
# remove the built code, for now only the test result
npm run clean
# remove the built code and node modules
npm run reset
Coverage report can be found in ./coverage
folder.
npm test
The source code is written in ES2015, hence before NodeJS fully support ES2015, we need to build the code to es2015-node
using Babel.
The built code can be found in ./dist
folder.
npm run build
# generate the documentation
npm run doc
# serve the generated documentation using `http-server`
# note that no watch functionality is hooked, hence
# changing code won't trigger documentation regeneration.
npm run serve-doc
Shorthand script to generate release content, including ./coverage
, ./jsdoc
and ./dist
.
npm run release