pretty-print
Advanced tools
Comparing version 1.0.0 to 1.1.0
50
index.js
@@ -5,2 +5,3 @@ var _ = require('lodash'); | ||
var util = require('util'); | ||
var asArray = require('as-array'); | ||
@@ -20,5 +21,5 @@ var print = module.exports = function (data, options) { | ||
}; | ||
_.defaults(options, defaults); | ||
var keys = _.keys(data); | ||
@@ -28,3 +29,3 @@ var maxKeyLen = _.max(_.map(keys, function (key) { | ||
})) + options.rightPadding; | ||
_.each(keys, function (key) { | ||
@@ -34,7 +35,7 @@ var paddedKey = addPadding(key, maxKeyLen); | ||
var lPad = ''; | ||
while (leftPadding--) { | ||
lPad += ' '; | ||
} | ||
if (util.isArray(data[key]) && data[key].length > 0){ | ||
@@ -44,5 +45,5 @@ var blankKey = key.replace(/./gi, ' '); // used for spacing | ||
var arr = data[key]; | ||
feedback.info(lPad + paddedKey + JSON.stringify(arr[0]).replace(/^\"|\"$/g, '')); | ||
for(var i = 1; i < arr.length; i += 1) { | ||
@@ -53,3 +54,14 @@ feedback.info(lPad + blankPaddedKey + JSON.stringify(arr[i]).replace(/^\"|\"$/g, '')); | ||
else{ | ||
feedback.info(lPad + paddedKey + JSON.stringify(data[key]).replace(/^\"|\"$/g, '')); | ||
var output = Array.isArray(data[key]) | ||
? asArray(data[key]) | ||
.map(function (item) { | ||
return JSON.stringify(item).replace(/^\"|\"$/g, ''); | ||
}) | ||
.join('') | ||
: JSON.stringify(data[key]).replace(/^\"|\"$/g, ''); | ||
feedback.info(lPad + paddedKey + output); | ||
} | ||
@@ -65,9 +77,9 @@ }); | ||
}; | ||
_.defaults(options, defaults); | ||
var maxKeyLen = _.max(_.map(data, function (obj) { | ||
return obj[options.key].length; | ||
})) + options.rightPadding; | ||
_.each(data, function (obj) { | ||
@@ -77,11 +89,11 @@ var objKey = obj[options.key]; | ||
var lPad = ''; | ||
if (!objKey) return; | ||
while (leftPadding--) { | ||
lPad += ' '; | ||
} | ||
var paddedKey = lPad + addPadding(objKey, maxKeyLen); | ||
if (options.value) paddedKey += obj[options.value]; | ||
@@ -96,12 +108,12 @@ feedback.info(paddedKey); | ||
}; | ||
var leftPadding = options.leftPadding; | ||
var lPad = ''; | ||
while (leftPadding--) { | ||
lPad += ' '; | ||
} | ||
_.defaults(options, defaults); | ||
_.each(data, function (val) { | ||
@@ -108,0 +120,0 @@ feedback.info(lPad + val); |
{ | ||
"name": "pretty-print", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Print formatted data to the the command line", | ||
@@ -27,5 +27,6 @@ "main": "index.js", | ||
"dependencies": { | ||
"lodash": "~2.2.1", | ||
"as-array": "^2.0.0", | ||
"chalk": "~0.3.0", | ||
"feedback": "~0.3.x", | ||
"chalk": "~0.3.0" | ||
"lodash": "~2.2.1" | ||
}, | ||
@@ -32,0 +33,0 @@ "devDependencies": { |
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
5662
130
4
+ Addedas-array@^2.0.0
+ Addedas-array@2.0.0(transitive)