Function: parseUrl()
ts
function parseUrl(url): {
hash?: string;
hostname?: string;
password?: string;
pathname?: string;
port?: string;
protocol?: string;
search?: string;
username?: string;
};解析 URL 字符串,返回 URL 的各个组成部分。
Parameters
| Parameter | Type | Description |
|---|---|---|
url | string | 要解析的 URL 字符串 |
Returns
ts
{
hash?: string;
hostname?: string;
password?: string;
pathname?: string;
port?: string;
protocol?: string;
search?: string;
username?: string;
}包含 URL 各个组成部分的对象
hash?
ts
optional hash?: string;hostname?
ts
optional hostname?: string;password?
ts
optional password?: string;pathname?
ts
optional pathname?: string;port?
ts
optional port?: string;protocol?
ts
optional protocol?: string;search?
ts
optional search?: string;username?
ts
optional username?: string;Example
ts
parseUrl('https://example.com/path')
// => { protocol: 'https:', hostname: 'example.com', pathname: '/path', search: '', hash: '' }Since
1.0.0