Update file type logic
This commit is contained in:
parent
6201fd9965
commit
0f6b618c0b
2 changed files with 18 additions and 2 deletions
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@ export function isFileTypeMergable(
|
|||
pathOrFileName: string,
|
||||
mergeableExtensions: string[]
|
||||
): boolean {
|
||||
const parts = pathOrFileName.split(".");
|
||||
const fileExtension = parts.at(-1) ?? "";
|
||||
const name = pathOrFileName.split("/").at(-1) ?? "";
|
||||
const separator = name.lastIndexOf(".");
|
||||
if (separator < 0) return false;
|
||||
const fileExtension = name.slice(separator + 1);
|
||||
|
||||
return mergeableExtensions.includes(fileExtension.toLowerCase());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue