MCPcopy
hub / github.com/esm-dev/esm.sh / isJsIdentifier

Function isJsIdentifier

server/utils.go:24–39  ·  view source on GitHub ↗

isJsIdentifier returns true if the given string is a valid JavaScript identifier.

(s string)

Source from the content-addressed store, hash-verified

22
23// isJsIdentifier returns true if the given string is a valid JavaScript identifier.
24func isJsIdentifier(s string) bool {
25 if len(s) == 0 {
26 return false
27 }
28 leadingChar := s[0]
29 if !((leadingChar >= 'a' && leadingChar <= 'z') || (leadingChar >= 'A' && leadingChar <= 'Z') || leadingChar == '_' || leadingChar == '$') {
30 return false
31 }
32 for i := 1; i < len(s); i++ {
33 c := s[i]
34 if !((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_' || c == '$') {
35 return false
36 }
37 }
38 return true
39}
40
41// isCommitish returns true if the given string is a commit hash.
42func isCommitish(s string) bool {

Callers 2

esmRouterFunction · 0.85
cjsModuleLexerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected