JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 59
  • Score
    100M100P100Q47318F
  • License MIT

simpler debug utility

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 progressed.io

build NPM version


simple debug utility

example

'use strict';

var debug = require('utils-debug')(__filename);

debug('hey there');

someMethod();

function someMethod(){
  debug('simple and easy');
  debug('debug');
  otherMethod();
}

function otherMethod(){
  debug('with useful information');
  yetAnother();
}

function yetAnother(){
  debug('just like...');
  debug('... you had imagined');
}

use filenames instead of mnemonics

utils-debug (master)DEBUG=example node example
at Object.<anonymous> (example.js:5:9)
 hey there
at someMethod (example.js:10:11)
 simple and easy
 debug
at otherMethod (example.js:16:11)
 with useful information
at yetAnother (example.js:21:11)
 just like...
 ... you had imagined

filter by method name

utils-debug (master)DEBUG=*#someMethod#yetAnother node example.js
someMethod (example.js:10:3)
 simple and easy
 debug
yetAnother (example.js:21:3)
 just like...
 ... you had imagined

documentation

var debug = require('utils-debug')([__filename]);

debug('hey there');

Thats basically it. Passing the __filename is optional.

path filter

To enable the debug functions that live in your files use their relative path.

That is, if you project looks like below

project-dir
 |-lib
   |--> code.js
 |-index.js

and want to debug lib/code.js you simply write

DEBUG=lib/code.js node index.js

or

DEBUG=lib/code node index.js 

So yes, the extension is not necessary.

To debug more than one file separate them with commas like so

DEBUG=lib/code,index node index.js

And use the Tab of your keyboard, is very handy to fill up those paths.

function filter

Method names can also be used to enable their output

utils-debug (master)DEBUG=*#someMethod#yetAnother node example.js
someMethod (example.js:10:3)
 simple and easy
 debug
yetAnother (example.js:21:3)
 just like...
 ... you had imagined

As you can see above, the wildcard * was used followed of '#'.

The only difference for this filter is that you have to separate methods with '#' instead of a comma.

wildcards

At the moment the only wildcard is *. This enables debugging for every file if nothing else is specified (see method-filter).

DEBUG=* node index.js 

There are plans to add glob matching as well.

why

You want expressive, unintrusive debugging.

todo

  • aliasing
  • glob matching
  • make some tests
  • be able to format the output

license

LICENSE