FridayNightFunkinBoyfriendBot/ChomensJS/util/getFilenameFromUrl.js
2024-02-20 17:01:13 +00:00

14 lines
371 B
JavaScript

const path = require('path')
/**
* get filename from url
* @param {string} urlStr the url
* @return {string} filename
* @example
* getFilenameFromUrl('https://sus.red/amogus.mid?verysus=true') // returns 'amogus.mid'
*/
function getFilenameFromUrl (urlStr) {
const url = new URL(urlStr)
return path.basename(url.pathname)
}
module.exports = getFilenameFromUrl