Documentation
¶
Overview ¶
Package name provides functionality for handling the URL path of a releaser. It contains a type Path that represents the URL path of a releaser and methods to validate and retrieve the well-known styled name of the releaser. It also contains a map of releasers and their well-known styled names.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidPath = errors.New("the path contains invalid characters")
Functions ¶
func Humanize ¶
Humanize deobfuscates the URL path and returns the formatted, human-readable group name. If the URL path contains invalid characters then an error is returned.
Example ¶
package main import ( "fmt" "github.com/Defacto2/releaser/name" ) func main() { s, _ := name.Humanize("defacto2") fmt.Println(s) s, _ = name.Humanize("razor-1911-demo") fmt.Println(s) s, _ = name.Humanize("razor-1911-demo*trsi") fmt.Println(s) }
Output: defacto2 razor 1911 demo razor 1911 demo, trsi
Example (Error) ¶
package main import ( "fmt" "github.com/Defacto2/releaser/name" ) func main() { _, err := name.Humanize("razor-1911-demo#trsi") if err != nil { fmt.Println(err) } }
Output: the path contains invalid characters
Types ¶
type List ¶
A List is a map of releasers and their well-known styled names.
Example ¶
package main import ( "fmt" "github.com/Defacto2/releaser/name" ) func main() { uri := "defacto2net" for key, val := range name.Names() { if key == name.Path(uri) { fmt.Println(val) } } }
Output: Defacto2 website
func Special ¶
func Special() List
Special returns the list of styled names that use special mix or all lower or upper casing.
Example ¶
package main import ( "fmt" "github.com/Defacto2/releaser/name" ) func main() { find := name.Path("surprise-productions") for key, val := range name.Special() { if key == find { fmt.Println(val) } } }
Output: Surprise! Productions
type Path ¶
type Path string
A Path is the partial URL path of the releaser.
func Obfuscate ¶
Obfuscate formats the named string to be used as a URL path.
Example:
string(Obfuscate("ACiD Productions")) = "acid-productions" string(Obfuscate("Razor 1911 Demo & Skillion")) = "razor-1911-demo-ampersand-skillion" string(Obfuscate("TDU-Jam!")) = "tdu_jam"
Example ¶
package main import ( "fmt" "github.com/Defacto2/releaser/name" ) func main() { obf := name.Obfuscate("ACiD Productions") if !obf.Valid() { fmt.Println("invalid") } else { fmt.Println(string(obf)) } }
Output: acid-productions
func (Path) String ¶
String returns the well-known styled name of the releaser if it exists in the names, lowercase or uppercase lists. Otherwise it returns an empty string.
Example:
name.Path("acid-productions").String() = "ACiD Productions" name.Path("razor-1911").String() = "" // unlisted
Example ¶
package main import ( "fmt" "github.com/Defacto2/releaser/name" ) func main() { fmt.Println(name.Path("acid-productions").String()) }
Output: ACiD Productions
Example (Unlisted) ¶
package main import ( "fmt" "github.com/Defacto2/releaser/name" ) func main() { s := name.Path("defacto2").String() fmt.Println(len(s)) }
Output: 0
func (Path) Valid ¶
Valid returns true if the URL path uses valid characters. Valid URL paths are all lowercase and contain only alphanumeric characters, dashes, underscores, ampersands and asterisks.
Example:
name.Path("acid-productions").Valid() = true name.Path("acid-productions!").Valid() = false
Example ¶
package main import ( "fmt" "github.com/Defacto2/releaser/name" ) func main() { fmt.Println(name.Path("defacto2").Valid()) fmt.Println(name.Path("Defacto2").Valid()) }
Output: true false