import { PATH_SEPARATOR } from "./PATH_SEPARATOR.js";

/**
 * Strips all directories from the path.
 * @example 'a/b/c' -> 'c'
 * @param {string} path
 * @returns {string}
 */
export function computePathBase(path) {
    if (typeof path !== "string") {
        throw new Error('path is not a string');
    }

    const lastSlashIndex = path.lastIndexOf(PATH_SEPARATOR);

    if (lastSlashIndex !== -1) {
        return path.substring(lastSlashIndex + 1);
    } else {
        return path;
    }
}
