---
title: "URL"
description: "一组用于描述 URL 结构与解析结果的 TypeScript 类型定义，覆盖协议、主机、路径等字段。"
seo_title: "URL Types"
seo_description: "Reference for @movk/core URL types, including the parsed URL shape and the query parameter value and record types used by URL utilities."
canonical_url: "https://core.mhaibaraai.cn/docs/types/url"
---
# URL

> 一组用于描述 URL 结构与解析结果的 TypeScript 类型定义，覆盖协议、主机、路径等字段。

## `ParsedUrl`

URL 解析结果接口。

```ts
interface ParsedUrl {
  /** 完整的原始 URL */
  href: string
  /** 协议 (http:, https:, etc.) */
  protocol: string
  /** 主机名 + 端口 */
  host: string
  /** 主机名 */
  hostname: string
  /** 端口号 */
  port: string
  /** 路径部分 */
  pathname: string
  /** 查询字符串 (包含 ?) */
  search: string
  /** 哈希部分 (包含 #) */
  hash: string
  /** 用户认证信息 (user:pass) */
  auth: string
  /** 源 (protocol + host) */
  origin: string
}
```

## 用法

```ts
import type { ParsedUrl } from '@movk/core'
import { parseUrl } from '@movk/core'

const result: ParsedUrl | null = parseUrl('https://example.com/path')
```

## `QueryParamValue`

查询参数值类型。

```ts
type QueryParamValue = string | number | boolean | null | undefined
```

## 用法

```ts
import type { QueryParamValue } from '@movk/core'

const value: QueryParamValue = 'hello'
const numValue: QueryParamValue = 123
const boolValue: QueryParamValue = true
```

## `QueryParams`

查询参数对象类型。

```ts
type QueryParams = Record<string, QueryParamValue | QueryParamValue[]>
```

## 用法

```ts
import type { QueryParams } from '@movk/core'

const params: QueryParams = {
  page: 1,
  limit: 10,
  tags: ['a', 'b', 'c'],
  active: true,
}
```

## Changelog

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


## Sitemap

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