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

/**
 * Get name of a file from a given path
 * @param {string} path
 * @returns {string}
 *
 * @example
 *  'a/b/c.txt' -> 'c'
 *  'hello.txt' -> 'hello'
 *  'http://meep.com/index.html' -> 'index'
 */
export function computeFileName(path) {
    const base = computePathBase(path);

    const lastDotIndex = base.lastIndexOf('.');

    if (lastDotIndex !== -1) {
        return base.substring(0, lastDotIndex);
    } else {
        //no extension
        return base;
    }
}