MCPcopy Index your code
hub / github.com/pocketbase/pocketbase / convertGoToJSName

Function convertGoToJSName

plugins/jsvm/mapper.go:34–67  ·  view source on GitHub ↗
(name string)

Source from the content-addressed store, hash-verified

32var nameExceptions = map[string]string{"OAuth2": "oauth2"}
33
34func convertGoToJSName(name string) string {
35 if v, ok := nameExceptions[name]; ok {
36 return v
37 }
38
39 startUppercase := make([]rune, 0, len(name))
40
41 for _, c := range name {
42 if c != '_' && !unicode.IsUpper(c) && !unicode.IsDigit(c) {
43 break
44 }
45
46 startUppercase = append(startUppercase, c)
47 }
48
49 totalStartUppercase := len(startUppercase)
50
51 // all uppercase eg. "JSON" -> "json"
52 if len(name) == totalStartUppercase {
53 return strings.ToLower(name)
54 }
55
56 // eg. "JSONField" -> "jsonField"
57 if totalStartUppercase > 1 {
58 return strings.ToLower(name[0:totalStartUppercase-1]) + name[totalStartUppercase-1:]
59 }
60
61 // eg. "GetField" -> "getField"
62 if totalStartUppercase == 1 {
63 return strings.ToLower(name[0:1]) + name[1:]
64 }
65
66 return name
67}

Callers 2

FieldNameMethod · 0.85
MethodNameMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…