prettyjson
Advanced tools
Comparing version 0.9.0 to 0.10.0
@@ -0,1 +1,6 @@ | ||
### 0.10.0 — *December 10, 2013* | ||
* Add pretty printing of errors (by @mmalecki) | ||
* Deprecate Node.js 0.6.x and 0.8.x | ||
### 0.9.0 — *October 4, 2013* | ||
@@ -2,0 +7,0 @@ |
@@ -112,22 +112,31 @@ // Package for formatting JSON data in a coloured | ||
var key; | ||
var isError = data instanceof Error; | ||
for(var i in data) { | ||
if (data.hasOwnProperty(i)) { | ||
// Prepend the index at the beginning of the line | ||
key = Utils.indent(indentation) + (i + ': ')[options.keysColor]; | ||
Object.getOwnPropertyNames(data).forEach(function(i) { | ||
// Prepend the index at the beginning of the line | ||
key = Utils.indent(indentation) + (i + ': ')[options.keysColor]; | ||
// If the value is serializable, render it in the same line | ||
if (isSerializable(data[i])) { | ||
key += exports.render(data[i], options, maxIndexLength - i.length); | ||
output.push(key); | ||
// Skip `undefined`, it's not a valid JSON value. | ||
if (data[i] === undefined) { | ||
return; | ||
} | ||
// If the index is an array or object, render it in next line | ||
} else { | ||
output.push(key); | ||
output.push( | ||
exports.render(data[i], options, indentation + options.defaultIndentation) | ||
); | ||
} | ||
// If the value is serializable, render it in the same line | ||
if (isSerializable(data[i]) && (!isError || i !== 'stack')) { | ||
key += exports.render(data[i], options, maxIndexLength - i.length); | ||
output.push(key); | ||
// If the index is an array or object, render it in next line | ||
} else { | ||
output.push(key); | ||
output.push( | ||
exports.render( | ||
isError && i === 'stack' | ||
? data[i].split('\n') | ||
: data[i], | ||
options, indentation + options.defaultIndentation | ||
) | ||
); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -134,0 +143,0 @@ // Return all the lines as a string |
@@ -17,8 +17,6 @@ "use strict"; | ||
for (key in input) { | ||
if (input.hasOwnProperty(key) && key.length > maxWidth) { | ||
maxWidth = key.length; | ||
} | ||
} | ||
Object.getOwnPropertyNames(input).forEach(function(key) { | ||
maxWidth = Math.max(maxWidth, key.length); | ||
}); | ||
return maxWidth; | ||
}; |
@@ -5,3 +5,3 @@ { | ||
"description": "Package for formatting JSON data in a coloured YAML-style, perfect for CLI output", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"homepage": "http://rafeca.com/prettyjson", | ||
@@ -26,6 +26,6 @@ "keywords": [ | ||
"engines": { | ||
"node": ">= 0.6.0 < 0.11.0" | ||
"node": ">= 0.10.0 < 0.12.0" | ||
}, | ||
"dependencies": { | ||
"colors": "0.6.0-1" | ||
"colors": "0.6.2" | ||
}, | ||
@@ -32,0 +32,0 @@ "devDependencies": { |
@@ -210,2 +210,16 @@ var prettyjson = process.env.EXPRESS_COV ? require('../lib-cov/prettyjson') : require('../lib/prettyjson'); | ||
}); | ||
it("should print an Error correctly ", function() { | ||
Error.stackTraceLimit = 1; | ||
var input = new Error('foo'); | ||
var stack = input.stack.split('\n'); | ||
var output = prettyjson.render(input, {}, 4); | ||
output.should.equal([ | ||
' ' + 'stack: '.green, | ||
' ' + '- '.green + stack[0], | ||
' ' + '- '.green + stack[1], | ||
' ' + 'message: '.green + ' foo' | ||
].join('\n')); | ||
}); | ||
}); | ||
@@ -212,0 +226,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1387918
974
+ Addedcolors@0.6.2(transitive)
- Removedcolors@0.6.0-1(transitive)
Updatedcolors@0.6.2