( root: string, rel: string, lineNumber: number, text: string )
| 1159 | } |
| 1160 | |
| 1161 | export async function insertAtLine( |
| 1162 | root: string, |
| 1163 | rel: string, |
| 1164 | lineNumber: number, |
| 1165 | text: string |
| 1166 | ): Promise<NoteMeta> { |
| 1167 | const abs = resolveSafe(root, rel) |
| 1168 | const body = await fs.readFile(abs, 'utf8') |
| 1169 | const lines = body.replace(/\r\n/g, '\n').split('\n') |
| 1170 | const clamped = Math.max(0, Math.min(lines.length, Math.floor(lineNumber))) |
| 1171 | const insertLines = text.split('\n') |
| 1172 | lines.splice(clamped, 0, ...insertLines) |
| 1173 | await fs.writeFile(abs, lines.join('\n'), 'utf8') |
| 1174 | const folder = folderOf(root, abs) |
| 1175 | if (!folder) throw new Error(`Note not in a known folder: ${rel}`) |
| 1176 | return await readMeta(root, abs, folder) |
| 1177 | } |
| 1178 | |
| 1179 | /* ---------- Backlinks ------------------------------------------------- */ |
| 1180 |
no test coverage detected