瀏覽代碼

Clean up path an url functions

Steven Silvester 8 年之前
父節點
當前提交
9d6dbda823
共有 2 個文件被更改,包括 12 次插入14 次删除
  1. 4 13
      src/coreutils/path.ts
  2. 8 1
      src/coreutils/url.ts

+ 4 - 13
src/coreutils/path.ts

@@ -7,6 +7,8 @@ import * as posix
 
 /**
  * The namespace for path-related functions.
+ *
+ * Note that Jupyter server paths do not start with a leading slash.
  */
 export
 namespace PathExt {
@@ -18,7 +20,7 @@ namespace PathExt {
    */
   export
   function join(...paths: string[]): string {
-    return posix.join(...paths);
+    return removeSlash(posix.join(...paths));
   }
 
   /**
@@ -41,7 +43,7 @@ namespace PathExt {
    */
   export
   function dirname(path: string): string {
-    return posix.dirname(path);
+    return removeSlash(posix.dirname(path));
   }
 
   /**
@@ -110,17 +112,6 @@ namespace PathExt {
     return removeSlash(posix.relative(from, to));
   }
 
-  /**
-   * Determines whether {path} is an absolute path. An absolute path will
-   * always resolve to the same location, regardless of the working directory.
-   *
-   * @param path - The path to test.
-   */
-  export
-  function isAbsolute(path: string): boolean {
-    return posix.isAbsolute(path);
-  }
-
   /**
    * Normalize a file extension to be of the type `'.foo'`.
    *

+ 8 - 1
src/coreutils/url.ts

@@ -24,6 +24,7 @@ namespace URLExt {
   function parse(url: string): IUrl {
     if (typeof document !== 'undefined') {
       let a = document.createElement('a');
+      a.href = url;
       return a;
     }
     return urlparse(url);
@@ -96,7 +97,13 @@ namespace URLExt {
    */
   export
   function isLocal(url: string): boolean {
-    return !parse(url).protocol && url.indexOf('//') !== 0;
+    switch (parse(url).hostname) {
+    case 'localhost':
+    case '':
+      return true;
+    default:
+      return false;
+    }
   }
 
   /**