Skip to content

Commit

Permalink
initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchitrk committed Sep 10, 2024
1 parent 13c0e07 commit 4e39590
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ go.work.sum

# env file
.env

.idea/
15 changes: 15 additions & 0 deletions adjectives.go
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",
}
18 changes: 18 additions & 0 deletions cmd/cli.go
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))
}
5 changes: 5 additions & 0 deletions go.mod
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
2 changes: 2 additions & 0 deletions go.sum
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=
68 changes: 68 additions & 0 deletions namingo.go
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
}
82 changes: 82 additions & 0 deletions namingo_test.go
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)
}
15 changes: 15 additions & 0 deletions nouns.go
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",
}

0 comments on commit 4e39590

Please sign in to comment.