Skip to content

Commit

Permalink
Merge pull request #21 from pinojs/skip-key-undefined
Browse files Browse the repository at this point in the history
If a value is undefined, we need to skip the key as well
  • Loading branch information
mcollina authored Aug 8, 2018
2 parents 66214a0 + 1c34d79 commit b6be3ef
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
8 changes: 3 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit b6be3ef

Please sign in to comment.