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

Function basename

src/utils/Path.js:26–35  ·  view source on GitHub ↗

* The path.basename() methods returns the last portion of a path, * similar to the Unix basename command. * Trailing directory separators are ignored, see path.sep. * @param {string} path * @returns {string}

(path, ext = "")

Source from the content-addressed store, hash-verified

24 * @returns {string}
25 */
26 basename(path, ext = "") {
27 ext = ext || "";
28 if (path === "" || path === "/") return path;
29 const ar = path.split("/");
30 const last = ar.slice(-1)[0];
31 if (!last) return ar.slice(-2)[0];
32 let res = decodeURI(last.split("?")[0] || "");
33 if (this.extname(res) === ext) res = res.replace(new RegExp(ext + "$"), "");
34 return res;
35 },
36
37 /**
38 * returns the extension of the path, from the last occurrence of the . (period)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected