Documentation
¶
Index ¶
- func GetPackageName(directory string) string
- func JoinNonemptyStrings(sep string, s ...string) string
- func NormalizePathItem(s string) string
- func OrderedKeysIter[K cmp.Ordered, V any](m map[K]V) iter.Seq2[K, V]
- func SnakeCase(str string) string
- func ToGoFilePath(pathString string) string
- func ToGolangName(rawString string, exported bool) string
- func Words(str string) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetPackageName ¶
GetPackageName returns the package name as a valid Go identifier extracted from the directory path. If the directory is empty, the function returns "main".
func JoinNonemptyStrings ¶
JoinNonemptyStrings joins non-empty strings with a separator.
func NormalizePathItem ¶ added in v0.3.0
NormalizePathItem converts a string to a valid path item.
The function removes invalid characters from the string, converts it to snake case. If string contains the invalid characters only, it is replaced by hash string of the original string to make it non-empty.
func OrderedKeysIter ¶ added in v0.3.0
OrderedKeysIter returns an iterator over the map's keys and values, in ascending order of the keys.
func ToGoFilePath ¶
ToGoFilePath converts any path-looking string to the valid path to Go source file path and returns it.
If the path is empty, the function returns a constant file name.
While converting, the function shortens the path by eliminating the dot parts, removes invalid characters from every part, converting the rest to snake case. If an item contains invalid characters only, it is replaced by hash string of the original string to make it non-empty. The last part also will have ".go" file extension.
func ToGolangName ¶
ToGolangName converts any string to a valid Golang name. The exported argument determines if the result should be the exported name (start with an uppercase letter) or not.
This function removes the invalid characters from source string, converts it to camel case or pascal case, makes initialisms uppercase, ensuring that the result doesn't conflict with Golang reserved keywords.
func Words ¶ added in v0.4.0
Words splits string into a slice of its words. Implementation initially is taken from github.com/samber/lo.Words and modified to treat digits as part of a word.
Types ¶
This section is empty.