|
|
@@ -23,39 +23,38 @@ |
|
|
|
* SOFTWARE. |
|
|
|
*/ |
|
|
|
|
|
|
|
// Package strcase converts strings to snake_case or CamelCase |
|
|
|
package strcase |
|
|
|
|
|
|
|
import ( |
|
|
|
"strings" |
|
|
|
) |
|
|
|
|
|
|
|
// Converts a string to snake_case |
|
|
|
// ToSnake converts a string to snake_case |
|
|
|
func ToSnake(s string) string { |
|
|
|
return ToDelimited(s, '_') |
|
|
|
} |
|
|
|
|
|
|
|
// Converts a string to SCREAMING_SNAKE_CASE |
|
|
|
// ToScreamingSnake converts a string to SCREAMING_SNAKE_CASE |
|
|
|
func ToScreamingSnake(s string) string { |
|
|
|
return ToScreamingDelimited(s, '_', true) |
|
|
|
} |
|
|
|
|
|
|
|
// Converts a string to kebab-case |
|
|
|
// ToKebab converts a string to kebab-case |
|
|
|
func ToKebab(s string) string { |
|
|
|
return ToDelimited(s, '-') |
|
|
|
} |
|
|
|
|
|
|
|
// Converts a string to SCREAMING-KEBAB-CASE |
|
|
|
// ToScreamingKebab converts a string to SCREAMING-KEBAB-CASE |
|
|
|
func ToScreamingKebab(s string) string { |
|
|
|
return ToScreamingDelimited(s, '-', true) |
|
|
|
} |
|
|
|
|
|
|
|
// Converts a string to delimited.snake.case (in this case `del = '.'`) |
|
|
|
// ToDelimited converts a string to delimited.snake.case (in this case `del = '.'`) |
|
|
|
func ToDelimited(s string, del uint8) string { |
|
|
|
return ToScreamingDelimited(s, del, false) |
|
|
|
} |
|
|
|
|
|
|
|
// Converts a string to SCREAMING.DELIMITED.SNAKE.CASE (in this case `del = '.'; screaming = true`) or delimited.snake.case (in this case `del = '.'; screaming = false`) |
|
|
|
// ToScreamingDelimited converts a string to SCREAMING.DELIMITED.SNAKE.CASE (in this case `del = '.'; screaming = true`) or delimited.snake.case (in this case `del = '.'; screaming = false`) |
|
|
|
func ToScreamingDelimited(s string, del uint8, screaming bool) string { |
|
|
|
s = addWordBoundariesToNumbers(s) |
|
|
|
s = strings.Trim(s, " ") |
|
|
|