toSnakeCase

Converts the str to snake_case, where words are separated by underscores and all letters are lowercase.

Usage Scenarios

  • Variable Naming: In programming, convert strings to snake_case for variable names.
  • Data Standardization: Standardize string formats in data processing.

Example

import { toSnakeCase } from 'funtool/string'

toSnakeCase('helloWorld'); // ✅ 'hello_world'
toSnakeCase('HelloWorld'); // ✅ 'hello_world'
toSnakeCase('hello-world'); // ✅ 'hello_world'
toSnakeCase('APIVersion');  // ✅ 'api_version'
toSnakeCase('MyXMLParser'); // ✅ 'my_xml_parser

Signature

function toSnakeCase(str: string): string

Parameters

  • str ( string ): The input string.

Returns

  • ( string ): A new string in snake_case format.