---
title: "snakeCase"
description: "Convert a string to snake_case, lowercasing words and joining them with underscores, ideal for database columns and config keys."
canonical_url: "https://core.mhaibaraai.cn/en/docs/transformers/string/snake-case"
---
# snakeCase

> Convert a string to snake_case, lowercasing words and joining them with underscores, ideal for database columns and config keys.

## Usage

Converts a string to snake_case format.

```ts
import { snakeCase } from '@movk/core'

snakeCase('firstName') // => 'first_name'
snakeCase('First Name') // => 'first_name'
snakeCase('first-name') // => 'first_name'
snakeCase('XMLHttpRequest') // => 'xml_http_request'
```

## API

`snakeCase(str: string): string`

### Parameters

**str** (`string`) *required*: The string to convert.

### Returns

**string**: Returns the string in snake_case format.

## Changelog

See commit history for [src/transformers/string/snakeCase.ts](https://github.com/mhaibaraai/movk-core/commits/main/src/transformers/string/snakeCase.ts).

---

- [GitHub](https://github.com/mhaibaraai/movk-core/blob/main/src/transformers/string/snakeCase.ts)


## Sitemap

See the full [sitemap](https://core.mhaibaraai.cn/sitemap.md) for all pages.
