string

计算字符串长度 isStrict为true的时候 返回一个字符串的长度,汉字算2个字符长度

Source:
Parameters:
Name Type Description
str String

要计算的字符串

isStrict Boolean

true 返回一个字符串的长度,汉字算2个字符长度; false 直接返回长度

Returns:
Type:
Number

返回字符串长度

Example
const str = 'script-toolkit库'
console(calcStrLength(str))
console(calcStrLength(str, true))
Source:
Parameters:
Name Type Description
str string

需要操作的字符串

start number

开始位置

end number

结束位置 3 的话就是倒数第三个 倒数第三个不被替换

replaceStr string

替换的值 默认 '*'

Example
omitStr('185098535', 2, 3, '*') // 18****535
Source:
Parameters:
Name Type Description
type String

验证类型

str String

被验证字符串

格式化替换字符串

Source:
Parameters:
Name Type Description
str String

要计算的字符串

isStrict Boolean

true 返回一个字符串的长度,汉字算2个字符长度; false 直接返回长度

Returns:
Type:
Number

返回字符串长度

Example
const str = 'script-toolkit库'
console(calcStrLength(str))
console(calcStrLength(str, true))
Source:
Parameters:
Name Type Description
str string

需要操作的字符串

start number

开始位置

end number

结束位置 3 的话就是倒数第三个 倒数第三个不被替换

replaceStr string

替换的值 默认 '*'

Example
omitStr('185098535', 2, 3, '*') // 18****535
Source:
Parameters:
Name Type Description
type String

验证类型

str String

被验证字符串

验证输入字符串

Source:
Parameters:
Name Type Description
str String

要计算的字符串

isStrict Boolean

true 返回一个字符串的长度,汉字算2个字符长度; false 直接返回长度

Returns:
Type:
Number

返回字符串长度

Example
const str = 'script-toolkit库'
console(calcStrLength(str))
console(calcStrLength(str, true))
Source:
Parameters:
Name Type Description
str string

需要操作的字符串

start number

开始位置

end number

结束位置 3 的话就是倒数第三个 倒数第三个不被替换

replaceStr string

替换的值 默认 '*'

Example
omitStr('185098535', 2, 3, '*') // 18****535
Source:
Parameters:
Name Type Description
type String

验证类型

str String

被验证字符串