MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / basename

Function basename

src/utils/Url.js:11–30  ·  view source on GitHub ↗

* Returns basename from a url eg. 'index.html' from 'ftp://localhost/foo/bar/index.html' * @param {string} url * @returns {string}

(url)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

basenameMethod · 0.80

Tested by

no test coverage detected