Skip to content

Commit f96075f

Browse files
authoredNov 23, 2021
only output space after key in object if value does not start with eol (#271)
1 parent ddafa94 commit f96075f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed
 

‎lib/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ function prettifyObject ({
395395
if (lines === undefined) return
396396

397397
const joinedLines = joinLinesWithIndentation({ input: lines, ident, eol })
398-
result += `${ident}${keyName}: ${joinedLines}${eol}`
398+
result += `${ident}${keyName}:${joinedLines.startsWith(eol) ? '' : ' '}${joinedLines}${eol}`
399399
})
400400
}
401401

‎test/basic.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,17 @@ test('basic prettifier tests', (t) => {
664664
t.equal(arst, 'INFO: hello world\n foo: bar_baz\n multiline\n cow: MOO\n')
665665
})
666666

667+
t.test('does not add trailing space if prettified value begins with eol', (t) => {
668+
t.plan(1)
669+
const pretty = prettyFactory({
670+
customPrettifiers: {
671+
calls: val => '\n' + val.map(it => ' ' + it).join('\n')
672+
}
673+
})
674+
const arst = pretty('{"msg":"doing work","calls":["step 1","step 2","step 3"],"level":30}')
675+
t.equal(arst, 'INFO: doing work\n calls:\n step 1\n step 2\n step 3\n')
676+
})
677+
667678
t.test('does not prettify custom key that does not exists', (t) => {
668679
t.plan(1)
669680
const pretty = prettyFactory({

0 commit comments

Comments
 (0)
Please sign in to comment.