prettyjson
Advanced tools
Comparing version 0.13.0 to 1.0.0
@@ -26,3 +26,2 @@ 'use strict'; | ||
exports.render = function render(data, options, indentation) { | ||
// Default values | ||
@@ -44,9 +43,20 @@ indentation = indentation || 0; | ||
var isSerializable = function(input) { | ||
if (typeof input === 'string' || typeof input === 'boolean' || | ||
if (typeof input === 'boolean' || | ||
typeof input === 'number' || input === null) { | ||
return true; | ||
} | ||
if (typeof input === 'string' && input.indexOf('\n') === -1) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
var indentLines = function(string, spaces){ | ||
var lines = string.split('\n'); | ||
lines = lines.map(function(line){ | ||
return Utils.indent(spaces) + line; | ||
}); | ||
return lines.join('\n'); | ||
}; | ||
var addColorToData = function(input) { | ||
@@ -83,2 +93,8 @@ if (options.noColor) { | ||
} | ||
else if (typeof data === 'string') { | ||
//unserializable string means it's multiline | ||
output.push(Utils.indent(indentation) + '"""'); | ||
output.push(indentLines(data, indentation + options.defaultIndentation)); | ||
output.push(Utils.indent(indentation) + '"""'); | ||
} | ||
else if (Array.isArray(data)) { | ||
@@ -95,3 +111,3 @@ // If the array is empty, render the `emptyArrayMsg` | ||
} | ||
var line = Utils.indent(indentation) + line; | ||
line = Utils.indent(indentation) + line; | ||
@@ -98,0 +114,0 @@ // If the element of the array is a string, bool, number, or null |
@@ -5,3 +5,3 @@ { | ||
"description": "Package for formatting JSON data in a coloured YAML-style, perfect for CLI output", | ||
"version": "0.13.0", | ||
"version": "1.0.0", | ||
"homepage": "http://rafeca.com/prettyjson", | ||
@@ -20,3 +20,3 @@ "keywords": [ | ||
"scripts": { | ||
"test": "mocha --reporter spec", | ||
"test": "npm run jshint && mocha --reporter spec", | ||
"testwin": "node ./node_modules/mocha/bin/mocha --reporter spec", | ||
@@ -39,10 +39,10 @@ "jshint": "jshint lib/*.js", | ||
"devDependencies": { | ||
"mocha": "1.8.1", | ||
"should": "1.2.2", | ||
"jshint": "~2.3.0", | ||
"mocha": "^1.18.2", | ||
"should": "^3.1.4", | ||
"jshint": "^2.4.4", | ||
"getversion": "~0.1.1", | ||
"istanbul": "~0.2.4", | ||
"coveralls": "~2.7.0", | ||
"coveralls": "^2.10.0", | ||
"mocha-lcov-reporter": "0.0.1" | ||
} | ||
} |
@@ -78,3 +78,3 @@ # prettyjson [![Build Status](https://secure.travis-ci.org/rafeca/prettyjson.png)](http://travis-ci.org/rafeca/prettyjson) [![NPM version](https://badge.fury.io/js/prettyjson.png)](http://badge.fury.io/js/prettyjson) [![Coverage Status](https://coveralls.io/repos/rafeca/prettyjson/badge.png?branch=master)](https://coveralls.io/r/rafeca/prettyjson?branch=master) | ||
var options = { | ||
noColors: true | ||
noColor: true | ||
}; | ||
@@ -81,0 +81,0 @@ |
@@ -22,2 +22,10 @@ var prettyjson = process.env.EXPRESS_COV ? require('../lib-cov/prettyjson') : require('../lib/prettyjson'); | ||
it("should output a multiline string with indentation", function() { | ||
var input = 'multiple\nlines' | ||
var output = prettyjson.render(input, {}, 4); | ||
output.should.equal(' """\n multiple\n lines\n """'); | ||
}); | ||
it("should output an array of strings", function() { | ||
@@ -24,0 +32,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
621662
449
0