Skip to main content

to_kebab_case

Function to_kebab_case 

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

Converts a string to kebab-case

Handles multiple input formats:

  • camelCase: "getUserById" -> “get-user-by-id”
  • PascalCase: "GetUser" -> “get-user”
  • snake_case: "get_user_by_id" -> “get-user-by-id”
  • Spaces: “List an Organization’s Issues” -> “list-an-organizations-issues”
  • Mixed: "XMLHttpRequest" -> “xml-http-request”
  • Unicode: "CAFÉ" -> “café”

Special handling:

  • Apostrophes are removed entirely: “Organization’s” -> “organizations”
  • Special characters become hyphens: “hello!world” -> “hello-world”
  • Consecutive non-alphanumeric characters are collapsed: “a—b” -> “a-b”
  • Leading/trailing hyphens are trimmed
  • Unicode characters are properly lowercased