Merge pull request #702 from trheyi/main

add ToCamelCase function in SUI core
This commit is contained in:
Max 2024-07-22 18:05:13 +08:00 committed by GitHub
commit 2c32f983ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View file

@ -357,6 +357,7 @@ func (page *Page) replaceProps(sel *goquery.Selection) error {
}
data := Data{}
for key, prop := range page.props {
key = ToCamelCase(key)
data[key] = prop.Val
}
data["$props"] = data

View file

@ -91,3 +91,22 @@ func TranslationKeyPrefix(name string) string {
name = strings.ReplaceAll(name, "]", "_")
return fmt.Sprintf("trans_%s", name)
}
// ToCamelCase convert the string to camel case
func ToCamelCase(s string, split ...string) string {
splitter := "-"
if len(split) > 0 {
splitter = split[0]
}
s = strings.ToLower(s)
parts := strings.Split(s, splitter)
for i, part := range parts {
if i == 0 {
continue
}
parts[i] = strings.ToUpper(part[:1]) + part[1:]
}
return strings.Join(parts, "")
}