All files / src maybe-line.ts

40% Statements 4/10
0% Branches 0/2
0% Functions 0/3
50% Lines 4/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2122x 22x                     22x             22x  
import auto from './auto.js'
import raw from './raw.js'
import type S from './sanitised.js'
 
/**
 * @returns space delimited line constructed from provided elements.
 *
 * `undefined` values are filtered out.
 *
 * Empty list (after filtering out `undefined`) propagates `undefined`.
 */
export const maybeLine =
  (...elements: unknown[]): undefined | S => {
    const elements_ = elements.filter(_ => typeof _ !== 'undefined')
    return elements_.length > 0 ?
      raw(elements_.map(auto).map(_ => _.toString().trim()).join(' ')) :
      undefined
  }
 
export default maybeLine