Skip to content

Commit

Permalink
Add formatPath function for existing files
Browse files Browse the repository at this point in the history
  • Loading branch information
richie0866 committed Jun 22, 2021
1 parent bf65512 commit 406e680
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/utils/file-utils/path-utils.ts
Original file line number Diff line number Diff line change
@@ -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];
Expand Down

0 comments on commit 406e680

Please sign in to comment.