mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-22 17:31:03 +01:00
- Introduced a new function ToKebabCase in utils/string.go to convert strings to kebab-case format. - The function trims whitespace, converts to lowercase, and replaces spaces and underscores with hyphens, enhancing string manipulation capabilities in the codebase.
32 lines
634 B
Go
32 lines
634 B
Go
package utils
|
|
|
|
import (
|
|
"golang.org/x/text/cases"
|
|
"golang.org/x/text/language"
|
|
"strings"
|
|
)
|
|
|
|
func ToSnakeCase(s string) string {
|
|
s = strings.TrimSpace(s)
|
|
s = strings.ToLower(s)
|
|
s = strings.ReplaceAll(s, " ", "_")
|
|
s = strings.ReplaceAll(s, "-", "_")
|
|
return s
|
|
}
|
|
|
|
func ToPascalCase(s string) string {
|
|
s = strings.TrimSpace(s)
|
|
s = strings.ReplaceAll(s, "_", " ")
|
|
s = cases.Title(language.English).String(s)
|
|
s = strings.ReplaceAll(s, " ", "")
|
|
return s
|
|
}
|
|
|
|
func ToKebabCase(s string) string {
|
|
s = strings.TrimSpace(s)
|
|
s = strings.ToLower(s)
|
|
s = strings.ReplaceAll(s, " ", "-")
|
|
s = strings.ReplaceAll(s, "_", "-")
|
|
return s
|
|
}
|