snake_case

Function snake_case 

Source
pub fn snake_case(str_input: &str) -> String
Expand description

Converts a string to snake_case.

Splits the input string into words based on spaces, hyphens, underscores, and capitalization, then converts each word to lowercase and joins them with underscores.

§Arguments

  • str_input - The input string to convert

§Returns

  • String - The converted string in snake_case

§Examples

use lowdash::snake_case;

assert_eq!(snake_case("hello world"), "hello_world");
assert_eq!(snake_case("foo-bar"), "foo_bar");
assert_eq!(snake_case("lorem_ipsum"), "lorem_ipsum");
assert_eq!(snake_case("FooBarBazHello"), "foo_bar_baz_hello");
assert_eq!(snake_case("fooBarBazHello"), "foo_bar_baz_hello");