-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved path handling for imports (#127)
- Loading branch information
Showing
6 changed files
with
81 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export function isAbsolutePath(path: string): boolean { | ||
return path.startsWith("/"); | ||
} | ||
|
||
export function joinPaths(abs_base: string, path: string): string { | ||
return `${abs_base}/${path}`; | ||
} | ||
|
||
export function normalizePath(path: string): string { | ||
let segments = path.split("/"); | ||
let normalizedSegments: string[] = []; | ||
for (const segment of segments) { | ||
switch (segment) { | ||
case "": | ||
break; | ||
case ".": | ||
break; | ||
case "..": | ||
normalizedSegments.pop(); | ||
break; | ||
default: | ||
normalizedSegments.push(segment); | ||
break; | ||
} | ||
} | ||
return (isAbsolutePath(path) ? "/" : "") + normalizedSegments.join("/"); | ||
} | ||
|
||
export function dirOf(path: string) { | ||
// Return everything before the final slash | ||
const lastSlash = path.lastIndexOf("/"); | ||
return path.substring(0, lastSlash); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters