toAbsoluteUrl

将相对 URL 转换为绝对 URL

用法

toAbsoluteUrl 函数用于将相对 URL 转换为绝对 URL。

import { toAbsoluteUrl } from '@movk/core'

toAbsoluteUrl('/path', 'https://example.com')
// 'https://example.com/path'

toAbsoluteUrl('../other', 'https://example.com/api/users')
// 'https://example.com/api/other'

toAbsoluteUrl('https://other.com', 'https://example.com')
// 'https://other.com' (已是绝对URL,不变)

API

toAbsoluteUrl(relativeUrl, baseUrl)

将相对 URL 转换为绝对 URL。

参数

relativeUrl
string required
相对 URL。
baseUrl
string required
基础 URL。

返回值

返回值
string
绝对 URL,转换失败返回原字符串。

Changelog

7c832 — refactor!: 重构模块架构,拆分 utils 为专业化模块

Copyright © 2024 - 2026 YiXuan - MIT License