From 1c34d792e4940d066fa0318c15af54b2e76aaf25 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 8 Aug 2018 15:01:51 +0200 Subject: [PATCH] If a value is undefined, we need to skip the key as well --- index.js | 8 +++----- test/basic.test.js | 3 +-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 0d6d1afd..371bd6f3 100644 --- a/index.js +++ b/index.js @@ -196,10 +196,6 @@ module.exports = function prettyFactory (options) { return line function joinLinesWithIndentation (value) { - if (!value) { - return - } - const lines = value.split(/\r?\n/) for (var i = 1; i < lines.length; i++) { lines[i] = IDENT + lines[i] @@ -248,7 +244,9 @@ module.exports = function prettyFactory (options) { } } } else if (filteredKeys.indexOf(keys[i]) < 0) { - result += IDENT + keys[i] + ': ' + joinLinesWithIndentation(JSON.stringify(value[keys[i]], null, 2)) + EOL + if (value[keys[i]] !== undefined) { + result += IDENT + keys[i] + ': ' + joinLinesWithIndentation(JSON.stringify(value[keys[i]], null, 2)) + EOL + } } } diff --git a/test/basic.test.js b/test/basic.test.js index c297a608..7295b8a6 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -443,8 +443,7 @@ test('basic prettifier tests', (t) => { const formatted = pretty(obj) t.is( formatted, - `[${epoch}] INFO (${pid} on ${hostname}): foo - a: undefined\n` + `[${epoch}] INFO (${pid} on ${hostname}): foo\n` ) cb() }