README
womit
Util to extract configs out of environment variables or arguments
Travis">

Introduction
womit is a util method to extract config parameters out of environment variables oder CLI arguments; thereby environments are preferred. Just call the method, pass in the key and get the respective config.
womit is the German translation for whereby.
This plugin is implemented in ECMAScript 6 without any transpilers like babel
.
Additionally standard
and ava
are used to grant a high quality implementation.
Installation
For installation use the Node Package Manager:
$ npm install --save womit
or clone the repository:
$ git clone https://github.com/felixheck/womit
Alternatively use the Yarn Package Manager:
$ yarn add womit
Usage
Import
First you have to import the module:
const womit = require('womit');
Request Config
Afterwards call the method with passed keys
to identify the respective key/value pair:
const [ port = 1337 ] = womit('port')
Alternatively it is possible to pass in multiple keys to get a list of config values.
This enables to define easily default values.
The list to be returned contains the values in the correlating order:
const [ port = 1337, tag = 'api' ] = womit('port', 'tag')
As mentioned before, environment variables are preferred.
Following some examples with corresponding return value:
PORT=8080 node example.js
:8080
node example.js --port 3000
:3000
PORT=8080 node example.js --port 3000
:8080
API
womit(key1[, key2[, ...]]) {Array.<*>}
keyX {string}
- key to identity the respective key/value pair. Must becamelCase
,UpperCamelCase
orsnake_case
.
Hint: environment variables must be UPPER_SNAKE_CASE
, argv lower-kebab-case
.
Hint: Using the argv definition enables to use numbers. Environment variable are parsed into strings.
Developing and Testing
First you have to install all dependencies:
$ npm install
To execute all unit tests once, use:
$ npm test
or to run tests based on file watcher, use:
$ npm start
To get information about the test coverage, use:
$ npm run coverage
Contribution
Fork this repository and push in your ideas.
Do not forget to add corresponding tests to keep up 100% test coverage.
License
The MIT License
Copyright (c) 2017 Felix Heck
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.