---
title: "getUrlExtension"
description: "从 URL 中提取文件扩展名（如 .jpg、.pdf），适用于文件类型判断和内容协商。"
seo_title: "getUrlExtension"
seo_description: "Extract the file extension from a URL pathname, returning the part after the last dot so you can branch on asset or document types."
canonical_url: "https://core.mhaibaraai.cn/docs/utilities/url/get-url-extension"
---
# getUrlExtension

> 从 URL 中提取文件扩展名（如 .jpg、.pdf），适用于文件类型判断和内容协商。

## 用法

`getUrlExtension` 函数用于获取 URL 的文件扩展名。

```ts
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)`

获取 URL 的文件扩展名。

### 参数

**url** (`string`) *required*: URL 字符串。

### 返回值

**返回值** (`string`): 文件扩展名(不含点),无扩展名返回空字符串。

## Changelog

See commit history for [src/utilities/url/parse.ts](https://github.com/mhaibaraai/movk-core/commits/main/src/utilities/url/parse.ts).


## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
