fantasyname

package module
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2023 License: Unlicense Imports: 6 Imported by: 4

README

PkgGoDev License Go Version Tag Mentioned in Awesome Go

CI Go Report Card Maintainability Test Coverage Issues

fantasyname

This is a golang implementation of name generator described at RinkWorks, its based on https://github.com/skeeto/fantasyname code.

example

How it looks like:

import (
    "fmt"
    "log"
    "time"
    "math/rand"

    fn "github.com/s0rg/fantasyname"
)

func main() {
    rand.Seed(time.Now().UnixNano())

    gen, err := fn.Compile("sV'i", fn.Collapse(true), fn.RandFn(rand.Intn))
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(gen.String()) // will print something like: entheu'loaf
}

Here is a full example.

You can run it with go run _example/main.go to see results.

pattern syntax

The letters s, v, V, c, B, C, i, m, M, D, and d represent different types of random replacements:

  • s - generic syllable
  • v - vowel
  • V - vowel or vowel combination
  • c - consonant
  • B - consonant or consonant combination suitable for beginning a word
  • C - consonant or consonant combination suitable anywhere in a word
  • i - insult
  • m - mushy name
  • M - mushy name ending
  • D - consonant suited for a stupid person's name
  • d - syllable suited for a stupid person's name (begins with a vowel)

Everything else is emitted literally.

All characters between parenthesis () are emitted literally. For example, the pattern s(dim), emits a random generic syllable followed by dim.

Characters between angle brackets <> emit patterns from the table above. Imagine the entire pattern is wrapped in one of these.

In both types of groupings, a vertical bar | denotes a random choice. Empty groups are allowed. For example, (foo|bar) emits either foo or bar. The pattern <c|v|> emits a constant, vowel, or nothing at all.

An exclamation point ! means to capitalize the component that follows it. For example, !(foo) will emit Foo and v!s will emit a lowercase vowel followed by a capitalized syllable, like eRod.

Documentation

Overview

Package fantasyname can generate pattern-based strings, that can be used as fantasy characters/places names.

This is free and unencumbered software released into the public domain. This library is based on the RinkWorks Fantasy Name Generator: http://www.rinkworks.com/namegen/.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyStack is returned, if parser counts stack as non-empty, but it was.
	ErrEmptyStack = errors.New("empty stack")
	// ErrInvalidSplit is returned when split - "|" is found in pattern out of any group.
	ErrInvalidSplit = errors.New("invalid split")
	// ErrUnbalancedGroup is returned when stuck upon unexpected group close/open brackets.
	ErrUnbalancedGroup = errors.New("unbalanced group")
)

Functions

func Compile

func Compile(pattern string, opts ...Option) (rv fmt.Stringer, err error)

Compile creates fmt.Stringer from given pattern, you can call it as many times as you wish, it will produce new name on every call.

Types

type Option added in v1.2.0

type Option func(*config)

Option is a configuration func.

func Collapse added in v1.2.0

func Collapse(v bool) Option

Collapse creates option for collapsing doubles in result.

func Dictionary added in v1.3.0

func Dictionary(d map[rune][]string) Option

Dictionary sets custom dictionary (that maps runes to possible strings) for generation.

func RandFn added in v1.2.0

func RandFn(v func(int) int) Option

RandFn creates option with custom random func.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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