@loom-io/front-matter-converter
Version:
Convert front matter yaml and json into json from loom-io files
21 lines (20 loc) • 661 B
JavaScript
import * as YAML from "yaml";
export async function hasFrontMatter(line) {
const firstLine = await line.read("utf8");
return firstLine.startsWith("---");
}
export async function getFrontMatterConverter(firstLine) {
const type = (await firstLine.read("utf8")).replace("---", "");
if (["", "yaml", "yml"].includes(type)) {
return YAML;
}
else if (type === "json") {
return JSON;
}
throw new FrontMatterTypeNotSupportedException(type);
}
export class FrontMatterTypeNotSupportedException extends Error {
constructor(type) {
super(`The frontmatter format inside the file not supported: ${type}`);
}
}