github.com/clubpay/ronykit/kit@v0.14.4-0.20240515065620-d0dace45cbc7/internal/tpl/tpl.go (about) 1 package tpl 2 3 import ( 4 _ "embed" 5 "fmt" 6 "strings" 7 "text/template" 8 9 "github.com/clubpay/ronykit/kit/utils" 10 ) 11 12 var ( 13 //go:embed go/stub.gotmpl 14 goFileStub string 15 GoStub *template.Template 16 17 //go:embed ts/stub.tstmpl 18 tsFileStub string 19 TsStub *template.Template 20 ) 21 22 func init() { 23 GoStub = template.Must(template.New("stub").Funcs(funcMaps).Parse(goFileStub)) 24 TsStub = template.Must(template.New("stub").Funcs(funcMaps).Parse(tsFileStub)) 25 } 26 27 var funcMaps = map[string]any{ 28 "strQuote": func(elems []string) []string { 29 out := make([]string, len(elems)) 30 for i, e := range elems { 31 out[i] = fmt.Sprintf("%q", e) 32 } 33 34 return out 35 }, 36 "strJoin": strings.Join, 37 "strSplit": strings.Split, 38 "strReplace": strings.ReplaceAll, 39 "toUpper": strings.ToUpper, 40 "toLower": strings.ToLower, 41 "toTitle": strings.ToTitle, 42 "toUTF8": strings.ToValidUTF8, 43 "lowerCamelCase": utils.ToLowerCamel, 44 "camelCase": utils.ToCamel, 45 "kebabCase": utils.ToKebab, 46 "snakeCase": utils.ToSnake, 47 "screamSnakeCase": utils.ToScreamingSnake, 48 "randomID": utils.RandomID, 49 "randomDigit": utils.RandomDigit, 50 "randomInt": utils.RandomInt64, 51 52 "goType": goType, 53 "tsType": tsType, 54 "tsReplacePathParams": tsReplacePathParams, 55 "strAppend": strAppend, 56 "strEmptySlice": strEmptySlice, 57 }