@maboiteaspam/set-verbosity

Set process.env[DEBUG] given process.argv

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
@maboiteaspam/set-verbosity
Minified + gzip package size for @maboiteaspam/set-verbosity in KB

Readme

set-verbosity

Set process.env[DEBUG] given process.argv

Install

npm i @maboiteaspam/set-verbosity --save

Usage

process.argv

Using the node process.argv value

var debug = require('@maboiteaspam/set-verbosity')('module-name', process.argv);
// or var debug = require('@maboiteaspam/set-verbosity')
//    .raw('module-name', process.argv.join(' '));

debug('hello')

Which then, can be invoked in such fashion

module-name -v
module-name --verbose
module-name -v module-name
module-name --verbose module-name,tomate,set-verbosity

minimist

Using minimist module to pre parse values

var argv  = require('minimist')(process.argv.slice(2));
var debug = require('@maboiteaspam/set-verbosity')('module-name', argv.v || argv.verbose);
// or var debug = require('@maboiteaspam/set-verbosity')
//  .parsed('module-name', argv.v || argv.verbose);

debug('hello')

Which then, can be invoked in such fashion

module-name -v
module-name --verbose
module-name -v module-name
module-name --verbose module-name,tomate,set-verbosity

debug object

This module returns instances of debug module

var debug = require('@maboiteaspam/set-verbosity')('module-name', process.argv);

debug('hello')

Which then, can be invoked in such fashion

module-name -v
module-name --verbose
module-name -v module-name
module-name --verbose module-name,tomate,set-verbosity

Api

setVerbosity

setVerbosity is a function object with two additional methods raw, parsed.

  • setVerbosity(string name, object arg) debug

When typeof(arg) is object, returns setVerbosity.raw(name, arg)

  • setVerbosity(string name, string arg) debug

When typeof(arg) is string, returns setVerbosity.parsed(name, arg)

  • setVerbosity(string name, bool arg) debug

When typeof(arg) is bool, returns setVerbosity.parsed(name, arg)

setVerbosity.parsed

  • setVerbosity.parsed(string name, string verboseModules)

Set process.env['DEBUG'] to verboseModules.

  • setVerbosity.parsed(string name, bool verbose) debug

Set process.env['DEBUG'] to name.

setVerbosity.raw

  • setVerbosity.raw(string name, string argv) debug

Parse argv to extract -v || --verbose (verboseModules)?. Set process.env['DEBUG'] to verboseModules or name.

  • setVerbosity.raw(string name, bool verbose) debug

Set process.env['DEBUG'] to name.

Examples

var debug = require('@maboiteaspam/set-verbosity')('module-name', process.argv);
var debug = require('@maboiteaspam/set-verbosity').raw('module-name', process.argv);

var argv  = require('minimist')(process.argv.slice(2));
var debug = require('@maboiteaspam/set-verbosity')('module-name', argv.v || argv.verbose);
var debug = require('@maboiteaspam/set-verbosity').parsed('module-name', argv.v || argv.verbose);

More

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.