ensureTrailingSlash

GitHub查看源码
确保 URL 字符串以斜杠结尾,若已有则原样返回,常用于路径标准化处理。

用法

ensureTrailingSlash 函数用于确保 URL 以斜杠结尾。

import { ensureTrailingSlash } from '@movk/core'

ensureTrailingSlash('https://example.com') // 'https://example.com/'
ensureTrailingSlash('https://example.com/path') // 'https://example.com/path/'
ensureTrailingSlash('https://example.com/') // 'https://example.com/'

API

ensureTrailingSlash(url)

确保 URL 以斜杠结尾。

参数

url
string required
URL 字符串。

返回值

返回值
string
带尾部斜杠的 URL。

Changelog

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