Skip to content

Commit 09f1f78

Browse files
committed
Add type declarations from @types/path-browserify
1 parent f913d9f commit 09f1f78

File tree

1 file changed

+139
-0
lines changed

1 file changed

+139
-0
lines changed

index.d.ts

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
declare namespace path {
2+
/**
3+
* Represents a file path as an object with components.
4+
*/
5+
interface PathObject {
6+
/**
7+
* The root portion of the path.
8+
*/
9+
root: string;
10+
/**
11+
* The directory portion of the path.
12+
*/
13+
dir: string;
14+
/**
15+
* The base name of the file, including the extension.
16+
*/
17+
base: string;
18+
/**
19+
* The file extension including the dot.
20+
*/
21+
ext: string;
22+
/**
23+
* The file name without the extension.
24+
*/
25+
name: string;
26+
}
27+
28+
/**
29+
* Provides methods and properties for handling and transforming file paths.
30+
*/
31+
interface Path {
32+
/**
33+
* Resolves a sequence of paths or path segments into an absolute path.
34+
*
35+
* @param pathSegments - The sequence of path segments to resolve.
36+
* @returns The resolved absolute path.
37+
*/
38+
resolve(this: void, ...pathSegments: string[]): string;
39+
40+
/**
41+
* Normalizes a path, resolving '..' and '.' segments.
42+
*
43+
* @param path - The path to normalize.
44+
* @returns The normalized path.
45+
*/
46+
normalize(this: void, path: string): string;
47+
48+
/**
49+
* Determines if a path is absolute.
50+
*
51+
* @param path - The path to check.
52+
* @returns `true` if the path is absolute, `false` otherwise.
53+
*/
54+
isAbsolute(this: void, path: string): boolean;
55+
56+
/**
57+
* Joins multiple path segments into a single path.
58+
*
59+
* @param paths - The path segments to join.
60+
* @returns The joined path.
61+
*/
62+
join(this: void, ...paths: string[]): string;
63+
64+
/**
65+
* Returns the relative path from one path to another.
66+
*
67+
* @param from - The starting path.
68+
* @param to - The destination path.
69+
* @returns The relative path from `from` to `to`.
70+
*/
71+
relative(this: void, from: string, to: string): string;
72+
73+
/**
74+
* Returns the directory name of a path.
75+
*
76+
* @param path - The path to get the directory name from.
77+
* @returns The directory name of the path.
78+
*/
79+
dirname(this: void, path: string): string;
80+
81+
/**
82+
* Returns the base name of a file, optionally removing the file extension.
83+
*
84+
* @param path - The path to get the base name from.
85+
* @param ext - An optional extension to remove from the base name.
86+
* @returns The base name of the file.
87+
*/
88+
basename(this: void, path: string, ext?: string): string;
89+
90+
/**
91+
* Returns the file extension of a path.
92+
*
93+
* @param path - The path to get the extension from.
94+
* @returns The file extension of the path.
95+
*/
96+
extname(this: void, path: string): string;
97+
98+
/**
99+
* Formats a path object into a path string.
100+
*
101+
* @param pathObject - The path object to format.
102+
* @returns The formatted path string.
103+
*/
104+
format(this: void, pathObject: Partial<PathObject>): string;
105+
106+
/**
107+
* Parses a path string into a path object.
108+
*
109+
* @param path - The path string to parse.
110+
* @returns The parsed path object.
111+
*/
112+
parse(this: void, path: string): PathObject;
113+
114+
/**
115+
* The platform-specific path segment separator.
116+
*/
117+
readonly sep: string;
118+
119+
/**
120+
* The platform-specific path delimiter.
121+
*/
122+
readonly delimiter: string;
123+
124+
/**
125+
* Provides methods for handling Windows paths (always `null`).
126+
*/
127+
readonly win32: null;
128+
129+
/**
130+
* Provides methods for handling POSIX paths.
131+
*/
132+
readonly posix: Path;
133+
}
134+
}
135+
/**
136+
* Provides path-related utilities for handling and transforming file paths.
137+
*/
138+
declare const path: path.Path;
139+
export = path;

0 commit comments

Comments
 (0)