github.com/MontFerret/ferret@v0.18.0/pkg/drivers/cdp/dom/helpers.go (about)

     1  package dom
     2  
     3  import (
     4  	"bytes"
     5  	"regexp"
     6  	"strings"
     7  )
     8  
     9  var camelMatcher = regexp.MustCompile("[A-Za-z0-9]+")
    10  
    11  func toCamelCase(input string) string {
    12  	var buf bytes.Buffer
    13  
    14  	matched := camelMatcher.FindAllString(input, -1)
    15  
    16  	if matched == nil {
    17  		return ""
    18  	}
    19  
    20  	for i, match := range matched {
    21  		res := match
    22  
    23  		if i > 0 {
    24  			if len(match) > 1 {
    25  				res = strings.ToUpper(match[0:1]) + match[1:]
    26  			} else {
    27  				res = strings.ToUpper(match)
    28  			}
    29  		}
    30  
    31  		buf.WriteString(res)
    32  	}
    33  
    34  	return buf.String()
    35  }