naming

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanFileName

func CleanFileName(fileName string) string

CleanFileName accepts a proposed file name like "Foo @ Bar.pdf", and normalizes it to a safe, valid file name like "Foo__Bar.pdf". The rules for normalization are:

- Alphanumeric characters are okay - Underscores are okay - Periods are okay - Hyphens are okay - Whitespace is converted to underscores

func CleanPrefix

func CleanPrefix(ident string) string

CleanPrefix strips the "command-line-arguments." prefix that the Go 'packages' package prepends to type identifier for types defined in the source file we're parsing.

func CleanTypeNameUpper

func CleanTypeNameUpper(typeName string) string

CleanTypeNameUpper normalizes a raw type's name to be a single token name in upper camel case.

func DispositionFileName

func DispositionFileName(contentDisposition string) string

DispositionFileName extracts the "filename" from an HTTP Content-Disposition header value.

func EmptyString

func EmptyString(value string) bool

EmptyString is a predicate that returns true when the input value is "".

func IsPathVariable

func IsPathVariable(token string) bool

IsPathVariable returns true if the given path segment value looks like it's a variable.

IsPathVariable("user") -> false
IsPathVariable(":user") -> false
IsPathVariable("{ID}") -> true
IsPathVariable("{Group.Organization.ID}") -> true

func JoinPackageName

func JoinPackageName(ident string) string

JoinPackageName converts a package-qualified type such as "fmt.Stringer" into a single "safe" identifier such as "fmtStringer". This is useful when converting types to languages with different naming semantics.

func LeadingSlash

func LeadingSlash(value string) string

LeadingSlash adds... a leading slash to the given string.

func NoImport

func NoImport(ident string) string

NoImport strips off the prefix before "/" in your type identifier (e.g. "github.com/foo/bar/Baz" -> "Baz")

func NoPackage

func NoPackage(ident string) string

NoPackage strips of any package prefixes from an identifier (e.g. "context.Context" -> "Context")

func NoPointer

func NoPointer(ident string) string

NoPointer strips off any "*" prefix your type identifier might have (e.g. "*Foo" -> "Foo")

func NoSlice

func NoSlice(ident string) string

NoSlice takes a string like "[]Foo" or "[456]Foo", strips off the slice/array braces, leaving you with "Foo".

func NotEmptyString

func NotEmptyString(value string) bool

NotEmptyString is a predicate that returns true when the input value is anything but "".

func PathTokens

func PathTokens(path string) []string

PathTokens accepts a path string like "foo/bar/baz" and returns a slice of the individual path segment tokens such as ["foo", "bar", "baz"]. This will ignore leading/trailing slashes in your path so that you don't get leading/trailing "" tokens in your slice. This does not, however, clean up empty tokens caused by "//" somewhere in your path.

func PathVariableName

func PathVariableName(pathSegment string) string

PathVariableName returns the raw variable name of the path variable if it actually is a variable (e.g. "{Foo.ID"}" becomes "Foo.ID). If it's not a path variable, then this return "" (e.g "User" -> "").

func ResolvePath

func ResolvePath(path string, delim rune, variableFunc func(string) string) string

ResolvePath accepts a path that potentially includes path variables (e.g. "{ID}) and uses the 'variableFunc' to replace those tokens in the path w/ some runtime value.

ResolvePath("foo/BAR", '/', strings.ToLower) --> "foo/BAR")
ResolvePath("foo/{BAR}", '/', strings.ToLower) --> "foo/bar")

func ToLowerCamel

func ToLowerCamel(value string) string

ToLowerCamel converts the string to lower camel-cased.

func ToUpperCamel

func ToUpperCamel(value string) string

ToUpperCamel converts the string to upper camel-cased.

func TokenizePath

func TokenizePath(path string, delim rune) []string

TokenizePath follows our standard segment/variable naming conventions and splits a path such as "foo/{bar/baz}/goo" or "foo.{bar.baz}.goo" into the slice ["foo", "{bar.baz}", "goo"].

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL