es-toolkit/docs/reference/string/snakeCase.md
정해준 d48900fa55
feat(snakeCase): add snakeCase (#152)
* feat(snakeCase): Add caseSplitPattern RegExp const

* feat(snakeCase): Add caseSplitPattern test code

* feat(snakeCase): Add snakeCase function

* feat(snakeCase): Add snakeCase test code

* feat(snakeCase): Add snakeCase docs

* feat(snakeCase): Add snakeCase benchmarks

* chore: Add string export

* fix(snakeCase): constants public api

* Update docs/ko/reference/string/snakeCase.md

* Update docs/ko/reference/string/snakeCase.md

* Update docs/reference/string/snakeCase.md

---------

Co-authored-by: Sojin Park <raon0211@gmail.com>
2024-07-11 09:14:09 +09:00

710 B

snakeCase

Converts a string to snake case.

Snake case is the naming convention in which each word is written in lowercase and separated by an underscore (_) character. For example, snake_case.

Signature

function snakeCase(str: string): string;

Parameters

  • str (string): The string that is to be changed to snake case.

Returns

(string) The converted string to snake case.

Examples

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

snakeCase('camelCase'); // returns 'camel_case'
snakeCase('some whitespace'); // returns 'some_whitespace'
snakeCase('hyphen-text'); // returns 'hyphen_text'
snakeCase('HTTPRequest'); // returns 'http_request'