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.

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

No recent changes
Copyright © 2024 - 2026 YiXuan - MIT License