Socket
Socket
Sign inDemoInstall

prettyjson

Package Overview
Dependencies
1
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 0.2.1

4

History.md

@@ -0,1 +1,5 @@

### 0.2.1 — *January 23, 2012*
* Fix: Bug when the JSON has attributes with booleans, integers or null values
### 0.2.0 — *January 22, 2012*

@@ -2,0 +6,0 @@

@@ -29,3 +29,3 @@ // Package for formatting JSON data in a coloured

// dashColor: 'red', // Color for the dashes in arrays
// defaultIndentation: 4 // Indentation on nested objects
// defaultIndentation: 2 // Indentation on nested objects
// }

@@ -46,8 +46,36 @@ exports.render = function render(data, options, indentation) {

// Helper function to detect if an object can be serializable directly
var isSerializable = function(input) {
if (typeof input === 'string' || typeof input === 'boolean'
|| typeof input === 'number' || input === null) {
return true;
}
return false;
};
var addColorToData = function(input){
if (typeof input === 'string') {
// Print strings in regular terminal color
return input;
}
if (input === true) {
return (input+'').green;
}
if (input === false) {
return (input+'').red;
}
if (input === null) {
return (input+'').grey;
}
if (typeof input === 'number') {
return (input+'').blue;
}
return (input+'');
};
// Render a string exactly equal
if (typeof data === 'string') {
output.push(Utils.indent(indentation) + data);
if (isSerializable(data)) {
output.push(Utils.indent(indentation) + addColorToData(data));
}
else if (Array.isArray(data)) {

@@ -85,4 +113,4 @@ // If the array is empty, render the `emptyArrayMsg`

// If the value is a string, render it in the same line
if (typeof data[i] === 'string') {
// If the value is serializable, render it in the same line
if (isSerializable(data[i])) {
key += exports.render(data[i], options, maxIndexLength - i.length);

@@ -89,0 +117,0 @@ output.push(key);

2

package.json

@@ -5,3 +5,3 @@ {

"description": "Package for formatting JSON data in a coloured YAML-style, perfect for CLI output",
"version": "0.2.0",
"version": "0.2.1",
"homepage": "https://github.com/rafeca/prettyjson",

@@ -8,0 +8,0 @@ "keywords": [

var prettyjson = require('../lib/prettyjson');
describe('prettyjson tests', function(){
describe('prettyjson general tests', function(){

@@ -156,3 +156,31 @@ it("should output a string exactly equal as the input", function(){

});
});
describe('Printing numbers, booleans and other objects', function(){
it("should print numbers correctly ", function(){
var input = 12345;
var output = prettyjson.render(input, {}, 4);
expect(output).toEqual(' ' + '12345'.blue);
});
it("should print booleans correctly ", function(){
var input = true;
var output = prettyjson.render(input, {}, 4);
expect(output).toEqual(' ' + 'true'.green);
input = false;
output = prettyjson.render(input, {}, 4);
expect(output).toEqual(' ' + 'false'.red);
});
it("should print a null object correctly ", function(){
var input = null;
var output = prettyjson.render(input, {}, 4);
expect(output).toEqual(' ' + 'null'.grey);
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc