All files / app/codeCharta/util nodePathHelper.ts

75% Statements 12/16
83.33% Branches 5/6
50% Functions 2/4
75% Lines 12/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31106x   106x             106x 36x 36x 36x             106x 60x   66x   66x 66x 48x        
import { fileRoot } from "../services/loadFile/fileRoot"
 
export function getUpdatedBlacklistItemPath(fileName: string, path: string) {
    Iif (isAbsoluteRootPath(path)) {
        return getUpdatedPath(fileName, path)
    }
    return path
}
 
export function getUpdatedPath(fileName: string, path: string) {
    const length = fileRoot.rootPath.length + 1
    const end = path.length <= length ? "" : `/${path.slice(length)}`
    return `${fileRoot.rootPath}/${fileName}${end}`
}
 
function isAbsoluteRootPath(path: string) {
    return path.startsWith(`${fileRoot.rootPath}/`)
}
 
export function getParent<T>(hashMap: Map<string, T>, path: string): T {
    do {
        // TODO: Check what happens with Windows paths.
        path = path.slice(0, path.lastIndexOf("/"))
 
        const node = hashMap.get(path)
        if (node) {
            return node
        }
    } while (path !== fileRoot.rootPath && path.length > 0)
}