MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / appendToNote

Function appendToNote

apps/desktop/src/main/vault.ts:2791–2811  ·  view source on GitHub ↗
(
  root: string,
  rel: string,
  body: string,
  position: 'start' | 'end'
)

Source from the content-addressed store, hash-verified

2789}
2790
2791export async function appendToNote(
2792 root: string,
2793 rel: string,
2794 body: string,
2795 position: 'start' | 'end'
2796): Promise<NoteMeta> {
2797 const abs = resolveSafe(root, rel)
2798 const folder = folderOf(root, abs)
2799 if (!folder) throw new Error(`Note not in a known folder: ${rel}`)
2800 const existing = await fs.readFile(abs, 'utf8')
2801 const trimmedAddition = body.replace(/\s+$/u, '')
2802 if (!trimmedAddition) return await readMeta(root, abs, folder)
2803 const next =
2804 position === 'end'
2805 ? `${existing}${existing.endsWith('\n') ? '' : '\n'}\n${trimmedAddition}\n`
2806 : `${trimmedAddition}\n\n${existing}`
2807 await fs.writeFile(abs, next, 'utf8')
2808 invalidateNoteMetaCache(root, rel)
2809 invalidateVaultTextSearchCache(root)
2810 return await readMeta(root, abs, folder)
2811}
2812
2813export async function uniqueTitle(dir: string, baseTitle: string): Promise<string> {
2814 let candidate = baseTitle

Callers 3

vault.test.tsFile · 0.90
registerIpcFunction · 0.90
cmdAppendFunction · 0.50

Calls 5

invalidateNoteMetaCacheFunction · 0.85
resolveSafeFunction · 0.70
folderOfFunction · 0.70
readMetaFunction · 0.70

Tested by

no test coverage detected