Skip to content

snakeCase

Converts a string to snake_case. Handles camelCase, PascalCase, kebab-case, spaces, and mixed formats.

Available since v2.0.0

import { snakeCase } from '@helpers4/string';
// or, from the all-in-one package (same code, one install):
import { snakeCase } from 'helpers4/string';
snakeCase(str: string): string
ParameterTypeDescription
strstringThe string to convert

string — String in snake_case

Converts a camelCase string to snake_case.

snakeCase('myVariableName')
// => 'my_variable_name'

Also handles kebab-case and other formats.

snakeCase('my-component-name')
// => 'my_component_name'

View source on GitHub