MCPcopy
hub / github.com/tomnomnom/gron / validIdentifier

Function validIdentifier

identifier.go:51–66  ·  view source on GitHub ↗

validIdentifier checks to see if a string is a valid JavaScript identifier E.g: justLettersAndNumbers1 -> true a key with spaces -> false 1startsWithANumber -> false

(s string)

Source from the content-addressed store, hash-verified

49// a key with spaces -> false
50// 1startsWithANumber -> false
51func validIdentifier(s string) bool {
52 if reservedWords[s] || s == "" {
53 return false
54 }
55
56 for i, r := range s {
57 if i == 0 && !validFirstRune(r) {
58 return false
59 }
60 if i != 0 && !validSecondaryRune(r) {
61 return false
62 }
63 }
64
65 return true
66}
67
68// validFirstRune returns true for runes that are valid
69// as the first rune in an identifier.

Callers 5

fillMethod · 0.85
TestValidIdentifierFunction · 0.85
BenchmarkValidIdentifierFunction · 0.85

Calls 2

validFirstRuneFunction · 0.85
validSecondaryRuneFunction · 0.85

Tested by 4

TestValidIdentifierFunction · 0.68
BenchmarkValidIdentifierFunction · 0.68