Documentation
¶
Overview ¶
Package nicename provides lightweight, thread-safe generators for memorable, human-friendly random names, URL slugs, and unique task identifiers.
Index ¶
- Variables
- func FormatTaskID(slug string) string
- func GenerateAardman() string
- func GenerateAardmanCharacter() string
- func GenerateAardmanSlug() string
- func GenerateCustom(adjectives []string, nouns []string, separator string, toSlug bool) string
- func GeneratePair() string
- func GeneratePairSlug() string
- func GenerateTaskID() string
- func Slugify(s string) string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var AardmanAdjectives = []string{
"Astute",
"Audacious",
"Barmy",
"Brave",
"Breezy",
"Brilliant",
"Bumbling",
"Cheesy",
"Chirpy",
"Chubby",
"Clever",
"Crafty",
"Cracking",
"Daft",
"Dapper",
"Daring",
"Dashing",
"Eccentric",
"Fearless",
"Feathered",
"Gallant",
"Grand",
"Gullible",
"Heroic",
"Industrious",
"Ingenious",
"Inventive",
"Jolly",
"Loyal",
"Mechanical",
"Mellow",
"Mischievous",
"Nifty",
"Noble",
"Plucky",
"Posh",
"Quirky",
"Resilient",
"Resourceful",
"Shifty",
"Smashing",
"Snazzy",
"Spiffy",
"Spirited",
"Splendid",
"Sprightly",
"Stealthy",
"Ticklish",
"Tireless",
"Toasty",
"Tricky",
"Unflappable",
"Valiant",
"Vigilant",
"Whimsical",
"Wobbly",
"Woolly",
"Zippy",
}
AardmanAdjectives contains spirited, eccentric, and charming adjectives celebrating Wallace & Gromit and classic British colloquialisms.
var AardmanCharacters = []string{
"Wallace",
"Gromit",
"Feathers McGraw",
"Wendolene Ramsbottom",
"Shaun the Sheep",
"Preston the Cyberdog",
"Lady Campanula Tottington",
"Lord Victor Quartermaine",
"Philip the Dog",
"Piella Bakewell",
"Fluffles",
"The Cooker",
"PC Mackintosh",
"Hutch the Rabbit",
"Reverend Clement Hedges",
"Norbot the Smart Gnome",
"Major Crum",
"Mr Caliche",
"Ginger",
"Rocky Rhodes",
"Fowler",
"Babs",
"Bunty",
"Mac",
"Nick and Fetcher",
"Mrs Tweedy",
"Mr Tweedy",
"Molly",
"Frizzle",
"Morph",
"Chas",
"Delilah",
"Grandmorph",
"Gillespie",
"Nailbrush",
"Bitzer",
"The Farmer",
"Shirley",
"Timmy",
"The Naughty Pigs",
"Slip",
"Agent Trumper",
"Lu-La",
"Frank the Tortoise",
"Rex the Dog",
"Pickles the Pug",
"Trixie",
"Roddy St James",
"Rita Malone",
"The Toad",
"Whitey",
"Spike",
"Le Frog",
"Sid",
"The Pirate Captain",
"Pirate with a Scarf",
"Albino Pirate",
"Pirate with Gout",
"Surprisingly Curvaceous Pirate",
"Polly the Dodo",
"Charles Darwin",
"Mr Bobo",
"Queen Victoria",
"Dug",
"Hognob",
"Goona",
"Lord Nooth",
"Treebor",
"Robin",
"Magpie",
"Cat",
"Dad Mouse",
}
AardmanCharacters contains memorable characters from the Wallace & Gromit and Aardman Animations filmography (Chicken Run, Morph, Shaun the Sheep, etc.).
var AardmanInventions = []string{
"Techno Trousers",
"Knit-o-matic",
"Snoozatron",
"Bun-vac 6000",
"Anti-Pesto Van",
"Rocket Ship",
"Porridge Gun",
"Autochef",
"Tellyscope",
"Wensleydale",
"Red Leicester",
"Stinking Bishop",
"Smashing Cheddar",
"Cracking Toast",
"West Wallaby Street",
"Top Bun Bakery",
"The Wrong Trousers",
"A Grand Day Out",
"A Close Shave",
"A Matter of Loaf and Death",
"The Curse of the Were-Rabbit",
"Vengeance Most Fowl",
}
AardmanInventions contains famous contraptions, locations, and iconic cheeses from 62 West Wallaby Street and beyond.
var AardmanNouns = append(append([]string{}, AardmanCharacters...), AardmanInventions...)
AardmanNouns combines all Aardman characters and inventions.
var First = []string{}/* 393 elements not displayed */
First contains a classic list of adjectives used for GeneratePair and GeneratePairSlug.
var Second = []string{}/* 4275 elements not displayed */
Second contains a classic list of names used for GeneratePair and GeneratePairSlug.
Functions ¶
func FormatTaskID ¶
FormatTaskID appends a 4-hex collision-resistant suffix to any given slug. If slug is empty, only the random hex suffix is returned without leading hyphens.
Example ¶
package main
import (
"fmt"
"strings"
"github.com/dreh23/nicename"
)
func main() {
taskID := nicename.FormatTaskID("custom-worker-task")
// Output will be something like "custom-worker-task-8f2a"
fmt.Println(strings.HasPrefix(taskID, "custom-worker-task-"))
}
Output: true
func GenerateAardman ¶
func GenerateAardman() string
GenerateAardman generates a spirited Aardman / Wallace & Gromit themed pair (e.g. "Cracking Gromit", "Cheesy Techno Trousers").
Example ¶
package main
import (
"fmt"
"github.com/dreh23/nicename"
)
func main() {
aardman := nicename.GenerateAardman()
// Output will be something like "Cracking Gromit"
fmt.Println(aardman != "")
}
Output: true
func GenerateAardmanCharacter ¶
func GenerateAardmanCharacter() string
GenerateAardmanCharacter generates a pair pairing an adjective with a specific character from the Aardman universe (e.g. "Clever Feathers McGraw").
func GenerateAardmanSlug ¶
func GenerateAardmanSlug() string
GenerateAardmanSlug generates a URL- and Git-branch-friendly slug from the Aardman dataset (e.g. "cracking-gromit", "plucky-feathers-mcgraw").
Example ¶
package main
import (
"fmt"
"strings"
"github.com/dreh23/nicename"
)
func main() {
slug := nicename.GenerateAardmanSlug()
// Output will be something like "cracking-gromit"
fmt.Println(strings.Contains(slug, "-"))
}
Output: true
func GenerateCustom ¶
GenerateCustom picks an adjective and a noun from custom slices, joining them with separator.
Example ¶
package main
import (
"fmt"
"strings"
"github.com/dreh23/nicename"
)
func main() {
adjectives := []string{"Grand", "Smashing"}
nouns := []string{"Contraption", "Rocket"}
name := nicename.GenerateCustom(adjectives, nouns, "-", true)
// Returns lowercase slug joined by hyphen
fmt.Println(strings.HasPrefix(name, "grand-") || strings.HasPrefix(name, "smashing-"))
}
Output: true
func GeneratePair ¶
func GeneratePair() string
GeneratePair generates a classic random adjective + name pair from the original dataset (e.g. "Adventurous Mary"). Preserves full backwards compatibility.
Example ¶
package main
import (
"fmt"
"strings"
"github.com/dreh23/nicename"
)
func main() {
pair := nicename.GeneratePair()
// Output will be something like "Adventurous Mary"
fmt.Println(len(strings.Split(pair, " ")) >= 2)
}
Output: true
func GeneratePairSlug ¶
func GeneratePairSlug() string
GeneratePairSlug generates a lowercase, kebab-cased slug from the original dataset (e.g. "adventurous-mary").
func GenerateTaskID ¶
func GenerateTaskID() string
GenerateTaskID returns a unique, collision-resistant identifier ideal for worker tasks, git branches, and container names (e.g. "cracking-gromit-8f2a").
Example ¶
package main
import (
"fmt"
"github.com/dreh23/nicename"
)
func main() {
taskID := nicename.GenerateTaskID()
// Output will be something like "cracking-gromit-8f2a"
fmt.Println(len(taskID) > 5)
}
Output: true
func Slugify ¶
Slugify converts any string into a clean lowercase, hyphen-separated slug, stripping special punctuation while preserving alphanumeric words.
Example ¶
package main
import (
"fmt"
"github.com/dreh23/nicename"
)
func main() {
fmt.Println(nicename.Slugify("Feathers McGraw"))
fmt.Println(nicename.Slugify("Bun-vac 6000"))
fmt.Println(nicename.Slugify(" Cracking Toast! "))
}
Output: feathers-mcgraw bun-vac-6000 cracking-toast
Types ¶
This section is empty.