For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/string/snakeCase.md.

snakeCase es-toolkit

Converts a string to snake case.

const converted = snakeCase(str);

Usage

snakeCase(str)

Use snakeCase when you want to convert a string to snake case. Snake case is a naming convention where each word is written in lowercase and words are connected with underscores (_).

import { snakeCase } from 'es-toolkit/string';

// Basic usage
snakeCase('camelCase'); // 'camel_case'
snakeCase('some whitespace'); // 'some_whitespace'

// Words connected with hyphens or other separators
snakeCase('hyphen-text'); // 'hyphen_text'
snakeCase('PascalCase'); // 'pascal_case'

// Handling consecutive uppercase letters
snakeCase('HTTPRequest'); // 'http_request'
snakeCase('XMLHttpRequest'); // 'xml_http_request'

It also correctly handles strings with various separators.

import { snakeCase } from 'es-toolkit/string';

// Mixed separators
snakeCase('camelCase-with_mixed.separators'); // 'camel_case_with_mixed_separators'

// With numbers
snakeCase('version2.1.0'); // 'version_2_1_0'

// With special characters
snakeCase('[email protected]'); // 'user_email_com'

Parameters

strstringrequired

The string to convert to snake case.

Returns

Returns a new string converted to snake case.

string
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.