Functions

Browse all available utility functions by category

string

camelCase

Converts string to camel case.

Example:

camelCase('Foo Bar'); // 'fooBar'
string

capitalize

Converts the first character of string to upper case and the remaining to lower case.

Example:

capitalize('FRED'); // 'Fred'
string

deburr

Deburrs string by converting Latin-1 Supplement and Latin Extended-A letters to basic Latin letters and removing combining diacritical marks.

Example:

deburr('déjà vu'); // 'deja vu'
string

endsWith

Checks if string ends with the given target string.

Example:

endsWith('abc', 'c'); // true
string

escape

Converts the characters "&", "<", ">", '"', and "'" in string to their corresponding HTML entities.

Example:

escape('fred, barney, & pebbles'); // 'fred, barney, &amp; pebbles'
string

escapeRegExp

Escapes the RegExp special characters "^", "$", "\", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", and "|" in string.

Example:

escapeRegExp('[lodash](https://lodash.com/)'); // '\\[lodash\\]\\(https://lodash\\.com/\\)'
string

kebabCase

Converts string to kebab case.

Example:

kebabCase('Foo Bar'); // 'foo-bar'
string

lowerCase

Converts string, as space separated words, to lower case.

Example:

lowerCase('--Foo-Bar--'); // 'foo bar'
string

lowerFirst

Converts the first character of string to lower case.

Example:

lowerFirst('Fred'); // 'fred'
string

pad

Pads string on the left and right sides if it's shorter than length. Padding characters are truncated if they can't be evenly divided by length.

Example:

pad('abc', 8); // ' abc '
string

padEnd

Pads string on the right side if it's shorter than length. Padding characters are truncated if they exceed length.

Example:

padEnd('abc', 6); // 'abc '
string

padStart

Pads string on the left side if it's shorter than length. Padding characters are truncated if they exceed length.

Example:

padStart('abc', 6); // ' abc'
string

parseInt

Converts string to an integer of the specified radix.

Example:

parseInt('08'); // 8
string

repeat

Repeats the given string n times.

Example:

repeat('*', 3); // '***'
string

replace

Replaces matches for pattern in string with replacement.

Example:

replace('Hi Fred', 'Fred', 'Barney'); // 'Hi Barney'
string

snakeCase

Converts string to snake case.

Example:

snakeCase('Foo Bar'); // 'foo_bar'
string

split

Splits string by separator.

Example:

split('a-b-c', '-', 2); // ['a', 'b']
string

startCase

Converts string to start case.

Example:

startCase('--foo-bar--'); // 'Foo Bar'
string

startsWith

Checks if string starts with the given target string.

Example:

startsWith('abc', 'a'); // true
string

toLower

Converts string, as a whole, to lower case.

Example:

toLower('--Foo-Bar--'); // '--foo-bar--'
string

toUpper

Converts string, as a whole, to upper case.

Example:

toUpper('--foo-bar--'); // '--FOO-BAR--'
string

trim

Removes leading and trailing whitespace or specified characters from string.

Example:

trim(' abc '); // 'abc'
string

trimEnd

Removes trailing whitespace or specified characters from string.

Example:

trimEnd(' abc '); // ' abc'
string

trimStart

Removes leading whitespace or specified characters from string.

Example:

trimStart(' abc '); // 'abc '
string

truncate

Truncates string if it's longer than the given maximum string length. The last characters of the truncated string are replaced with the omission string which defaults to "...".

Example:

truncate('hi-diddly-ho there, neighborino'); // 'hi-diddly-ho there, neighbo...'
string

unescape

The inverse of escape; this method converts the HTML entities &amp;, &lt;, &gt;, &quot;, and &#39; in string to their corresponding characters.

Example:

unescape('fred, barney, &amp; pebbles'); // 'fred, barney, & pebbles'
string

upperCase

Converts string, as space separated words, to upper case.

Example:

upperCase('--foo-bar--'); // 'FOO BAR'
string

upperFirst

Converts the first character of string to upper case.

Example:

upperFirst('fred'); // 'Fred'
string

words

Splits string into an array of its words.

Example:

words('fred, barney, & pebbles'); // ['fred', 'barney', 'pebbles']