Skip to content

Commit

Permalink
Function to convert to upper kebab case
Browse files Browse the repository at this point in the history
  • Loading branch information
stoewer committed Feb 26, 2020
1 parent e8fc715 commit 98db970
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion kebab.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ package strcase

// KebabCase converts a string into kebab case.
func KebabCase(s string) string {
return lowerDelimiterCase(s, '-')
return delimiterCase(s, '-', false)
}

// UpperKebabCase converts a string into kebab case with capital letters.
func UpperKebabCase(s string) string {
return delimiterCase(s, '-', true)
}
23 changes: 23 additions & 0 deletions kebab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,26 @@ func TestKebabCase(t *testing.T) {
assert.Equal(t, snake, converted)
}
}

func TestUpperKebabCase(t *testing.T) {
data := map[string]string{
"": "",
"F": "F",
"Foo": "FOO",
"FooB": "FOO-B",
"FooID": "FOO-ID",
" FooBar\t": "FOO-BAR",
"HTTPStatusCode": "HTTP-STATUS-CODE",
"ParseURL.DoParse": "PARSE-URL.DO-PARSE",
"Convert Space": "CONVERT-SPACE",
"Convert-dash": "CONVERT-DASH",
"Skip___MultipleUnderscores": "SKIP-MULTIPLE-UNDERSCORES",
"Skip MultipleSpaces": "SKIP-MULTIPLE-SPACES",
"Skip---MultipleDashes": "SKIP-MULTIPLE-DASHES",
}

for camel, snake := range data {
converted := UpperKebabCase(camel)
assert.Equal(t, snake, converted)
}
}

0 comments on commit 98db970

Please sign in to comment.