prettyjson
Advanced tools
Comparing version 1.2.4 to 1.2.5
@@ -7,4 +7,11 @@ 'use strict'; | ||
var conflictChars = /[^\w\s\n\r\v\t\.,]/i; | ||
exports.version = require('../package.json').version; | ||
// Helper function to detect if an object should be printed or ignored | ||
var isPrintable = function(input, options) { | ||
return input !== undefined || options.renderUndefined; | ||
}; | ||
// Helper function to detect if an object can be directly serializable | ||
@@ -57,3 +64,7 @@ var isSerializable = function(input, onlyPrimitives, options) { | ||
if (typeof input === 'number') { | ||
return colors[options.numberColor](sInput); | ||
if (input >= 0) { | ||
return colors[options.positiveNumberColor](sInput); | ||
} else { | ||
return colors[options.negativeNumberColor](sInput); | ||
} | ||
} | ||
@@ -88,2 +99,12 @@ if (typeof input === 'function') { | ||
var renderToArray = function(data, options, indentation) { | ||
if (typeof data === 'string' && data.match(conflictChars) && | ||
options.escape) { | ||
data = JSON.stringify(data); | ||
} | ||
if (!isPrintable(data, options)) { | ||
return []; | ||
} | ||
if (isSerializable(data, false, options)) { | ||
@@ -102,3 +123,2 @@ return [Utils.indent(indentation) + addColorToData(data, options)]; | ||
if (Array.isArray(data)) { | ||
@@ -113,2 +133,6 @@ // If the array is empty, render the `emptyArrayMsg` | ||
data.forEach(function(element) { | ||
if (!isPrintable(element, options)) { | ||
return; | ||
} | ||
// Prepend the dash at the begining of each array's element line | ||
@@ -160,2 +184,6 @@ var line = '- '; | ||
Object.getOwnPropertyNames(data).forEach(function(i) { | ||
if (!isPrintable(data[i], options)) { | ||
return; | ||
} | ||
// Prepend the index at the beginning of the line | ||
@@ -215,5 +243,11 @@ key = (i + ': '); | ||
options.numberColor = options.numberColor || 'blue'; | ||
options.positiveNumberColor = options.positiveNumberColor | ||
|| options.numberColor; | ||
options.negativeNumberColor = options.negativeNumberColor | ||
|| options.numberColor; | ||
options.defaultIndentation = options.defaultIndentation || 2; | ||
options.noColor = !!options.noColor; | ||
options.noAlign = !!options.noAlign; | ||
options.escape = !!options.escape; | ||
options.renderUndefined = !!options.renderUndefined; | ||
@@ -220,0 +254,0 @@ options.stringColor = options.stringColor || null; |
@@ -5,3 +5,3 @@ { | ||
"description": "Package for formatting JSON data in a coloured YAML-style, perfect for CLI output", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"homepage": "http://rafeca.com/prettyjson", | ||
@@ -22,2 +22,6 @@ "keywords": [ | ||
"main": "./lib/prettyjson", | ||
"files": [ | ||
"bin/prettyjson", | ||
"lib/*.js" | ||
], | ||
"license": "MIT", | ||
@@ -24,0 +28,0 @@ "scripts": { |
@@ -60,2 +60,5 @@ # prettyjson [![Build Status](https://travis-ci.org/rafeca/prettyjson.svg)](https://travis-ci.org/rafeca/prettyjson) [![NPM version](https://badge.fury.io/js/prettyjson.svg)](https://badge.fury.io/js/prettyjson) [![Coverage Status](https://coveralls.io/repos/github/rafeca/prettyjson/badge.svg?branch=master)](https://coveralls.io/github/rafeca/prettyjson?branch=master) | ||
$ prettyjson --inline-arrays=1 package.json | ||
# Escape conflictive strings | ||
$ prettyjson --escape=1 package.json | ||
``` | ||
@@ -62,0 +65,0 @@ |
Sorry, the diff of this file is not supported yet
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
283
139
17361
7