Update file type logic

This commit is contained in:
Andras Schmelczer 2026-09-20 22:04:47 +01:00
commit 0f6b618c0b
2 changed files with 18 additions and 2 deletions

View file

@ -71,3 +71,17 @@ describe("isFileTypeMergable", () => {
); );
}); });
}); });
for (const path of [
"md",
"txt",
"nested/md",
"nested/txt",
"a.md/txt",
"a.txt/md",
"note."
]) {
it(`does not merge an extensionless file: ${path}`, () => {
assert.equal(isFileTypeMergable(path, ["md", "txt"]), false);
});
}

View file

@ -2,8 +2,10 @@ export function isFileTypeMergable(
pathOrFileName: string, pathOrFileName: string,
mergeableExtensions: string[] mergeableExtensions: string[]
): boolean { ): boolean {
const parts = pathOrFileName.split("."); const name = pathOrFileName.split("/").at(-1) ?? "";
const fileExtension = parts.at(-1) ?? ""; const separator = name.lastIndexOf(".");
if (separator < 0) return false;
const fileExtension = name.slice(separator + 1);
return mergeableExtensions.includes(fileExtension.toLowerCase()); return mergeableExtensions.includes(fileExtension.toLowerCase());
} }