Package Exports
- utils-debug
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (utils-debug) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
utils-debug 

documentation -
install -
tests
todo -
why
unobtrusive debug utility
example
var debug = require('utils-debug')();
debug('hey there');
fn1();
function fn1(){
debug('%s', 'simple');
debug('and easy');
debug('debug');
fn2();
}
function fn2(){
debug('if you need it');
fn3();
}
function fn3(){
debug('just like...');
debug('... you had imagined');
}use filenames instead of mnemonics
$ DEBUG=example.js node example.js
at Object.<anonymous> (example.js:5:1)
hey there
at fn1 (example.js:10:3)
simple
and easy
debug
at fn2 (example.js:18:3)
if you need it
at fn3 (example.js:23:3)
just like...
... you had imaginedfilter by function name
$ DEBUG=*#fn1#fn2 node example.js
fn1 (example.js:10:3)
simple and easy debug
fn2 (example.js:21:3)
just like...
... you had imagineddocumentation
var Debug = require('utils-debug');The module exports a function factory.
function Debug(/* no arguments */)It returns a noop (empty function) when no flags given (no process.env.DEBUG)
or the file is not included on the process.env.DEBUG flag.
returns
noop(empty function) if there was noprocess.env.DEBUGnoopif the file did not pass the checks given by the flagsdebugfunction that uses the same format asconsole.log
var Debug = require('utils-debug');
var debug = Debug();
debug('hey there'); fn();
function fn(){
debug('%s', 'simple stuff');
}filters
To enable debug functions that live in your code there are three types of filters.
paths separated by comma
$ DEBUG=lib/dir/,lib/file1,lib/file2.js node program.jsThe extension is optional. If a path ends with slash (forward or backward) it will be considered a directory.
NOTE: paths have to be relative to the CWD
function names starting with a pound sign
$ DEBUG=*#method1#method2 node program.jswilcards
DEBUG=*will match any file(s)DEBUG=folder/*/*any file one dir deep afterfolderDEBUG=folder/*/file.jsmatches any directory afterfolder1 folder deepDEBUG=folder/**any file after directoryfolderwith any folder depthDEBUG=folder/**/file.jsany file after directoryfolderwith any folder depth that ends up onfile.js
why
You want expressive, unobtrusive debugging.
install
With npm
$ npm install utils-debugtests
To run the tests
$ npm test output
filter
✓ resolves filepaths from CWD
✓ files should not need extension
✓ files should be separated by comma
✓ DEBUG=* makes util.filter.star = true
✓ DEBUG=folder/ or would be treated as file
✓ DEBUG=folder/* does not qualify as *
✓ DEBUG=folder/*#method is labeled as fn flag
✓ DEBU=folder/*#method1#method2 to filter more than one
skipFile
✓ * does not skip any files
✓ folder/file.js skips any other file
✓ folder/*/file.js is wilcard for only one folder deep
✓ folder/*/file.js skips any other files
✓ folder/**/file.js is wilcard for any one folder depth
✓ folder/**/file.js skips any other files
14 passing (34ms)todo
- aliasing (to use it instead of filename)
- glob matching