Skip to main content

to_kebab_case

Function to_kebab_case 

Source
pub fn to_kebab_case(s: &str) -> String
Expand description

Convert string to kebab-case.

Converts camelCase, PascalCase, and other formats to kebab-case by inserting hyphens before uppercase letters and converting them to lowercase.

Edge cases:

  • Consecutive uppercase letters (acronyms) like “HTTPServer” → “http-server”
  • Leading/trailing hyphens are removed
  • Already kebab-case strings pass through unchanged

§Examples

use spikard_cli::codegen::common::case_conversion::to_kebab_case;
assert_eq!(to_kebab_case("user"), "user");
assert_eq!(to_kebab_case("getUser"), "get-user");
assert_eq!(to_kebab_case("createUserProfile"), "create-user-profile");
assert_eq!(to_kebab_case("HTTPServer"), "http-server");
assert_eq!(to_kebab_case("GraphQLType"), "graph-ql-type"); // Splits on each uppercase