UNPKG

7.06 kBTypeScriptView Raw
1declare module 'path/posix' {
2 import path = require('path');
3 export = path;
4}
5declare module 'path/win32' {
6 import path = require('path');
7 export = path;
8}
9/**
10 * The `path` module provides utilities for working with file and directory paths.
11 * It can be accessed using:
12 *
13 * ```js
14 * const path = require('path');
15 * ```
16 * @see [source](https://github.com/nodejs/node/blob/v17.0.0/lib/path.js)
17 */
18declare module 'path' {
19 namespace path {
20 /**
21 * A parsed path object generated by path.parse() or consumed by path.format().
22 */
23 interface ParsedPath {
24 /**
25 * The root of the path such as '/' or 'c:\'
26 */
27 root: string;
28 /**
29 * The full directory path such as '/home/user/dir' or 'c:\path\dir'
30 */
31 dir: string;
32 /**
33 * The file name including extension (if any) such as 'index.html'
34 */
35 base: string;
36 /**
37 * The file extension (if any) such as '.html'
38 */
39 ext: string;
40 /**
41 * The file name without extension (if any) such as 'index'
42 */
43 name: string;
44 }
45 interface FormatInputPathObject {
46 /**
47 * The root of the path such as '/' or 'c:\'
48 */
49 root?: string | undefined;
50 /**
51 * The full directory path such as '/home/user/dir' or 'c:\path\dir'
52 */
53 dir?: string | undefined;
54 /**
55 * The file name including extension (if any) such as 'index.html'
56 */
57 base?: string | undefined;
58 /**
59 * The file extension (if any) such as '.html'
60 */
61 ext?: string | undefined;
62 /**
63 * The file name without extension (if any) such as 'index'
64 */
65 name?: string | undefined;
66 }
67 interface PlatformPath {
68 /**
69 * Normalize a string path, reducing '..' and '.' parts.
70 * 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.
71 *
72 * @param p string path to normalize.
73 */
74 normalize(p: string): string;
75 /**
76 * Join all arguments together and normalize the resulting path.
77 * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown.
78 *
79 * @param paths paths to join.
80 */
81 join(...paths: string[]): string;
82 /**
83 * The right-most parameter is considered {to}. Other parameters are considered an array of {from}.
84 *
85 * Starting from leftmost {from} parameter, resolves {to} to an absolute path.
86 *
87 * If {to} isn't already absolute, {from} arguments are prepended in right to left order,
88 * until an absolute path is found. If after using all {from} paths still no absolute path is found,
89 * the current working directory is used as well. The resulting path is normalized,
90 * and trailing slashes are removed unless the path gets resolved to the root directory.
91 *
92 * @param pathSegments string paths to join. Non-string arguments are ignored.
93 */
94 resolve(...pathSegments: string[]): string;
95 /**
96 * Determines whether {path} is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory.
97 *
98 * @param path path to test.
99 */
100 isAbsolute(p: string): boolean;
101 /**
102 * Solve the relative path from {from} to {to}.
103 * 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.
104 */
105 relative(from: string, to: string): string;
106 /**
107 * Return the directory name of a path. Similar to the Unix dirname command.
108 *
109 * @param p the path to evaluate.
110 */
111 dirname(p: string): string;
112 /**
113 * Return the last portion of a path. Similar to the Unix basename command.
114 * Often used to extract the file name from a fully qualified path.
115 *
116 * @param p the path to evaluate.
117 * @param ext optionally, an extension to remove from the result.
118 */
119 basename(p: string, ext?: string): string;
120 /**
121 * Return the extension of the path, from the last '.' to end of string in the last portion of the path.
122 * If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string
123 *
124 * @param p the path to evaluate.
125 */
126 extname(p: string): string;
127 /**
128 * The platform-specific file separator. '\\' or '/'.
129 */
130 readonly sep: string;
131 /**
132 * The platform-specific file delimiter. ';' or ':'.
133 */
134 readonly delimiter: string;
135 /**
136 * Returns an object from a path string - the opposite of format().
137 *
138 * @param pathString path to evaluate.
139 */
140 parse(p: string): ParsedPath;
141 /**
142 * Returns a path string from an object - the opposite of parse().
143 *
144 * @param pathString path to evaluate.
145 */
146 format(pP: FormatInputPathObject): string;
147 /**
148 * On Windows systems only, returns an equivalent namespace-prefixed path for the given path.
149 * If path is not a string, path will be returned without modifications.
150 * This method is meaningful only on Windows system.
151 * On POSIX systems, the method is non-operational and always returns path without modifications.
152 */
153 toNamespacedPath(path: string): string;
154 /**
155 * Posix specific pathing.
156 * Same as parent object on posix.
157 */
158 readonly posix: PlatformPath;
159 /**
160 * Windows specific pathing.
161 * Same as parent object on windows
162 */
163 readonly win32: PlatformPath;
164 }
165 }
166 const path: path.PlatformPath;
167 export = path;
168}
169declare module 'node:path' {
170 import path = require('path');
171 export = path;
172}
173declare module 'node:path/posix' {
174 import path = require('path/posix');
175 export = path;
176}
177declare module 'node:path/win32' {
178 import path = require('path/win32');
179 export = path;
180}