refactor: use Nuxt 4 directory structure

This commit is contained in:
AnotiaWang
2025-02-28 16:16:02 +08:00
parent 7a87ed5def
commit c45d75fad2
31 changed files with 33 additions and 28 deletions

28
app/utils/tree-node.ts Normal file
View File

@ -0,0 +1,28 @@
export function isChildNode(parentId: string, childId: string) {
return childId.length > parentId.length && childId.startsWith(parentId)
}
export function isParentNode(parentId: string, childId: string) {
return childId.length < parentId.length && childId.startsWith(parentId)
}
export function isRootNode(nodeId: string) {
return nodeId === '0' // equal to `nodeDepth(nodeId) === 1`
}
export function parentNodeId(nodeId: string) {
return nodeId.split('-').shift()
}
export function nodeIndex(nodeId: string) {
return parseInt(nodeId.split('-').pop()!)
}
export function nodeDepth(nodeId: string) {
return nodeId.split('-').length
}
/** Returns the next search breadth at a given node */
export function searchBreadth(initialBreadth: number, nodeId: string) {
return Math.ceil(initialBreadth / Math.pow(2, nodeDepth(nodeId) - 1))
}