mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 10:32:19 -05:00
f4b176c93d
GitOrigin-RevId: 791233ce1e68920a4f2d7042ed4c60ca3f4be8fb
28 lines
784 B
TypeScript
28 lines
784 B
TypeScript
import { findInTree } from '../util/find-in-tree'
|
|
import { Folder } from '../../../../../types/folder'
|
|
import { Doc } from '../../../../../types/doc'
|
|
import { FileRef } from '../../../../../types/file-ref'
|
|
|
|
export function isNameUniqueInFolder(
|
|
tree: Folder,
|
|
parentFolderId: string,
|
|
name: string
|
|
): boolean {
|
|
return !findByNameInFolder(tree, parentFolderId, name)
|
|
}
|
|
|
|
export function findByNameInFolder(
|
|
tree: Folder,
|
|
parentFolderId: string,
|
|
name: string
|
|
): Doc | FileRef | Folder | undefined {
|
|
if (tree._id !== parentFolderId) {
|
|
tree = findInTree(tree, parentFolderId).entity
|
|
}
|
|
|
|
return (
|
|
tree.docs.find(entity => entity.name === name) ||
|
|
tree.fileRefs.find(entity => entity.name === name) ||
|
|
tree.folders.find(entity => entity.name === name)
|
|
)
|
|
}
|