1.38.0snakeCase
Converts a string into snake_case by tokenizing it, lowercasing each word, and joining the words with underscores.
snakeCase(value):stringTokenization
The input is first passed to the internal tokenize function. The exact token boundaries therefore depend on the behavior of tokenize.
Lowercase conversion
Each token returned by tokenize is converted to lowercase using toLowerCase().
Joining tokens
The lowercase tokens are joined together using an underscore (_) as the separator.
Parameters
valuestringrequiredThe string to convert to snake_case.
Returns
stringA snake_case string created by lowercasing the tokenized words and joining them with underscores.
Examples
Basic usage
Convert a phrase into snake_case.
snakeCase("Hello World");
// "hello_world"Multiple words
Each token is lowercased and joined with an underscore.
snakeCase("User Profile Settings");
// "user_profile_settings"Mixed casing
All tokenized words are converted to lowercase.
snakeCase("HelloWorld");
// "hello_world"Empty input
An input that produces no tokens returns an empty string.
snakeCase("");
// ""Underscore-separated output
The resulting tokens are always joined using an underscore.
snakeCase("first second third");
// "first_second_third"