* Returns dirname from url eg. 'ftp://localhost/foo/' from 'ftp://localhost/foo/bar' * @param {string} url * @returns {string}
(url)
| 171 | * @returns {string} |
| 172 | */ |
| 173 | dirname(url) { |
| 174 | if (typeof url !== "string") throw new Error("URL must be string"); |
| 175 | |
| 176 | const urlObj = this.parse(url); |
| 177 | url = urlObj.url; |
| 178 | const protocol = this.getProtocol(url); |
| 179 | |
| 180 | if (protocol === "content:") { |
| 181 | try { |
| 182 | let { rootUri, docId, isFileUri } = Uri.parse(url); |
| 183 | |
| 184 | if (isFileUri) return this.dirname(rootUri); |
| 185 | else { |
| 186 | if (docId.endsWith("/")) docId = docId.slice(0, -1); |
| 187 | docId = [...docId.split("/").slice(0, -1), ""].join("/"); |
| 188 | return Uri.format(rootUri, docId); |
| 189 | } |
| 190 | } catch (error) { |
| 191 | return null; |
| 192 | } |
| 193 | } else { |
| 194 | if (url.endsWith("/")) url = url.slice(0, -1); |
| 195 | return [...url.split("/").slice(0, -1), ""].join("/") + urlObj.query; |
| 196 | } |
| 197 | }, |
| 198 | |
| 199 | /** |
| 200 | * Parse given url into url and query |