coolname

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: Apache-2.0 Imports: 5 Imported by: 1

README

Random name and slug generator

coolname is a Golang port of a Python package by Alexander Lukanin. All hard work of creating and maintaing word lists happens upstream.

Documentation

See package docs at pkg.go.dev

Installation

$ go get github.com/sio/coolname

Usage

Importing the package
import "github.com/sio/coolname"
Generating cool names
>>> coolname.Slug()
"vegan-outrageous-bumblebee-of-discourse"
nil

>>> coolname.SlugN(2)
"crimson-caracal"
nil

>>> coolname.Generate()
[]string{
  "kind",
  "romantic",
  "markhor",
  "of",
  "luxury",
}
nil
Advanced configuration

Several tunable knobs are provided, check the docs and source code to be able to:

  • Provide custom word lists
  • Create new lists by combining existing ones via plain concatenation or via cartesian product (see config.json, custom JSON inputs are supported!)
  • Use custom random number generator
Golang port (this package)

Copyright 2023 Vitaly Potyarkin, Apache-2.0 License

Word lists and JSON config

Copyright 2015-2023 Alexander Lukanin and contributors, BSD-2-Clause License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Generate     = defaultGenerator.Generate
	GenerateN    = defaultGenerator.GenerateN
	GenerateFrom = defaultGenerator.GenerateFrom
	Slug         = defaultGenerator.Slug
	SlugN        = defaultGenerator.SlugN
	SlugFrom     = defaultGenerator.SlugFrom
)

Functions

This section is empty.

Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

coolname generator

Zero value is perfectly usable (will load default configuration)

Tunable knobs:

  • After instanciation user may provide custom configuration and word list via Configure() method
  • User may also override the default dictionary name (ReplaceDefaultDict) and random number generator (ReplaceRandom)

func (*Generator) Configure

func (g *Generator) Configure(conf *data.Config, words *data.WordCollection) (err error)

Load configuration. Calling this method is not required if default word collection is OK for you

func (*Generator) Generate

func (g *Generator) Generate() (words []string, err error)

Return a slice of random words (most likely will result in length of 4)

func (*Generator) GenerateFrom

func (g *Generator) GenerateFrom(dictionary string) (words []string, err error)

Return a random word combination from dictionary specified by name

Valid dictionary names are top level keys from config.json

func (*Generator) GenerateN

func (g *Generator) GenerateN(count int) (words []string, err error)

Return a slice of N random words

Prepositions and articles (of, from, the) are not counted as words, so the resulting slice may contain more elements than `count`

Currently only dictionaries for 2, 3 and 4 words are defined upstream (see config.json)

func (*Generator) ReplaceDefaultDict

func (g *Generator) ReplaceDefaultDict(name string)

Set dictionary name to be used by Slug() and Generate()

Default: "all"

func (*Generator) ReplaceRandom

func (g *Generator) ReplaceRandom(r func(max int) int)

Provide a custom random number generator

The function `r` must return integer values from a half-open interval [0, max) for any non-negative `max` value

Default: math/rand::IntN()

func (*Generator) Slug

func (g *Generator) Slug() (slug string, err error)

Generate URL safe slug

func (*Generator) SlugFrom

func (g *Generator) SlugFrom(dictionary string) (slug string, err error)

Generate URL safe slug from a given dictionary (see GenerateFrom)

func (*Generator) SlugN

func (g *Generator) SlugN(count int) (slug string, err error)

Generate URL safe slug with specified amount of meaningful words (see GenerateN)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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