UNPKG

3.82 kBTypeScriptView Raw
1/**
2 * The namespace for path-related functions.
3 *
4 * Note that Jupyter server paths do not start with a leading slash.
5 */
6export declare namespace PathExt {
7 /**
8 * Join all arguments together and normalize the resulting path.
9 * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown.
10 *
11 * @param paths - The string paths to join.
12 */
13 function join(...paths: string[]): string;
14 /**
15 * Return the last portion of a path. Similar to the Unix basename command.
16 * Often used to extract the file name from a fully qualified path.
17 *
18 * @param path - The path to evaluate.
19 *
20 * @param ext - An extension to remove from the result.
21 */
22 function basename(path: string, ext?: string): string;
23 /**
24 * Get the directory name of a path, similar to the Unix dirname command.
25 * When an empty path is given, returns the root path.
26 *
27 * @param path - The file path.
28 */
29 function dirname(path: string): string;
30 /**
31 * Get the extension of the path.
32 *
33 * @param path - The file path.
34 *
35 * @returns the extension of the file.
36 *
37 * #### Notes
38 * The extension is the string from the last occurrence of the `.`
39 * character to end of string in the last portion of the path, inclusive.
40 * If there is no `.` in the last portion of the path, or if the first
41 * character of the basename of path [[basename]] is `.`, then an
42 * empty string is returned.
43 */
44 function extname(path: string): string;
45 /**
46 * Normalize a string path, reducing '..' and '.' parts.
47 * 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.
48 * When an empty path is given, returns the root path.
49 *
50 * @param path - The string path to normalize.
51 */
52 function normalize(path: string): string;
53 /**
54 * Resolve a sequence of paths or path segments into an absolute path.
55 * The root path in the application has no leading slash, so it is removed.
56 *
57 * @param parts - The paths to join.
58 *
59 * #### Notes
60 * The right-most parameter is considered {to}. Other parameters are considered an array of {from}.
61 *
62 * Starting from leftmost {from} parameter, resolves {to} to an absolute path.
63 *
64 * If {to} isn't already absolute, {from} arguments are prepended in right to left order, until an absolute path is found. If after using all {from} paths still no absolute path is found, the current working directory is used as well. The resulting path is normalized, and trailing slashes are removed unless the path gets resolved to the root directory.
65 */
66 function resolve(...parts: string[]): string;
67 /**
68 * Solve the relative path from {from} to {to}.
69 *
70 * @param from - The source path.
71 *
72 * @param to - The target path.
73 *
74 * #### Notes
75 * If from and to each resolve to the same path (after calling
76 * path.resolve() on each), a zero-length string is returned.
77 * If a zero-length string is passed as from or to, `/`
78 * will be used instead of the zero-length strings.
79 */
80 function relative(from: string, to: string): string;
81 /**
82 * Normalize a file extension to be of the type `'.foo'`.
83 *
84 * @param extension - the file extension.
85 *
86 * #### Notes
87 * Adds a leading dot if not present and converts to lower case.
88 */
89 function normalizeExtension(extension: string): string;
90 /**
91 * Remove the leading slash from a path.
92 *
93 * @param path: the path from which to remove a leading slash.
94 */
95 function removeSlash(path: string): string;
96}