(text)
| 57 | * and an estimated runtime in seconds at {@link AUDIOBOOK_WPM}. |
| 58 | */ |
| 59 | export function scriptStats(text) { |
| 60 | const norm = (text || '').replace(/\r\n?/g, '\n'); |
| 61 | const headings = norm.match(new RegExp(HEADING_RE.source, HEADING_RE.flags)) || []; |
| 62 | // Spoken words only: drop `# heading` lines (titles aren't narrated as body, |
| 63 | // mirroring the parser) AND bracket markup, then whitespace-split. |
| 64 | const spoken = stripMarkup(norm.replace(new RegExp(HEADING_RE.source, HEADING_RE.flags), ' ')); |
| 65 | const words = spoken.split(/\s+/).filter(Boolean).length; |
| 66 | const chapters = Math.max(1, headings.length); |
| 67 | const runtimeSec = words > 0 ? (words / AUDIOBOOK_WPM) * 60 : 0; |
| 68 | return { chapters, words, runtimeSec }; |
| 69 | } |
| 70 | |
| 71 | /** Format seconds as a clock string: `H:MM` (≥1h) or `M:SS` (<1h). Pure. */ |
| 72 | export function formatRuntimeClock(sec) { |
no test coverage detected