# url.parse ## 功能 解析当前 URL 为对象。 ## 语法 ```bt url(text).parse() ``` ## 参数 无。 ## 返回值 | 类型 | 说明 | | ------ | ------ | | Object | 返回 URL 解析对象。字段见下方“返回对象字段”。 | ## 返回对象字段 | 字段 | 类型 | 必定存在 | 说明 | | ------ | ------ | ------ | ------ | | scheme | String | 是 | URL scheme,不含 `:`,例如 `http`、`https`。 | | username | String | 是 | URL 用户名。没有用户名时为空字符串。 | | password | String/Empty | 是 | URL 密码。没有密码时为 `empty`。 | | host | String/Empty | 是 | 主机名或 IP 字符串。URL 没有 host 时为 `empty`。 | | port | Int/Empty | 是 | 显式端口号。URL 未显式提供端口时为 `empty`,不会返回 scheme 的默认端口。 | | path | String | 是 | URL 路径,通常以 `/` 开头。 | | query | String/Empty | 是 | 原始查询字符串,不含 `?`。没有查询字符串时为 `empty`。 | | fragment | String/Empty | 是 | URL fragment,不含 `#`。没有 fragment 时为 `empty`。 | | origin | String | 是 | URL origin 的 ASCII 序列化结果,例如 `https://btlang.org`。 | | url | String | 是 | 标准化后的完整 URL 字符串。 | ## 代码示例 ```bt info = url('https://btlang.org/zh-hans/docs/index?q=BT').parse() // 输出:btlang.org print info.host ``` ## 注意事项 - URL 无法解析时会抛出运行时错误。 - `password`、`host`、`port`、`query`、`fragment` 这些可选 URL 组件缺失时返回 `empty`。