* 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 = "")
| 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) |
nothing calls this directly
no outgoing calls
no test coverage detected