* Returns basename from a url eg. 'index.html' from 'ftp://localhost/foo/bar/index.html' * @param {string} url * @returns {string}
(url)
| 9 | * @returns {string} |
| 10 | */ |
| 11 | basename(url) { |
| 12 | url = this.parse(url).url; |
| 13 | const protocol = this.getProtocol(url); |
| 14 | if (protocol === "content:") { |
| 15 | try { |
| 16 | let { rootUri, docId, isFileUri } = Uri.parse(url); |
| 17 | |
| 18 | if (isFileUri) return this.basename(rootUri); |
| 19 | |
| 20 | if (docId.endsWith("/")) docId = docId.slice(0, -1); |
| 21 | docId = docId.split(":").pop(); |
| 22 | return this.pathname(docId).split("/").pop(); |
| 23 | } catch (error) { |
| 24 | return null; |
| 25 | } |
| 26 | } else { |
| 27 | if (url.endsWith("/")) url = url.slice(0, -1); |
| 28 | return this.pathname(url).split("/").pop(); |
| 29 | } |
| 30 | }, |
| 31 | |
| 32 | /** |
| 33 | * Checks if given urls are same or not |