1 declare module "path" {
4 * A parsed path object generated by path.parse() or consumed by path.format().
8 * The root of the path such as '/' or 'c:\'
12 * The full directory path such as '/home/user/dir' or 'c:\path\dir'
16 * The file name including extension (if any) such as 'index.html'
20 * The file extension (if any) such as '.html'
24 * The file name without extension (if any) such as 'index'
29 interface FormatInputPathObject {
31 * The root of the path such as '/' or 'c:\'
35 * The full directory path such as '/home/user/dir' or 'c:\path\dir'
39 * The file name including extension (if any) such as 'index.html'
43 * The file extension (if any) such as '.html'
47 * The file name without extension (if any) such as 'index'
52 interface PlatformPath {
54 * Normalize a string path, reducing '..' and '.' parts.
55 * When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used.
57 * @param p string path to normalize.
59 normalize(p: string): string;
61 * Join all arguments together and normalize the resulting path.
62 * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown.
64 * @param paths paths to join.
66 join(...paths: string[]): string;
68 * The right-most parameter is considered {to}. Other parameters are considered an array of {from}.
70 * Starting from leftmost {from} parameter, resolves {to} to an absolute path.
72 * If {to} isn't already absolute, {from} arguments are prepended in right to left order,
73 * until an absolute path is found. If after using all {from} paths still no absolute path is found,
74 * the current working directory is used as well. The resulting path is normalized,
75 * and trailing slashes are removed unless the path gets resolved to the root directory.
77 * @param pathSegments string paths to join. Non-string arguments are ignored.
79 resolve(...pathSegments: string[]): string;
81 * Determines whether {path} is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory.
83 * @param path path to test.
85 isAbsolute(p: string): boolean;
87 * Solve the relative path from {from} to {to}.
88 * At times we have two absolute paths, and we need to derive the relative path from one to the other. This is actually the reverse transform of path.resolve.
90 relative(from: string, to: string): string;
92 * Return the directory name of a path. Similar to the Unix dirname command.
94 * @param p the path to evaluate.
96 dirname(p: string): string;
98 * Return the last portion of a path. Similar to the Unix basename command.
99 * Often used to extract the file name from a fully qualified path.
101 * @param p the path to evaluate.
102 * @param ext optionally, an extension to remove from the result.
104 basename(p: string, ext?: string): string;
106 * Return the extension of the path, from the last '.' to end of string in the last portion of the path.
107 * If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string
109 * @param p the path to evaluate.
111 extname(p: string): string;
113 * The platform-specific file separator. '\\' or '/'.
115 readonly sep: string;
117 * The platform-specific file delimiter. ';' or ':'.
119 readonly delimiter: string;
121 * Returns an object from a path string - the opposite of format().
123 * @param pathString path to evaluate.
125 parse(p: string): ParsedPath;
127 * Returns a path string from an object - the opposite of parse().
129 * @param pathString path to evaluate.
131 format(pP: FormatInputPathObject): string;
133 * On Windows systems only, returns an equivalent namespace-prefixed path for the given path.
134 * If path is not a string, path will be returned without modifications.
135 * This method is meaningful only on Windows system.
136 * On POSIX systems, the method is non-operational and always returns path without modifications.
138 toNamespacedPath(path: string): string;
140 * Posix specific pathing.
141 * Same as parent object on posix.
143 readonly posix: PlatformPath;
145 * Windows specific pathing.
146 * Same as parent object on windows
148 readonly win32: PlatformPath;
151 const path: path.PlatformPath;