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