@sidekick-coder/db
Version:
Cli Tool to manipulate data from diferent sources
42 lines (38 loc) • 839 B
JavaScript
import { parse as parse$1, stringify as stringify$1 } from 'yaml';
// src/core/parsers/yaml.ts
var parse = parse$1;
var stringify = stringify$1;
var YAML = {
parse,
stringify
};
// src/core/parsers/markdown.ts
function parse2(contents) {
let body = contents;
const result = {};
if (contents.startsWith("---")) {
const [, frontmatter, rest] = contents.split("---");
Object.assign(result, YAML.parse(frontmatter));
body = rest.trim();
}
result["body"] = body || "";
return result;
}
function stringify2(data) {
const { body, ...properties } = data;
let result = "";
if (properties && Object.keys(properties).length) {
result += `---
${YAML.stringify(properties)}---
`;
}
if (body) {
result += body;
}
return result;
}
var MD = {
parse: parse2,
stringify: stringify2
};
export { MD };