Skip to content

Commit

Permalink
Make it respect depth.
Browse files Browse the repository at this point in the history
  • Loading branch information
bo01ean authored Feb 22, 2018
1 parent 94828a5 commit c38768d
Showing 1 changed file with 58 additions and 60 deletions.
118 changes: 58 additions & 60 deletions debug.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@

Object.defineProperty(global, '__stack', {
get: function () {
var orig = Error.prepareStackTrace;
Error.prepareStackTrace = function (_, stack) {
module.exports = function (space, depth = 2) {
Object.defineProperty(global, '__stack', {
get: function () {
var orig = Error.prepareStackTrace;
Error.prepareStackTrace = function (_, stack) {
return stack;
};
var err = new Error;
Error.captureStackTrace(err, arguments.callee);
var stack = err.stack;
Error.prepareStackTrace = orig;
return stack;
};
var err = new Error;
Error.captureStackTrace(err, arguments.callee);
var stack = err.stack;
Error.prepareStackTrace = orig;
return stack;
}
});
}
});

Object.defineProperty(global, '__line', {
get: function () {
return __stack[2].getLineNumber();
}
});
Object.defineProperty(global, '__line', {
get: function () {
return __stack[depth].getLineNumber();
}
});

Object.defineProperty(global, '__function', {
get: function () {
return __stack[2].getFunctionName();
}
});
Object.defineProperty(global, '__function', {
get: function () {
return __stack[depth].getFunctionName();
}
});

Object.defineProperty(global, '__file', {
get: function () {
return __stack[depth].getFileName();
}
});

Object.defineProperty(global, '__file', {
get: function () {
return __stack[2].getFileName();
function censor(censor) {
var i = 0;
return function (key, value) {
if (i !== 0 && typeof censor === 'object' && typeof value == 'object' && censor == value) { return '[Circular]'; }
if (i >= 29) { return '[Unknown]'; }
++i;
return value;
};
}
});

function censor(censor) {
var i = 0;
return function (key, value) {
if (i !== 0 && typeof censor === 'object' && typeof value == 'object' && censor == value) { return '[Circular]'; }
if (i >= 29) { return '[Unknown]'; }
++i;
return value;
};
}
const regex = /["']?([\.a-z_0-9]+)["']?\s?:(!?.+)(!?\s+)/ig;
const groupIndexForKeys = 1;

const regex = /["']?([\.a-z_0-9]+)["']?\s?:(!?.+)(!?\s+)/ig;
const groupIndexForKeys = 1;
function colorify(str, color) {
color = (color === undefined) ? 6 : color;
var colors = [6, 2, 3, 4, 5, 1];
var colorCode = colors[color];
return '\u001b[3' + color + ';1m' + str + ' ' + '\u001b[0m';
}

function colorify(str, color) {
color = (color === undefined) ? 6 : color;
var colors = [6, 2, 3, 4, 5, 1];
var colorCode = colors[color];
return '\u001b[3' + color + ';1m' + str + ' ' + '\u001b[0m';
}
function colorifyObjectKeys(str) {
while ((m = regex.exec(str)) !== null) {
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
}

function colorifyObjectKeys(str) {
while ((m = regex.exec(str)) !== null) {
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
function parseIt(obj) {
var textRepresentation = JSON.stringify(obj, censor(obj));
return textRepresentation;
}
}

function parseIt(obj) {
var textRepresentation = JSON.stringify(obj, censor(obj));
return textRepresentation;
}

module.exports = function (space) {
space = (space === undefined) ? 'default' : space;
const path = require('path');
const bug = require('debug')(space);
Expand All @@ -78,5 +78,3 @@ module.exports = function (space) {
return bug([].concat.apply([path.basename(__file) + ':' + __line], arguments).join(' '));
}
}


0 comments on commit c38768d

Please sign in to comment.