StrTool

StrTool

new StrTool()

Source:
字符串工具类

Methods

byteSize(str) → {Number}

Source:
返回字符串的字节长度(方法一)
Example
byteSize('45 d s')   // 6
byteSize('文喝武喝 4s')   // 15
Parameters:
Name Type Description
str String 目标字符串
Returns:
字节长度
Type
Number

byteSize2(str, lenopt) → {Number}

Source:
返回字符串的字节长度(方法二)
Example
byteSize2('文喝武喝 4s'))   // 11
byteSize2('文喝武喝 4s', 3))   // 15
byteSize2('2333哈哈'))   // 8
Parameters:
Name Type Attributes Default Description
str String 目标字符串
len number <optional>
2 一个中文要转换成几个字节(因为有的2,有的3)
Returns:
Type
Number

byteSize3(str, lenopt) → {*}

Source:
返回字符串的字节长度(方法三)
Example
byteSize3('2333哈哈')   // 8
Parameters:
Name Type Attributes Default Description
str *
len number <optional>
2
Returns:
Type
*

capitalize(typeopt) → {String}

Source:
首字母大写
Example
capitalize('azeze')   // Azeze
capitalize('azeZE')   // AzeZE
capitalize('Azeze', 1)   // azeze
Parameters:
Name Type Attributes Default Description
first, ...rest String <optional>
目标字符串
type Number <optional>
1 1:小写;不传:大写
Returns:
Type
String

capitalizeEveryWord(str) → {String}

Source:
每个单词首字母大写
Example
capitalizeEveryWord("hsd sd")   // Hsd Sd
Parameters:
Name Type Description
str String 目标字符串
Returns:
Type
String

end()

Source:
打印结束点

splitLines(str) → {Array}

Source:
将多行字符串拆分为行数组
Example
splitLines('This\nis a\nmultiline\nstring.\n')   // ["This", "is a", "multiline", "string.", ""]
Parameters:
Name Type Description
str String 目标数组
Returns:
Type
Array

start()

Source:
打印开始点

stripHTMLTags(str) → {String}

Source:
删除字符串中的HTMl标签
Example
stripHTMLTags('<p><em>lorem</em> <strong>ipsum</strong></p>')   // 'lorem ipsum'
Parameters:
Name Type Description
str String
Returns:
Type
String

typeSize(val) → {Number}

Source:
获取不同类型变量的字节长度
Example
typeSize('2333哈哈')   // 10
typeSize([1, 2, 3, 4, 5])   // 5
typeSize({ one: 1, two: 2, three: 3 })   // 3
Parameters:
Name Type Description
val * 值/引用
Returns:
Type
Number