import { defaultHeaderFields } from './model.js'; // Pure helpers for the printed document. No DOM; tested in Node. // build.js strips `export` when bundling. // What to print for a field. Secrets are either shown or withheld; an empty // secret is always "(not set)" so a blank is never mistaken for a hidden value. export function displayValue(field, includeSecrets) { if (field.secret) { if (!field.value) return '(not set)'; return includeSecrets ? field.value : '[withheld]'; } return field.value || '(blank)'; } export function headerFields(doc) { return doc.header ? doc.header.fields : defaultHeaderFields(doc); } export function headerText(field, doc) { return field.kind === 'lastUpdated' ? (field.text || '') + doc.meta.lastUpdated : field.text; } // { left, middle: [..], right } in printed order: the left-aligned field, then // unaligned fields in list order, then the right-aligned field. Empty text is dropped. export function headerLayout(doc) { const fields = headerFields(doc); const left = fields.find((f) => f.align === 'left'); const right = fields.find((f) => f.align === 'right'); return { left: left ? headerText(left, doc) : '', middle: fields.filter((f) => f.align !== 'left' && f.align !== 'right').map((f) => headerText(f, doc)).filter(Boolean), right: right ? headerText(right, doc) : '', }; } export function countSecrets(doc) { let n = 0; for (const s of doc.sections) { for (const r of s.records || []) for (const f of r.fields) if (f.secret && f.value) n++; } return n; }