yeah, @peterflynn is right.  You could pass `undefined` to slice if `lastIndexOf()` returned -1 e.g. 

    var index = lastIndexOf(".");
    return filename.slice(0, index === -1 ? undefined : index);