确保字符串以指定前缀开始;若未以该前缀开始则添加之。
Ensure a string starts with the specified prefix; if not, prepend it.
要确保的前缀 / prefix to ensure
待处理的字符串 / input string
如果 str 已以 prefix 开头则返回原字符串,否则返回加上前缀后的新字符串 / original string if it already starts with prefix, otherwise the string with prefix prepended
str
prefix
// ensurePrefix('pre-', 'fix') -> 'pre-fix' Copy
// ensurePrefix('pre-', 'fix') -> 'pre-fix'
确保字符串以指定前缀开始;若未以该前缀开始则添加之。
Ensure a string starts with the specified prefix; if not, prepend it.