转换字符串string为 驼峰写法。
_.camelCase('Foo Bar');//'fooBar'转换字符串string首字母为大写,剩下为小写。
_.capitalize('FRED');//'Fred'检查字符串string是否以给定的target字符串结尾。
_.endsWith('abc', 'c');//true转义string中的 “&”, “<”, “>”, ‘"’, “’”, 和 “`” 字符为HTML实体字符。
_.escape('<h3>123</h3>'); //<h3>123</h3>_.unescape([string=’’]) _.escape的反向版。 这个方法转换string字符串中的 HTML 实体 &, <, >, ", ', 和 ` 为对应的字符。
_.unescape('<h3>123</h3>'); //<h3>123</h3>转换字符串string为 kebab case.
_.kebabCase('Foo Bar');//'foo-bar'如果string字符串长度小于 length 则从左侧和右侧填充字符。 如果没法平均分配,则截断超出的长度。
_.pad('abc', 8, '_');_.padEnd([string=’’], [length=0], [chars=’ ']) 如果string字符串长度小于 length 则在右侧填充字符。 如果超出length长度则截断超出的部分。 _.padStart([string=’’], [length=0], [chars=’ ']) 如果string字符串长度小于 length 则在左侧填充字符。 如果超出length长度则截断超出的部分。
重复 N 次给定字符串。
_.repeat('abc', 2);//'abcabc'替换string字符串中匹配的pattern为给定的replacement 。
_.replace('Hi Fred', 'Fred', 'Barney');//'Hi Barney'转换字符串string为 snake case.
_.snakeCase('Foo Bar');//'foo_bar'转换 string 字符串为 start case.
_.startCase(' foo-bar'); // => 'Foo Bar'从string字符串中移除前面和后面的 空格 或 指定的字符。
_.trim('abc-_-', '-_-');//'abc'截断string字符串,如果字符串超出了限定的最大值。 被截断的字符串后面会以 omission 代替,omission 默认是 “…”。
_.truncate('hi-diddly-ho there, neighborino');//'hi-diddly-ho there, neighbo...' _.truncate('hi-diddly-ho there, neighborino', { 'length': 24, });//'hi-diddly-ho there,...'拆分字符串string中的词为数组 。
_.words('fred, barney, & pebbles');//['fred', 'barney', 'pebbles']创建一个预编译模板方法,可以插入数据到模板中 “interpolate” 分隔符相应的位置。
var compiled = _.template('hello <%= user %>!'); compiled({ 'user': 'fred' });//'hello fred!'