UNPKG

713 BJavaScriptView Raw
1var utils = require('./utils');
2var debug = require('debug');
3
4/**
5 * @description Create a debug instance based on your package.json alias/name.
6 *
7 * The challenge here is to figure out where your package.json exist.
8 *
9 * @param {String} name - Name of the debug unit.
10 * @return {Function}
11 */
12module.exports = function initDebug(name) {
13 var parentPath = utils.getCallerRoot();
14 var alias, pkg;
15
16 try {
17 pkg = require(parentPath + '/package.json');
18
19 if (pkg.alias) {
20 alias = pkg.alias;
21 } else {
22 alias = pkg.name;
23 }
24
25 } catch (err) {
26 alias = 'undefined';
27 }
28
29 return debug(alias + ':' + name);
30};
31
32module.exports._base = debug;