Skip to content

snakeCase() function

Converts str to snake case.

Word boundaries are detected from spaces, punctuation, digits, case changes, and acronyms.

Signature:

typescript
declare function snakeCase(str: string): string;

Example

ts
snakeCase("foo bar"); // "foo_bar"
snakeCase("fooBar"); // "foo_bar"
snakeCase("foo-bar"); // "foo_bar"
snakeCase("XMLHttpRequest"); // "xml_http_request"

Open Source Code

Released under the Apache-2.0 License.