export type GetCanonicalFileName = (fileName: string) => string; export interface FileSpec { wildcardRoot: string; regExp: RegExp; hasDirectoryWildcard: boolean; } export declare namespace FileSpec { function is(value: any): value is FileSpec; function isInPath(path: string, paths: FileSpec[]): boolean; function matchesIncludeFileRegex(filePath: string, isFile?: boolean): boolean; function matchIncludeFileSpec(includeRegExp: RegExp, exclude: FileSpec[], filePath: string, isFile?: boolean): boolean; } export interface FileSystemEntries { files: string[]; directories: string[]; } export declare function getDirectoryPath(pathString: string): string; /** * Returns length of the root part of a path or URL (i.e. length of "/", "x:/", "//server/"). */ export declare function getRootLength(pathString: string, sep?: "\\" | "/"): number; export declare function getPathSeparator(pathString: string): "\\" | "/"; export declare function getPathComponents(pathString: string): string[]; export declare function reducePathComponents(components: readonly string[]): string[]; export declare function combinePathComponents(components: string[]): string; export declare function getRelativePath(dirPath: string, relativeTo: string): string | undefined; export declare function normalizeSlashes(pathString: string, sep?: "\\" | "/"): string; /** * Combines and resolves paths. If a path is absolute, it replaces any previous path. Any * `.` and `..` path components are resolved. Trailing directory separators are preserved. * * ```ts * resolvePath("/path", "to", "file.ext") === "path/to/file.ext" * resolvePath("/path", "to", "file.ext/") === "path/to/file.ext/" * resolvePath("/path", "dir", "..", "to", "file.ext") === "path/to/file.ext" * ``` */ export declare function resolvePaths(path: string, ...paths: (string | undefined)[]): string; export declare function combinePaths(pathString: string, ...paths: (string | undefined)[]): string; /** * Determines whether a `parent` path contains a `child` path using the provide case sensitivity. */ export declare function containsPath(parent: string, child: string, ignoreCase?: boolean): boolean; export declare function containsPath(parent: string, child: string, currentDirectory: string, ignoreCase?: boolean): boolean; /** * Changes the extension of a path to the provided extension. * * ```ts * changeAnyExtension("/path/to/file.ext", ".js") === "/path/to/file.js" * ``` */ export declare function changeAnyExtension(path: string, ext: string): string; /** * Changes the extension of a path to the provided extension if it has one of the provided extensions. * * ```ts * changeAnyExtension("/path/to/file.ext", ".js", ".ext") === "/path/to/file.js" * changeAnyExtension("/path/to/file.ext", ".js", ".ts") === "/path/to/file.ext" * changeAnyExtension("/path/to/file.ext", ".js", [".ext", ".ts"]) === "/path/to/file.js" * ``` */ export declare function changeAnyExtension(path: string, ext: string, extensions: string | readonly string[], ignoreCase: boolean): string; /** * Gets the file extension for a path. * * ```ts * getAnyExtensionFromPath("/path/to/file.ext") === ".ext" * getAnyExtensionFromPath("/path/to/file.ext/") === ".ext" * getAnyExtensionFromPath("/path/to/file") === "" * getAnyExtensionFromPath("/path/to.ext/file") === "" * ``` */ export declare function getAnyExtensionFromPath(path: string): string; /** * Gets the file extension for a path, provided it is one of the provided extensions. * * ```ts * getAnyExtensionFromPath("/path/to/file.ext", ".ext", true) === ".ext" * getAnyExtensionFromPath("/path/to/file.js", ".ext", true) === "" * getAnyExtensionFromPath("/path/to/file.js", [".ext", ".js"], true) === ".js" * getAnyExtensionFromPath("/path/to/file.ext", ".EXT", false) === "" */ export declare function getAnyExtensionFromPath(path: string, extensions: string | readonly string[], ignoreCase: boolean): string; /** * Returns the path except for its containing directory name. * Semantics align with NodeJS's `path.basename` except that we support URLs as well. * * ```ts * // POSIX * getBaseFileName("/path/to/file.ext") === "file.ext" * getBaseFileName("/path/to/") === "to" * getBaseFileName("/") === "" * // DOS * getBaseFileName("c:/path/to/file.ext") === "file.ext" * getBaseFileName("c:/path/to/") === "to" * getBaseFileName("c:/") === "" * getBaseFileName("c:") === "" * ``` */ export declare function getBaseFileName(pathString: string): string; /** * Gets the portion of a path following the last (non-terminal) separator (`/`). * Semantics align with NodeJS's `path.basename` except that we support URLs as well. * If the base name has any one of the provided extensions, it is removed. * * ```ts * getBaseFileName("/path/to/file.ext", ".ext", true) === "file" * getBaseFileName("/path/to/file.js", ".ext", true) === "file.js" * getBaseFileName("/path/to/file.js", [".ext", ".js"], true) === "file" * getBaseFileName("/path/to/file.ext", ".EXT", false) === "file.ext" * ``` */ export declare function getBaseFileName(pathString: string, extensions: string | readonly string[], ignoreCase: boolean): string; /** * Gets a relative path that can be used to traverse between `from` and `to`. */ export declare function getRelativePathFromDirectory(from: string, to: string, ignoreCase: boolean): string; /** * Gets a relative path that can be used to traverse between `from` and `to`. */ export declare function getRelativePathFromDirectory(fromDirectory: string, to: string, getCanonicalFileName: GetCanonicalFileName): string; export declare function getRelativePathComponentsFromDirectory(fromDirectory: string, to: string, getCanonicalFileNameOrIgnoreCase: GetCanonicalFileName | boolean): string[]; export declare function ensureTrailingDirectorySeparator(pathString: string): string; export declare function hasTrailingDirectorySeparator(pathString: string): boolean; export declare function stripTrailingDirectorySeparator(pathString: string): string; export declare function getFileExtension(fileName: string, multiDotExtension?: boolean): string; export declare function getFileName(pathString: string): string; export declare function getShortenedFileName(pathString: string, maxDirLength?: number): string; export declare function stripFileExtension(fileName: string, multiDotExtension?: boolean): string; export declare function normalizePath(pathString: string): string; export declare function getWildcardRegexPattern(rootPath: string, fileSpec: string): string; export declare function isDirectoryWildcardPatternPresent(fileSpec: string): boolean; export declare function getWildcardRoot(rootPath: string, fileSpec: string): string; export declare function hasPythonExtension(path: string): boolean; export declare function getRegexEscapedSeparator(pathSep?: string): "/" | "\\\\"; /** * Determines whether a path is an absolute disk path (e.g. starts with `/`, or a dos path * like `c:`, `c:\` or `c:/`). */ export declare function isRootedDiskPath(path: string): boolean; /** * Determines whether a path consists only of a path root. */ export declare function isDiskPathRoot(path: string): boolean;