feat: python.ts
This commit is contained in:
@@ -285,6 +285,23 @@ export function resolveFilename(filename: string): string {
|
||||
return filename;
|
||||
}
|
||||
|
||||
export function joinPath(path1: string, ...paths: string[]): string {
|
||||
let basePath = path1;
|
||||
if (paths != null && paths.length > 0) {
|
||||
for (let i = 0; i < paths.length; i++) {
|
||||
const path2 = paths[i];
|
||||
if (basePath.endsWith("/") && path2.startsWith("/")) {
|
||||
basePath += path2.substring(1);
|
||||
} else if (basePath.endsWith("/") || path2.startsWith("/")) {
|
||||
basePath += path2;
|
||||
} else {
|
||||
basePath += "/" + path2;
|
||||
}
|
||||
}
|
||||
}
|
||||
return basePath;
|
||||
}
|
||||
|
||||
export async function existsPath(path: string): Promise<boolean> {
|
||||
try {
|
||||
const stat = await Deno.stat(path);
|
||||
@@ -507,3 +524,12 @@ Deno.test("test-key-ring-rs", () => {
|
||||
getKeyRingPassword("test-service", "test-user"),
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("join-path", () => {
|
||||
assertEquals("a/b", joinPath("a/", "/b"));
|
||||
assertEquals("a/b", joinPath("a/", "b"));
|
||||
assertEquals("a/b", joinPath("a", "/b"));
|
||||
assertEquals("a/b", joinPath("a", "b"));
|
||||
assertEquals("a/b/c", joinPath("a", "b", "/c"));
|
||||
assertEquals("a/b/c", joinPath("a", "b", "c"));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user