I think it would more performant to just rewrite this as:

    return filename.slice(0, filename.getLastIndexOf('.'));