@sidekick-coder/db
Version:
Cli Tool to manipulate data from diferent sources
44 lines (39 loc) • 823 B
JavaScript
;
var yaml = require('yaml');
// src/core/parsers/yaml.ts
var parse = yaml.parse;
var stringify = yaml.stringify;
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
};
exports.MD = MD;