getDomain

GitHub查看源码
从完整 URL 中提取域名部分(含协议),适用于跨域检测和 URL 分析场景。

用法

getDomain 函数用于获取 URL 的域名部分。

import { getDomain } from '@movk/core'

getDomain('https://sub.example.com/path') // 'sub.example.com'
getDomain('https://example.com:8080') // 'example.com'

API

getDomain(url)

获取 URL 的域名部分。

参数

url
string required
URL 字符串。

返回值

返回值
string
域名,解析失败返回空字符串。

Changelog

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