---
title: "safeEncodeURIComponent"
description: "Encode a URI component safely, returning a percent-encoded string and avoiding exceptions on edge-case input during URL building."
canonical_url: "https://core.mhaibaraai.cn/en/docs/utilities/url/safe-encode-uri-component"
---
# safeEncodeURIComponent

> Encode a URI component safely, returning a percent-encoded string and avoiding exceptions on edge-case input during URL building.

## Usage

`safeEncodeURIComponent` encodes a URI component safely.

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

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

## API

### `safeEncodeURIComponent(str)`

Encode a URI component (safe version).

### Parameters

**str** (`string`) *required*: The string to encode.

### Returns

**returns** (`string`): The encoded string.

## Changelog

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

---

- [GitHub](https://github.com/mhaibaraai/movk-core/blob/main/src/utilities/url/transform.ts)


## Sitemap

See the full [sitemap](https://core.mhaibaraai.cn/sitemap.md) for all pages.
