Socket
Socket
Sign inDemoInstall

dbug

Package Overview
Dependencies
0
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.1.1

53

lib/dbug.js

@@ -7,21 +7,38 @@ /* This Source Code Form is subject to the terms of the Mozilla Public

const names = [];
const skips = [];
const colors = [6, 2, 3, 4, 5, 1];
var prevColor = 0;
var useColor = tty.isatty(2) || process.env.DEBUG_COLOR;
(process.env.DEBUG || '')
.split(/[\s,]+/)
.forEach(function(name){
name = name.replace('*', '.*?');
if (name[0] === '-') {
skips.push(new RegExp('^' + name.substr(1) + '$'));
} else {
names.push(new RegExp('^' + name + '(:.+)?$'));
}
});
function envDebugColor() {
try {
return !!JSON.parse(process.env.DEBUG_COLOR);
} catch (ex) {
return false;
}
}
function environ() {
var useColor = process.env.DEBUG_COLOR ? envDebugColor() : tty.isatty(2);
var names = [];
var skips = [];
if (process.env.DEBUG) {
process.env.DEBUG
.split(/[\s,]+/)
.forEach(function(name){
name = name.replace('*', '.*?');
if (name[0] === '-') {
skips.push(new RegExp('^' + name.substr(1) + '$'));
} else {
names.push(new RegExp('^' + name + '(:.+)?$'));
}
});
}
return {
names: names,
skips: skips,
useColor: useColor
};
}
function color() {

@@ -50,3 +67,3 @@ return colors[prevColor++ % colors.length];

function enable(name) {
function enable(name, useColor) {
var c;

@@ -79,2 +96,3 @@ var format = useColor ? function colored(level, text) {

dbug.enabled = true;
dbug[format.name] = true;
dbug.log = logAt('log');

@@ -90,3 +108,4 @@ dbug.debug = dbug.log;

module.exports = function dbug(name) {
var match = skips.some(function(re){
var env = environ();
var match = env.skips.some(function(re){
return re.test(name);

@@ -99,3 +118,3 @@ });

match = names.some(function(re){
match = env.names.some(function(re){
return re.test(name);

@@ -109,3 +128,3 @@ });

return enable(name);
return enable(name, env.useColor);
};
{
"name": "dbug",
"version": "0.1.0",
"version": "0.1.1",
"description": "debug improvements",

@@ -5,0 +5,0 @@ "main": "./lib/dbug.js",

@@ -56,2 +56,8 @@ /* This Source Code Form is subject to the terms of the Mozilla Public

assert(!food.enabled);
},
'should check process.env every time': function() {
process.env.DEBUG = 'derp';
assert(require('../')('derp').enabled);
process.env.DEBUG = 'foo';
assert(!require('../')('derp:herp').enabled);
}

@@ -97,4 +103,3 @@ },

process.stderr.write = err;
},
}
},

@@ -127,2 +132,12 @@ 'disabled': {

'color': {
'should default to colored on tty': function() {
assert.equal(foo.colored, require('tty').isatty(2));
},
'should look for DEBUG_COLOR to override tty': function() {
process.env.DEBUG_COLOR = false;
assert(require('../')('foo').plain);
}
},
'after': function() {

@@ -129,0 +144,0 @@ //console._stdout = process.stdout;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc