跳转到内容

toStartsWith 1.0.0

typescript
import { toStartsWith } from 'omn'

确保字符串以指定前缀开头;如果已经以该前缀开头则直接返回,否则添加前缀。

示例

typescript
// 不以 "/" 开头时,自动添加
toStartsWith('hello', '/')
// → "/hello"

// 已经以 "/" 开头时,直接返回
toStartsWith('/hello', '/')
// → "/hello"

API

typescript
function toStartsWith(input: string, prefix: string): string
参数类型默认值说明
inputstring-字符串输入
prefixstring-期望的开头前缀