/** * 路徑處理工具類別 * 支援一般路徑和 URL 路徑(http://, https:// 等) * @example * PathHelper.join('a', 'b', 'c') => 'a/b/c' * PathHelper.join('http://example.com', 'api', 'users') => 'http://example.com/api/users' * PathHelper.joinPathWithLeadingSlash('a', 'b') => '/a/b' * PathHelper.removeLeadingSlash('/abc/def') => 'abc/def' */ export declare class PathHelper { private static readonly slashSymbol; /** * 連接多個路徑片段,自動處理斜線 * @param paths 路徑片段 * @returns 連接後的路徑 * @example * join('a', 'b', 'c') => 'a/b/c' * join('a/', '/b/', '/c') => 'a/b/c' * join('/a', 'b', 'c/') => '/a/b/c' * join('', 'a', '', 'b') => 'a/b' * join('http://example.com', 'api', 'users') => 'http://example.com/api/users' */ static join(...paths: string[]): string; /** * 連接多個路徑片段,並確保開頭有斜線 * @param paths 路徑片段 * @returns 連接後的路徑(開頭有斜線) * @example * joinPathWithLeadingSlash('a', 'b', 'c') => '/a/b/c' * joinPathWithLeadingSlash('/a', 'b') => '/a/b' */ static joinPathWithLeadingSlash(...paths: string[]): string; /** * 連接多個路徑片段,不包含開頭斜線 * @param paths 路徑片段 * @returns 連接後的路徑(不含開頭斜線) * @example * joinPathWithoutLeadingSlash('/a', 'b', 'c') => 'a/b/c' * joinPathWithoutLeadingSlash('a', 'b') => 'a/b' */ static joinPathWithoutLeadingSlash(...paths: string[]): string; /** * 移除路徑開頭的斜線 * @param path 路徑 * @returns 移除開頭斜線後的路徑 * @example * removeLeadingSlash('/abc/def') => 'abc/def' * removeLeadingSlash('abc/def') => 'abc/def' */ static removeLeadingSlash(path: string): string; /** * 移除路徑結尾的斜線 * @param path 路徑 * @returns 移除結尾斜線後的路徑 * @example * removeTrailingSlash('abc/def/') => 'abc/def' * removeTrailingSlash('abc/def') => 'abc/def' */ static removeTrailingSlash(path: string): string; /** * 移除路徑開頭和結尾的斜線 * @param path 路徑 * @returns 移除開頭和結尾斜線後的路徑 * @example * trimSlashes('/abc/def/') => 'abc/def' * trimSlashes('abc/def') => 'abc/def' */ static trimSlashes(path: string): string; /** * 移除路徑中重複的斜線 * @param path 路徑 * @returns 移除重複斜線後的路徑 * @example * removeDoubleSlashes('a//b///c') => 'a/b/c' * removeDoubleSlashes('/a//b/') => '/a/b/' * removeDoubleSlashes('http://example.com//api') => 'http://example.com/api' */ static removeDoubleSlashes(path: string): string; /** * 正規化路徑 * @param path 路徑 * @param options 選項 * @param options.leadingSlash 是否保留開頭斜線,預設 true * @param options.trailingSlash 是否保留結尾斜線,預設 false * @returns 正規化後的路徑 * @example * normalizePath('//a//b//c//') => '/a/b/c' * normalizePath('//a//b//c//', { leadingSlash: false }) => 'a/b/c' * normalizePath('//a//b//c//', { trailingSlash: true }) => '/a/b/c/' */ static normalizePath(path: string, options?: { leadingSlash?: boolean; trailingSlash?: boolean; }): string; /** * 確保路徑有開頭斜線 * @param path 路徑 * @returns 有開頭斜線的路徑 * @example * ensureLeadingSlash('abc/def') => '/abc/def' * ensureLeadingSlash('/abc/def') => '/abc/def' */ static ensureLeadingSlash(path: string): string; /** * 確保路徑有結尾斜線 * @param path 路徑 * @returns 有結尾斜線的路徑 * @example * ensureTrailingSlash('abc/def') => 'abc/def/' * ensureTrailingSlash('abc/def/') => 'abc/def/' */ static ensureTrailingSlash(path: string): string; }