瀏覽代碼

Expose previously private normalize (path) method

Trevor Slaton 5 年之前
父節點
當前提交
e7c8c9ac5e
共有 1 個文件被更改,包括 30 次插入15 次删除
  1. 30 15
      packages/services/src/contents/index.ts

+ 30 - 15
packages/services/src/contents/index.ts

@@ -231,6 +231,17 @@ export namespace Contents {
      */
     localPath(path: string): string;
 
+    /**
+     * Normalize a global path. Reduces '..' and '.' parts, and removes
+     * leading slashes from the local part of the path, while retaining
+     * the drive name if it exists.
+     *
+     * @param path: the path.
+     *
+     * @returns The normalized path.
+     */
+    normalize(path: string): string;
+
     /**
      * Given a path of the form `drive:local/portion/of/it.txt`
      * get the name of the drive. If the path is missing
@@ -597,6 +608,23 @@ export class ContentsManager implements Contents.IManager {
     return PathExt.join(firstParts.slice(1).join(':'), ...parts.slice(1));
   }
 
+  /**
+   * Normalize a global path. Reduces '..' and '.' parts, and removes
+   * leading slashes from the local part of the path, while retaining
+   * the drive name if it exists.
+   *
+   * @param path: the path.
+   *
+   * @returns The normalized path.
+   */
+  normalize(path: string): string {
+    const parts = path.split(':');
+    if (parts.length === 1) {
+      return PathExt.normalize(path);
+    }
+    return `${parts[0]}:${PathExt.normalize(parts.slice(1).join(':'))}`;
+  }
+
   /**
    * Given a path of the form `drive:local/portion/of/it.txt`
    * get the name of the drive. If the path is missing
@@ -678,7 +706,7 @@ export class ContentsManager implements Contents.IManager {
    */
   newUntitled(options: Contents.ICreateOptions = {}): Promise<Contents.IModel> {
     if (options.path) {
-      let globalPath = Private.normalize(options.path);
+      let globalPath = this.normalize(options.path);
       let [drive, localPath] = this._driveForPath(globalPath);
       return drive
         .newUntitled({ ...options, path: localPath })
@@ -746,7 +774,7 @@ export class ContentsManager implements Contents.IManager {
     path: string,
     options: Partial<Contents.IModel> = {}
   ): Promise<Contents.IModel> {
-    const globalPath = Private.normalize(path);
+    const globalPath = this.normalize(path);
     const [drive, localPath] = this._driveForPath(path);
     return drive
       .save(localPath, { ...options, path: localPath })
@@ -1404,17 +1432,4 @@ namespace Private {
     }
     return extension;
   }
-
-  /**
-   * Normalize a global path. Reduces '..' and '.' parts, and removes
-   * leading slashes from the local part of the path, while retaining
-   * the drive name if it exists.
-   */
-  export function normalize(path: string): string {
-    const parts = path.split(':');
-    if (parts.length === 1) {
-      return PathExt.normalize(path);
-    }
-    return `${parts[0]}:${PathExt.normalize(parts.slice(1).join(':'))}`;
-  }
 }