Skip to content

@pmun/utils / stripLeadingSlash

Function: stripLeadingSlash()

ts
function stripLeadingSlash(path?): string;

确保路径不以斜杠 / 开头

Parameters

path?

路径字符串

null | string

Returns

string

不包含前导斜杠的路径字符串,若输入为空则返回空字符串

Example

ts
stripLeadingSlash('/foo/bar') // 'foo/bar'
stripLeadingSlash('foo/bar') // 'foo/bar'
stripLeadingSlash('') // ''