1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/.
8 * PathUtils is a set of utilities for operating on absolute paths.
10 [ChromeOnly, Exposed=(Window, Worker)]
13 * Return the last path component.
15 * @param path An absolute path.
17 * @returns The last path component.
20 DOMString filename(DOMString path);
23 * Return an ancestor directory of the given path.
25 * @param path An absolute path.
26 * @param depth The number of ancestors to remove, defaulting to 1 (i.e., the
29 * @return The ancestor directory.
31 * If the path provided is a root path (e.g., `C:` on Windows or `/`
32 * on *NIX), then null is returned.
35 DOMString? parent(DOMString path, optional long depth = 1);
38 * Join the given components into a full path.
40 * @param components The path components. The first component must be an
41 * absolute path. There must be at least one component.
44 DOMString join(DOMString... components);
47 * Join the given relative path to the base path.
49 * @param base The base path. This must be an absolute path.
50 * @param relativePath A relative path to join to the base path.
53 DOMString joinRelative(DOMString base, DOMString relativePath);
56 * Creates an adjusted path using a path whose length is already close
57 * to MAX_PATH. For windows only.
59 * @param path An absolute path.
62 DOMString toExtendedWindowsPath(DOMString path);
65 * Normalize a path by removing multiple separators and `..` and `.`
68 * On UNIX platforms, the path must exist as symbolic links will be resolved.
70 * @param path The absolute path to normalize.
74 DOMString normalize(DOMString path);
77 * Split a path into its components.
79 * @param path An absolute path.
82 sequence<DOMString> split(DOMString path);
85 * Split a relative path into its components.
87 * @param path A relative path.
90 sequence<DOMString> splitRelative(DOMString path, optional SplitRelativeOptions options = {});
93 * Transform a file path into a file: URI
95 * @param path An absolute path.
97 * @return The file: URI as a string.
100 UTF8String toFileURI(DOMString path);
103 * Determine if the given path is an absolute or relative path.
105 * @param path A file path that is either relative or absolute.
107 * @return Whether or not the path is absolute.
109 boolean isAbsolute(DOMString path);
113 partial namespace PathUtils {
115 * The profile directory.
117 [Throws, BinaryName="ProfileDirSync"]
118 readonly attribute DOMString profileDir;
121 * The local-specific profile directory.
123 [Throws, BinaryName="LocalProfileDirSync"]
124 readonly attribute DOMString localProfileDir;
127 * The OS temporary directory.
129 [Throws, BinaryName="TempDirSync"]
130 readonly attribute DOMString tempDir;
135 [Throws, BinaryName="XulLibraryPathSync"]
136 readonly attribute DOMString xulLibraryPath;
140 partial namespace PathUtils {
142 * The profile directory.
144 [NewObject, BinaryName="GetProfileDirAsync"]
145 Promise<DOMString> getProfileDir();
148 * The local-specific profile directory.
150 [NewObject, BinaryName="GetLocalProfileDirAsync"]
151 Promise<DOMString> getLocalProfileDir();
154 * The OS temporary directory.
156 [NewObject, BinaryName="GetTempDirAsync"]
157 Promise<DOMString> getTempDir();
162 [NewObject, BinaryName="GetXulLibraryPathAsync"]
163 Promise<DOMString> getXulLibraryPath();
166 dictionary SplitRelativeOptions {
167 /** Allow for a path that contains empty components. */
168 boolean allowEmpty = false;
170 /** Allow for a path that contains ".." components. */
171 boolean allowParentDir = false;
173 /** Allow for a path that contains "." components. */
174 boolean allowCurrentDir = false;