{"version":3,"file":"get-filename.cjs","names":["safeDecodeURIComponent"],"sources":["../src/get-filename.ts"],"sourcesContent":["import { safeDecodeURIComponent } from './safe-decode-uri-component';\n\n/**\n * Returns the filename part of the URL, decoded so that percent-encoded\n * characters read as they would in a file manager. A filename that can't be\n * decoded is returned as it appears in the URL.\n *\n * @param url The full URL.\n *\n * @example\n * ```js\n * const filename1 = getFilename( 'http://localhost:8080/this/is/a/test.jpg' ); // 'test.jpg'\n * const filename2 = getFilename( '/this/is/a/test.png' ); // 'test.png'\n * const filename3 = getFilename( '/uploads/%E9%9F%B3.mp3' ); // '音.mp3'\n * ```\n *\n * @return The filename part of the URL.\n */\nexport function getFilename( url: string ): string | void {\n\tlet filename;\n\n\tif ( ! url ) {\n\t\treturn;\n\t}\n\n\ttry {\n\t\tfilename = new URL( url, 'http://example.com' ).pathname\n\t\t\t.split( '/' )\n\t\t\t.pop();\n\t} catch {}\n\n\tif ( filename ) {\n\t\t// Decode after splitting the path, so an encoded slash (`%2F`) stays\n\t\t// part of the filename instead of being treated as a separator.\n\t\treturn safeDecodeURIComponent( filename );\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAkBA,SAAgB,YAAa,KAA6B;CACzD,IAAI;CAEJ,IAAK,CAAE,KACN;CAGD,IAAI;EACH,WAAW,IAAI,IAAK,KAAK,oBAAqB,CAAC,CAAC,SAC9C,MAAO,GAAI,CAAC,CACZ,IAAI;CACP,QAAQ,CAAC;CAET,IAAK,UAGJ,QAAA,GAAOA,+BAAAA,uBAAAA,CAAwB,QAAS;AAE1C"}