Commit 0844b88
Changed files (2)
src
test
src/util.ts
@@ -24,18 +24,19 @@ export function isString(obj: any) {
return typeof obj === 'string'
}
+const pad = (v: string) => (v === ' ' ? ' ' : '')
+
export function normalizeMultilinePieces(
pieces: TemplateStringsArray
): TemplateStringsArray {
return Object.assign(
pieces.map((p, i) =>
p.trim()
- ? parseLine(p)
- .words.map(({ w, e }) => {
- if (w === '\\') return ''
- return w.trim() + (p[e + 1] === ' ' ? ' ' : '')
- })
- .join(' ')
+ ? pad(p[0]) +
+ parseLine(p)
+ .words.map(({ w }) => (w === '\\' ? '' : w.trim()))
+ .join(' ') +
+ pad(p[p.length - 1])
: pieces[i]
),
{ raw: pieces.raw }
test/util.test.js
@@ -24,6 +24,7 @@ import {
quote,
quotePowerShell,
randomId,
+ normalizeMultilinePieces,
getCallerLocationFromString,
} from '../build/util.js'
@@ -92,6 +93,13 @@ describe('util', () => {
"$ \u001b[93m$\u001b[39m\u001b[93m'\u001b[39m\u001b[93m\\\u001b[39m\u001b[93m'\u001b[39m\u001b[93m'\u001b[39m\n"
)
})
+
+ test('normalizeMultilinePieces()', () => {
+ assert.equal(
+ normalizeMultilinePieces([' a ', 'b c d', ' e']).join(','),
+ ' a ,b c d, e'
+ )
+ })
})
test('getCallerLocation: empty', () => {