Handle dotfiles

This commit is contained in:
Manav Rathi 2024-04-18 14:10:43 +05:30
parent ca29c81394
commit e9e17e6ea3
No known key found for this signature in database

View file

@ -17,8 +17,12 @@ type FileNameComponents = [name: string, extension: string | undefined];
*/
export const nameAndExtension = (fileName: string): FileNameComponents => {
const i = fileName.lastIndexOf(".");
// No extension
if (i == -1) return [fileName, undefined];
else return [fileName.slice(0, i), fileName.slice(i + 1)];
// A hidden file without an extension, e.g. ".gitignore"
if (i == 0) return [fileName, undefined];
// Both components present, just omit the dot.
return [fileName.slice(0, i), fileName.slice(i + 1)];
};
/**