name

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: BSD-2-Clause Imports: 3 Imported by: 3

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

View Source
var ErrInvalidPath = errors.New("the path contains invalid characters")

Functions

func Humanize

func Humanize(path Path) (string, error)

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)

	x, err := name.Humanize("razor-1911-demo#trsi")
	fmt.Printf("%q, %s\n", x, err) // print the quoted x string and any error

}
Output:

defacto2
razor 1911 demo
razor 1911 demo, trsi
"", the path contains invalid characters

Types

type List

type List map[Path]string

A List is a map of releasers and their well-known styled names.

func Lower

func Lower() List

Lower returns the list of styled names that use all lowercasing.

func Names

func Names() List

Names returns the list of well-known styled names.

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

func Upper

func Upper() List

Upper returns the list of styled names that use all uppercasing.

type Path

type Path string

A Path is the partial URL path of the releaser.

func Obfuscate

func Obfuscate(name string) Path

Obfuscate formats the named string to be used as a URL path.

Example:

Obfuscate("ACiD Productions") = "acid-productions"
Obfuscate("Razor 1911 Demo & Skillion") = "razor-1911-demo-ampersand-skillion"
Obfuscate("TDU-Jam!") = "tdu_jam"

func (Path) String

func (path Path) String() 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

func (Path) Valid

func (path Path) Valid() bool

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

Jump to

Keyboard shortcuts

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