All files / src/domain story-narrative.ts

75% Statements 24/32
66.66% Branches 12/18
100% Functions 9/9
75% Lines 24/32

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 21 22 23 24 25 26 27 28 29 30 31 32 333x 1x 1x     1x 1x 1x 1x 1x     1x     1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 1x 3x 3x     3x 3x  
/** Compact As / I want / so that for board cards (no H1, no markdown). */
export function compactStoryNarrative(preamble: string | null | undefined): string | null {
  if (!preamble?.trim()) {
    return null
  }
  let text = preamble.trim()
  text = text.replace(/^#\s+US-\d{4}\s*[—-]\s*.+\n?/i, "")
  text = text.replace(/\*\*/g, "")
  text = text.replace(/\s+/g, " ").trim()
  if (!text) {
    return null
  }
  if (text.length > 140) {
    return `${text.slice(0, 137)}…`
  }
  return text
}
 
export function extractUsPreamble(raw: string): string {
  let body = raw
  if (body.replace(/^\uFEFF/, "").startsWith("---")) {
    const end = body.indexOf("---", 3)
    if (end !== -1) {
      body = body.slice(end + 3)
    }
  }
  const match = /^## /m.exec(body)
  if (!match || match.index === undefined) {
    return body.trim()
  }
  return body.slice(0, match.index).trim()
}