/**
 * Returns the file extension of the path component of a URL
 * @param {string} url
 * @returns {string} null if no extension found
 */
export function getUrlExtension( url ) {

	let parsedUrl;
	try {

		parsedUrl = new URL( url );

	} catch ( _ ) {

		try {

			// Try again as a relative URL
			parsedUrl = new URL( 'https://example.com/' + url );

		} catch ( _ ) {

			// Ignore invalid URLs
			return null;

		}

	}

	const filename = parsedUrl.pathname.split( '/' ).pop();
	const dotIndex = filename.lastIndexOf( '.' );
	if ( dotIndex === - 1 || dotIndex === filename.length - 1 ) {

		// Has no extension or has trailing . character
		return null;

	}

	const extension = filename.substring( dotIndex + 1 );
	return extension;

}

@@ -229,132 +229,37 @@
  url
- );%0A%0A%09%7D catch ( _ ) %7B%0A%0A%09%09try %7B%0A%0A%09%09%09// Try again as a relative URL%0A%09%09%09parsedUrl = new URL(
+,
  'http
-s
 ://
-example
+fakehost
 .com/'
- + url
  );%0A%0A
-%09
 %09%7D c
@@ -274,17 +274,16 @@
  ) %7B%0A%0A%09%09
-%09
 // Ignor
@@ -299,17 +299,16 @@
  URLs%0A%09%09
-%09
 return n
@@ -317,13 +317,8 @@
 l;%0A%0A
-%09%09%7D%0A%0A
 %09%7D%0A%0A

Use base parameter in URL.