# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/03_leaf.ipynb.

# %% auto 0
__all__ = ['trimleaf', 'joinleaf', 'normleaf']

# %% ../nbs/03_leaf.ipynb 5
from pathlib import Path
from typing import Tuple

# %% ../nbs/03_leaf.ipynb 7
from quac import (strq, )

# %% ../nbs/03_leaf.ipynb 9
from .util import aspath, path2str, joinpaths

# %% ../nbs/03_leaf.ipynb 11
def trimleaf(path: strq = None, node: strq = None) -> Path:
    path = aspath(path2str(path).removesuffix(str(node)))
    node = aspath(node)
    return path

def joinleaf(path: strq = None, node: strq = None) -> Path:
    path = trimleaf(path, node)
    full = joinpaths(path, node)
    return full

def normleaf(base: Path, leaf: Path) -> Tuple[Path, Path]:
    full = Path(trimleaf(base, leaf)) / leaf
    *most, last = full.resolve().parts    
    return Path(*most), Path(last)
