---
title: "safeDecodeURIComponent"
description: "安全地解码 URL 组件，解码失败时返回原字符串而非抛出异常，避免格式错误崩溃。"
seo_title: "safeDecodeURIComponent"
seo_description: "Decode a URI component safely, returning the original string instead of throwing when the input contains malformed escape sequences."
canonical_url: "https://core.mhaibaraai.cn/docs/utilities/url/safe-decode-uri-component"
---
# safeDecodeURIComponent

> 安全地解码 URL 组件，解码失败时返回原字符串而非抛出异常，避免格式错误崩溃。

## 用法

`safeDecodeURIComponent` 函数用于解码 URL 组件(安全版本,失败返回原字符串)。

```ts
import { safeDecodeURIComponent } from '@movk/core'

safeDecodeURIComponent('%E4%B8%AD%E6%96%87') // '中文'
safeDecodeURIComponent('hello%20world') // 'hello world'
safeDecodeURIComponent('%invalid%') // '%invalid%'
```

## API

### `safeDecodeURIComponent(str)`

解码 URL 组件(安全版本)。

### 参数

**str** (`string`) *required*: 要解码的字符串。

### 返回值

**返回值** (`string`): 解码后的字符串。

## Changelog

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


## Sitemap

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