0 Tk

String Methods

String Manipulation with Lodash

Lodash offers various functions for working with strings. Here are some frequently used string manipulation methods:

_.camelCase([string=‘’])

Converts string to camel case.

_.camelCase('Foo Bar');
// => 'fooBar'

_.camelCase('--foo-bar--');
// => 'fooBar'

_.camelCase('__FOO_BAR__');
// => 'fooBar'

_.trim([string=‘’], [chars=whitespace])

Removes leading and trailing whitespace or specified characters from string.

_.trim('  abc  ');
// => 'abc'

_.trim('-_-abc-_-', '_-');
// => 'abc'

_.template([string=‘’], [options={}])

Creates a compiled template function that can interpolate data properties in “interpolate” delimiters, HTML-escape interpolated data properties in “escape” delimiters, and execute JavaScript in “evaluate” delimiters.

const compiled = _.template('hello <%= user %>!');
compiled({ 'user': 'fred' });
// => 'hello fred!'

Previous: Function Methods Next: Utility Methods

Last updated 2 days ago