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