All files / src maybe-lines.ts

92.85% Statements 13/14
50% Branches 1/2
100% Functions 5/5
92.3% Lines 12/13

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   5x 10x 7x 7x 7x 5x 2x   3x     22x  
import auto from './auto.js'
import raw from './raw.js'
import type S from './sanitised.js'
 
/** @returns lines joined with provided separator or undefined if there are no lines. */
export const maybeLines =
  <T>(inputs: readonly T[], separator = '\n'): undefined | S => {
    const outputs =
      inputs
        .filter(_ => typeof _ !== 'undefined')
        .map(_ => auto(_))
        .filter(_ => typeof _ !== 'undefined')
        .map(_ => _.toString().trim())
    if (outputs.length === 0) {
      return
    }
    return raw(outputs.join(separator))
  }
 
export default maybeLines