app/lib/dictionary/parse.mjs
31 lines and 2 functions in DrDustinEdwards/dustinedwards-info, at commit 1590ba4 on 2026-10-24. This file on GitHub.
Functions
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| dictionaryPath | 9 to 11 | 1 | 100% | OkCRAP 1 | No data: no mutants in this code |
| parseDictionaryEntry | 21 to 36 | 4 | 69% | OkCRAP 4.5 | No data: no mutants in this code |
Imports
It imports no other module of this repo. Imported by app/lib/carrel/dictionary-handler.server.ts, app/lib/dictionary/compile.mjs, app/lib/dictionary/save.server.ts, app/lib/health/checks.server.ts, app/lib/operator/sync-tools.server.ts.
Source
// Reads a dictionary entry file (docs/DICTIONARY.md) into its front matter as written and its body, the
// editors' notes. Nothing here judges: compile.mjs does, so the gate, the build and the save read one parse.
import matter from "gray-matter";
export const DICTIONARY_DIR = "content/dictionary";
/** The repository path of an entry's file, from its key (`capsid`). */
export function dictionaryPath(/** @type {string} */ key) {
return `${DICTIONARY_DIR}/${key}.md`;
}
/**
* @typedef {{ data: Record<string, unknown>, body: string, problems: string[] }} ParsedEntry
*/
/**
* @param {{ file: string, raw: string }} input
* @returns {ParsedEntry}
*/
export function parseDictionaryEntry({ file, raw }) {
/** @type {string[]} */
const problems = [];
if (!raw.startsWith("---")) {
problems.push(`${file}: the file must start with a --- front matter block`);
}
try {
// An options object, even an empty one: gray-matter caches by input when it is omitted, and a cached
// parse is one object shared by every caller.
const parsed = matter(raw, {});
return { data: /** @type {Record<string, unknown>} */ (parsed.data), body: parsed.content, problems };
} catch (error) {
problems.push(`${file}: the front matter does not parse: ${error instanceof Error ? error.message.split("\n")[0] : String(error)}`);
return { data: {}, body: "", problems };
}
}