// okf-frontmatter.mjs // Minimal flat-frontmatter reader for the shared OKF conformance checker. // Provenance: vendored from okr's lib/frontmatter.mjs at c06e4d7 so the catalog-hosted // checker is self-contained — zero npm dependencies, no cross-repo import. The checker // only reads (never writes), so only parseFrontmatter().get is vendored. okr has since // added BOM/CRLF normalization here (lib/frontmatter.mjs:23); this copy has not, so the // two have diverged and are no longer byte-identical (parity is the parity-gate's job, // not this file's). const FM_RE = /^---\n([\s\S]*?)\n---/; export function parseFrontmatter(content) { const match = String(content).match(FM_RE); const raw = match ? match[1] : null; const get = (key) => { if (raw === null) return null; const m = raw.match(new RegExp(`^\\s*${key}:\\s*(.*)$`, 'm')); if (!m) return null; let v = m[1].trim(); if (v === '') return null; const q = v[0]; if (q === '"' || q === "'") { const end = v.indexOf(q, 1); if (end !== -1) return v.slice(1, end); // internal '#' preserved v = v.slice(1); // unterminated quote: fall back to the rest } else { v = v.replace(/\s+#.*$/, '').trim(); // unquoted: strip trailing comment } return v === '' ? null : v; }; return { raw, get }; }