getUrlExtension

Extract the file extension from a URL pathname, returning the part after the last dot so you can branch on asset or document types.

Usage

getUrlExtension extracts the file extension from a URL.

import { getUrlExtension } from '@movk/core'

getUrlExtension('https://example.com/file.pdf') // 'pdf'
getUrlExtension('https://example.com/file.tar.gz') // 'gz'
getUrlExtension('https://example.com/path/') // ''

API

getUrlExtension(url)

Get the file extension from a URL.

Parameters

url
string required
The URL string.

Returns

returns
string
The file extension without the leading dot, or an empty string if none found.

Changelog

No recent changes
Copyright © 2024 - 2026 YiXuan - MIT License