diff --git a/src/utils/file-utils/path-utils.ts b/src/utils/file-utils/path-utils.ts index b84deb6..5bf4426 100644 --- a/src/utils/file-utils/path-utils.ts +++ b/src/utils/file-utils/path-utils.ts @@ -1,3 +1,18 @@ +/** Formats the given path. **The path must be a real file or folder!** */ +export function formatPath(path: string): string { + assert(isfile(path) || isfolder(path), `'${path}' does not point to a folder or file`); + + // Replace all slashes with forward slashes + path = path.gsub("\\", "/")[0]; + + // Add a trailing slash + if (isfolder(path)) { + if (path.sub(-1) !== "/") path += "/"; + } + + return path; +} + /** Adds a trailing slash if there is no extension. */ export function addTrailingSlash(path: string): string { path = path.gsub("\\", "/")[0];