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

Function rewriteFolderKeyMap

packages/app-core/src/lib/vault-layout.ts:700–721  ·  view source on GitHub ↗
(
  map: Record<string, T>,
  folder: NoteFolder,
  oldSubpath: string,
  newSubpath: string
)

Source from the content-addressed store, hash-verified

698// so renames/deletes/duplicates rewrite them identically. Generic helpers keep
699// the two in lock-step without duplicating the traversal logic.
700function rewriteFolderKeyMap<T>(
701 map: Record<string, T>,
702 folder: NoteFolder,
703 oldSubpath: string,
704 newSubpath: string
705): Record<string, T> {
706 const next: Record<string, T> = {}
707 const exactKey = folderIconKey(folder, oldSubpath)
708 const prefix = `${exactKey}/`
709 for (const [key, value] of Object.entries(map)) {
710 if (key === exactKey) {
711 next[folderIconKey(folder, newSubpath)] = value
712 continue
713 }
714 if (key.startsWith(prefix)) {
715 next[folderIconKey(folder, newSubpath) + key.slice(exactKey.length)] = value
716 continue
717 }
718 next[key] = value
719 }
720 return next
721}
722
723function removeFolderKeyMap<T>(
724 map: Record<string, T>,

Callers 1

Calls 1

folderIconKeyFunction · 0.70

Tested by

no test coverage detected