(root: string, rel: string, text: string)
| 1104 | } |
| 1105 | |
| 1106 | export async function prependToNote(root: string, rel: string, text: string): Promise<NoteMeta> { |
| 1107 | const abs = resolveSafe(root, rel) |
| 1108 | const body = await fs.readFile(abs, 'utf8') |
| 1109 | const normalized = body.replace(/\r\n/g, '\n') |
| 1110 | const fm = normalized.match(FRONTMATTER_RE) |
| 1111 | const snippet = trimTrailingNewlines(text) + '\n\n' |
| 1112 | let next: string |
| 1113 | if (fm) { |
| 1114 | const after = normalized.slice(fm[0].length) |
| 1115 | next = fm[0] + snippet + after |
| 1116 | } else { |
| 1117 | next = snippet + normalized |
| 1118 | } |
| 1119 | await fs.writeFile(abs, next, 'utf8') |
| 1120 | const folder = folderOf(root, abs) |
| 1121 | if (!folder) throw new Error(`Note not in a known folder: ${rel}`) |
| 1122 | return await readMeta(root, abs, folder) |
| 1123 | } |
| 1124 | |
| 1125 | export async function replaceInNote( |
| 1126 | root: string, |
no test coverage detected