Simplify the getFilenameFromUrl
helper function
This commit is contained in:
parent
0ba242ea4a
commit
f3e0f86641
@ -338,13 +338,10 @@ function isPdfFile(filename) {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function getFilenameFromUrl(url, onlyStripPath = false) {
|
function getFilenameFromUrl(url, onlyStripPath = false) {
|
||||||
let end = url.length;
|
|
||||||
if (!onlyStripPath) {
|
if (!onlyStripPath) {
|
||||||
const anchor = url.indexOf("#");
|
[url] = url.split(/[#?]/, 1);
|
||||||
const query = url.indexOf("?");
|
|
||||||
end = Math.min(anchor > 0 ? anchor : end, query > 0 ? query : end);
|
|
||||||
}
|
}
|
||||||
return url.substring(url.lastIndexOf("/", end) + 1, end);
|
return url.substring(url.lastIndexOf("/") + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user