Giter Site home page Giter Site logo

unknownmoon / utility-node-opts-parser Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 514 KB

[usable, not-being-maintained] Parse the opts feeding from environment variables or arguments. Won't handle `--test-opt="value"` case.

License: ISC License

JavaScript 100.00%

utility-node-opts-parser's Introduction

utility-node-opts-parser

Note that this project is still in preview stage

GitHub version Dependency Status devDependency Status

Master Develop
Build Status Master Build Status Develop
codecov codecov

Parse the opts feeding from environment variables or arguments.

Supported cases:

  1. Short/long named options is set/unset
  2. 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

Usage

Install from GitHub Repository

# 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

APIs

Reference to the JSDoc. Generate JSDoc Documentation

Examples

  1. 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');
  2. 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');
  3. 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');
  4. Has options APIs hasOpts, hasOptsInEnv, hasOptsInArgv are following the save pattern, but return true/false

Development

Initialisation

# Have Node ^6.0.0 & NPM ^3.8.6 installed

# install dependencies
npm install

Clean Up

# remove the built code, for now only the test result 
npm run clean

# remove the built code and node modules
npm run reset

Test

Coverage report can be found in ./coverage folder.

npm test

Build

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 JSDoc Documentation

# 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

Release

Shorthand script to generate release content, including ./coverage, ./jsdoc and ./dist.

npm run release

utility-node-opts-parser's People

Contributors

unknownmoon avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.