确保字符串以指定后缀结束;若未以该后缀结束则添加之。
Ensure a string ends with the specified suffix; if not, append it.
要确保的后缀 / suffix to ensure
待处理的字符串 / input string
如果 str 已以 suffix 结尾则返回原字符串,否则返回加上后缀后的新字符串 / original string if it already ends with suffix, otherwise the string with suffix appended
str
suffix
// ensureSuffix('.js', 'file') -> 'file.js' Copy
// ensureSuffix('.js', 'file') -> 'file.js'
确保字符串以指定后缀结束;若未以该后缀结束则添加之。
Ensure a string ends with the specified suffix; if not, append it.