Skip to content

Commit

Permalink
Merge pull request #702 from trheyi/main
Browse files Browse the repository at this point in the history
add ToCamelCase function in SUI core
  • Loading branch information
trheyi authored Jul 22, 2024
2 parents fc1442b + 2f828b6 commit 2c32f98
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions sui/core/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions sui/core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
}

0 comments on commit 2c32f98

Please sign in to comment.