const { inspect } = require("util"); const nodeTypes = { bold: "**", italics: "_", strikethrough: "~~", underline: "==", text: "", }; const CompileASTtoMarkdown = ast => ast.reduce((acc, value) => { if (typeof value === "string") return acc + value; if (value.type === "url") { return acc + `[${CompileASTtoMarkdown(value.children)}](${value.url})`; } let str = nodeTypes[value.type]; str += CompileASTtoMarkdown(value.children); str += nodeTypes[value.type]; return acc + str; }, ""); module.exports = CompileASTtoMarkdown;