-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,5 @@ go.work.sum | |
|
||
# env file | ||
.env | ||
|
||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package namingo | ||
|
||
var adjectives = []string{ | ||
"brave", "mighty", "dark", "ancient", "mysterious", "powerful", "swift", "noble", "fearless", "wise", | ||
"loyal", "ferocious", "legendary", "majestic", "stealthy", "elegant", "fearsome", "dangerous", "bold", "sly", | ||
"heroic", "cunning", "ruthless", "noble", "savage", "swift", "honorable", "sly", "gallant", "fierce", | ||
"brilliant", "fearless", "reliable", "unforgiving", "energetic", "formidable", "resilient", "unstoppable", | ||
"mighty", "crafty", "heroic", "brave", "resolute", "tactical", "adventurous", "brilliant", "dedicated", | ||
"charismatic", "mysterious", "unwavering", "legendary", "reliable", "stealthy", "daring", "persevering", | ||
"tenacious", "brave", "resolute", "sensitive", "vigilant", "shrewd", "determined", "strong", | ||
"courageous", "noble", "unbreakable", "mystic", "fiery", "resilient", "evasive", "unpredictable", | ||
"fearsome", "intrepid", "adventurous", "shrewd", "talented", "resourceful", "skilled", | ||
"unstoppable", "daring", "precise", "dynamic", "creative", "strategic", "dedicated", "valiant", "ambitious", | ||
"proud", "focused", "resilient", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"github.com/sanchitrk/namingo" | ||
) | ||
|
||
var ( | ||
words = flag.Int("w", 1, "Number of words in the name") | ||
sep = flag.String("sep", " ", "Separator between words") | ||
transform = flag.String("case", "title", "Case of the generated name") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
fmt.Println(namingo.Generate(*words, *sep, *transform)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/sanchitrk/namingo | ||
|
||
go 1.23.0 | ||
|
||
require golang.org/x/text v0.18.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= | ||
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package namingo | ||
|
||
import ( | ||
"golang.org/x/text/cases" | ||
"golang.org/x/text/language" | ||
"math/rand" | ||
) | ||
|
||
const ( | ||
title = "title" | ||
upper = "upper" | ||
lower = "lower" | ||
) | ||
|
||
func Adjective() string { | ||
return adjectives[rand.Intn(len(adjectives))] | ||
} | ||
|
||
func Name() string { | ||
return nouns[rand.Intn(len(nouns))] | ||
} | ||
|
||
func DefaultCase() string { | ||
return lower | ||
} | ||
|
||
func UpperCase() string { | ||
return upper | ||
} | ||
|
||
func LowerCase() string { | ||
return lower | ||
} | ||
|
||
func TitleCase() string { | ||
return title | ||
} | ||
|
||
// Generate generates a random name | ||
// Takes a number of words and a separator | ||
// If a single word is requested, it will return a name | ||
// If more than one word is requested, it will return an adjective + name | ||
func Generate(words int, sep string, tf string) string { | ||
var rs string | ||
if words == 1 { | ||
rs = Name() | ||
} | ||
rs = Adjective() + sep + Name() | ||
|
||
switch tf { | ||
case "": // if no case is specified, use lowercase as default | ||
c := cases.Lower(language.English) | ||
rs = c.String(rs) | ||
case upper: | ||
c := cases.Upper(language.English) | ||
rs = c.String(rs) | ||
case lower: | ||
c := cases.Lower(language.English) | ||
rs = c.String(rs) | ||
case title: | ||
c := cases.Title(language.English) | ||
rs = c.String(rs) | ||
default: // defaults to lowercase | ||
c := cases.Lower(language.English) | ||
rs = c.String(rs) | ||
} | ||
return rs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package namingo | ||
|
||
import "testing" | ||
|
||
func TestGenerateAll(t *testing.T) { | ||
for i := 0; i < 100; i++ { | ||
name := Generate(1, " ", "") | ||
if name == "" { | ||
t.Error("Name should not be empty") | ||
} | ||
t.Log(name) | ||
name = Generate(2, " ", "") | ||
if name == "" { | ||
t.Error("Name should not be empty") | ||
} | ||
t.Log(name) | ||
} | ||
} | ||
|
||
func TestGenerateWithNoCase(t *testing.T) { | ||
// default case is lowercase | ||
name := Generate(1, " ", "") | ||
if name == "" { | ||
t.Error("Name should not be empty") | ||
} | ||
//t.Log(name) | ||
name = Generate(2, " ", "") | ||
if name == "" { | ||
t.Error("Name should not be empty") | ||
} | ||
t.Log(name) | ||
} | ||
|
||
func TestGenerateWithDefaultCase(t *testing.T) { | ||
name := Generate(1, " ", DefaultCase()) | ||
if name == "" { | ||
t.Error("Name should not be empty") | ||
} | ||
name = Generate(2, " ", DefaultCase()) | ||
if name == "" { | ||
t.Error("Name should not be empty") | ||
} | ||
} | ||
|
||
func TestGenerateWithUpperCase(t *testing.T) { | ||
name := Generate(1, " ", UpperCase()) | ||
if name == "" { | ||
t.Error("Name should not be empty") | ||
} | ||
t.Log(name) | ||
name = Generate(2, " ", UpperCase()) | ||
if name == "" { | ||
t.Error("Name should not be empty") | ||
} | ||
t.Log(name) | ||
} | ||
|
||
func TestGenerateWithLowerCase(t *testing.T) { | ||
name := Generate(1, " ", LowerCase()) | ||
if name == "" { | ||
t.Error("Name should not be empty") | ||
} | ||
t.Log(name) | ||
name = Generate(2, " ", LowerCase()) | ||
if name == "" { | ||
t.Error("Name should not be empty") | ||
} | ||
t.Log(name) | ||
} | ||
|
||
func TestGenerateWithTitleCase(t *testing.T) { | ||
name := Generate(1, " ", TitleCase()) | ||
if name == "" { | ||
t.Error("Name should not be empty") | ||
} | ||
t.Log(name) | ||
name = Generate(2, " ", TitleCase()) | ||
if name == "" { | ||
t.Error("Name should not be empty") | ||
} | ||
t.Log(name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package namingo | ||
|
||
var nouns = []string{ | ||
"luke", "vader", "leia", "yoda", "obi-wan", "chewbacca", "han", "palpatine", "r2-d2", "c-3po", | ||
"tatooine", "hoth", "dagobah", "alderaan", "endor", "coruscant", "naboo", "kamino", "geonosis", "jakku", | ||
"stormtrooper", "sith", "jedi", "droid", "ewok", "clone", "bounty hunter", "lightsaber", "blaster", | ||
"starfighter", "x-wing", "tie fighter", "millennium falcon", "death star", "boba fett", "jango fett", | ||
"padmé", "mace windu", "kylo ren", "rey", "snoke", "finn", "poe dameron", "anakin", "grievous", "count dooku", | ||
"darth maul", "qui-gon jinn", "ahsoka", "lothal", "bespin", "kessel", "mustafar", "scarif", "jedha", | ||
"corellia", "ackbar", "lando", "wedge", "tarkin", "greedo", "maz kanata", "jabba", "watto", | ||
"bossk", "ig-88", "rancor", "sarlaac", "nien nunb", "mon mothma", "wampa", "tauntaun", "bantha", | ||
"dewback", "rathtar", "porg", "porgs", "gungan", "geonosian", "zabrak", "twilek", "mandalorian", "hutt", | ||
"kaminoan", "mon calamari", "rodian", "trandoshan", "chiss", "vibroblade", "holocron", "kyber crystal", | ||
"gungan", "jawas", "sandcrawler", "sith lord", "jedi knight", "jedi council", "force", "dark side", "light side", | ||
} |