MCPcopy Create free account
hub / github.com/TejasQ/gen-subs / splitFilePath

Function splitFilePath

splitFilePath.ts:1–29  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

1export function splitFilePath(filePath: string) {
2 // Extract the base name (the last part of the path)
3 const baseName = filePath.split("/").pop();
4
5 if (!baseName) throw new Error("Invalid file path");
6
7 // Handling cases where there is no extension or the file is hidden
8 if (baseName === "" || baseName.startsWith(".") || !baseName.includes(".")) {
9 return {
10 pathWithoutExtension: filePath,
11 extension: "",
12 fileName: baseName,
13 };
14 }
15
16 // Finding the last dot to separate the extension
17 const lastDotIndex = baseName.lastIndexOf(".");
18
19 // Extracting the path without extension and the extension
20 const pathWithoutExtension =
21 filePath.substring(0, filePath.lastIndexOf(".")) ||
22 baseName.substring(0, lastDotIndex);
23 const extension = baseName.substring(lastDotIndex);
24
25 // Extracting just the file name without the extension
26 const fileName = baseName.substring(0, lastDotIndex);
27
28 return { pathWithoutExtension, extension, fileName };
29}

Callers 3

burnInSubtitlesFunction · 0.90
embedSubtitlesFunction · 0.90
forActionFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected