代码拉取完成,页面将自动刷新
map
examples from parseInt
and trim
(#3487)
import castSlice from './.internal/castSlice.js'
import charsEndIndex from './.internal/charsEndIndex.js'
import charsStartIndex from './.internal/charsStartIndex.js'
import stringToArray from './.internal/stringToArray.js'
/**
* Removes leading and trailing whitespace or specified characters from `string`.
*
* @since 3.0.0
* @category String
* @param {string} [string=''] The string to trim.
* @param {string} [chars=whitespace] The characters to trim.
* @returns {string} Returns the trimmed string.
* @see trimEnd, trimStart
* @example
*
* trim(' abc ')
* // => 'abc'
*
* trim('-_-abc-_-', '_-')
* // => 'abc'
*/
function trim(string, chars) {
if (string && chars === undefined) {
return string.trim()
}
if (!string || !chars) {
return string
}
const strSymbols = stringToArray(string)
const chrSymbols = stringToArray(chars)
const start = charsStartIndex(strSymbols, chrSymbols)
const end = charsEndIndex(strSymbols, chrSymbols) + 1
return castSlice(strSymbols, start, end).join('')
}
export default trim
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。