randname

package module
v0.0.0-...-d5b0f28 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2018 License: MIT Imports: 12 Imported by: 35

README

randname

Build Status

A Go package which creates random names with an emphasis on flexibility and ease of use.

Contributing

Feel free to send PRs my way! Just make sure that your code passes golint and go test. If you add any publicly exported methods, please document them.

Documentation

Index

Examples

Constants

View Source
const PrefixedDefaultLen = uint8(6)

PrefixedDefaultLen is the number of characters that will be appended to a suffix if no length was specified.

Variables

View Source
var ArabicNumerals = []rune{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}

ArabicNumerals contains the numeric digits 0-9.

View Source
var LowercaseAlphabet = []rune{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}

LowercaseAlphabet contains each letter of the alphaber, in lowercase.

View Source
var PrefixedDefaultAcceptable = append(append(append([]rune{}, ArabicNumerals...), UppercaseAlphabet...), LowercaseAlphabet...)

PrefixedDefaultAcceptable contains the characters that will be tacked onto the end of the Prefix, if none were provided.

View Source
var SpecialCharacters = []rune{'^', '$', '#', '*', '(', ')', '%', '@'}

SpecialCharacters holds a host of standard special characters.

View Source
var UppercaseAlphabet = []rune{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}

UppercaseAlphabet contains each letter of the alphabet, in uppercase.

Functions

func Generate

func Generate() string

generate fetches a random name of the default format and strategy.

func GenerateCamelCaseAdjNoun

func GenerateCamelCaseAdjNoun(adjective, noun string, digit int) string

GenerateCamelCaseAdjNoun formats an adjective, noun, and digit in the following way: bigCloud9

func GenerateHyphenedAdjNoun

func GenerateHyphenedAdjNoun(adjective, noun string, digit int) string

GenerateHyphenedAdjNoun formats an adjective, noun, and digit in the following way: big-cloud-9

func GeneratePascalCaseAdjNoun

func GeneratePascalCaseAdjNoun(adjective, noun string, digit int) string

GeneratePascalCaseAdjNoun formats an adjective, noun, and digit in the following way: BigCloud9

func GenerateWithPrefix

func GenerateWithPrefix(prefix string, characters uint8) string

GenerateWithPrefix generates a string with a given prefix then a given number of randomly selected characters.

Example
package main

import (
	"fmt"

	"github.com/marstr/randname"
)

func main() {
	for i := 0; i < 10; i++ {
		fmt.Println(randname.GenerateWithPrefix("randname-", 10))
	}
}
Output:

Types

type AdjNoun

type AdjNoun struct {
	Adjectives    *collection.Dictionary
	Format        AdjNounFormat
	Nouns         *collection.Dictionary
	RandGenerator io.Reader
}

AdjNoun creates a random name of the form adjectiveNameDigit

func NewAdjNoun

func NewAdjNoun() *AdjNoun

NewAdjNoun creates a new instance of AdjNoun that is populated with all of the defaults.

func (AdjNoun) Generate

func (adNoun AdjNoun) Generate() string

Generate creates a new randomly generated name with the

type AdjNounFormat

type AdjNounFormat func(string, string, int) string

AdjNounFormat is a type of function that aggregates an Adjective, Noun, and Digit into a single formatted string.

type FileDictionaryBuilder

type FileDictionaryBuilder struct {
	Target string
}

FileDictionaryBuilder read words from a file.

func (FileDictionaryBuilder) Build

func (fdb FileDictionaryBuilder) Build(dict *collection.Dictionary) (err error)

Build walks a simple newline delimited file of words and populates a dictionary with them.

type Prefixed

type Prefixed struct {
	Prefix        string
	Acceptable    []rune
	Len           uint8
	RandGenerator io.Reader
}

Prefixed offers a means of generating a random name by providing a prefix, followed by a number of random letters or numbers.

Example
package main

import (
	"fmt"

	"github.com/marstr/randname"
)

func main() {
	generator := randname.Prefixed{
		Prefix:     "randname-",
		Acceptable: randname.ArabicNumerals,
		Len:        10,
	}

	for i := 0; i < 10; i++ {
		fmt.Println(generator.Generate())
	}
}
Output:

func (Prefixed) Generate

func (p Prefixed) Generate() string

Generate creates a string starting with a prefix, and ending with an assortment of randomly chosen runes.

Example
package main

import (
	"fmt"

	"github.com/marstr/randname"
)

func main() {
	generator := randname.Prefixed{
		Prefix: "randnameRocks",
	}
	fmt.Println(generator.Generate())
}
Output:

Jump to

Keyboard shortcuts

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