CyrefJS
CCyrefJS
فا
Back to documentation
String/Since 1.38.0

snakeCase

Converts a string into snake_case by tokenizing it, lowercasing each word, and joining the words with underscores.

snakeCase(value):string

Tokenization

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

valuestringrequired

The string to convert to snake_case.

Returns

string

A snake_case string created by lowercasing the tokenized words and joining them with underscores.

Examples

01

Basic usage

Convert a phrase into snake_case.

TypeScript
snakeCase("Hello World");
// "hello_world"
02

Multiple words

Each token is lowercased and joined with an underscore.

TypeScript
snakeCase("User Profile Settings");
// "user_profile_settings"
03

Mixed casing

All tokenized words are converted to lowercase.

TypeScript
snakeCase("HelloWorld");
// "hello_world"
04

Empty input

An input that produces no tokens returns an empty string.

TypeScript
snakeCase("");
// ""
05

Underscore-separated output

The resulting tokens are always joined using an underscore.

TypeScript
snakeCase("first second third");
// "first_second_third"
Built with@cyref/js·Official documentation