Handle dotfiles
This commit is contained in:
parent
ca29c81394
commit
e9e17e6ea3
1 changed files with 5 additions and 1 deletions
|
@ -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)];
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue