fname

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2023 License: MIT Imports: 8 Imported by: 1

README

fname banner

fname

Generate random, human-friendly names, like determined-pancake or sinister discovery. fname is like a grammatically aware diceware generator for unique names or identifiers.

fname isn't meant to provide a secure, globally unique identifier, but with over 500 billion possible combinations, it's good enough for most non-critical use cases.

Installation

Download

Download the latest release from the releases page.

Go
go install github.com/splode/fname/cmd/fname@latest
Source
git clone https://github.com/splode/fname.git
cd fname
go install ./cmd/fname

Usage

CLI

Generate a single, random name phrase:

$ fname
extinct-green

Generate multiple name phrases, passing the number of names as an argument:

$ fname --quantity 3
influential-length
direct-ear
cultural-storage

Generate a name phrase with a custom delimiter:

$ fname --delimiter "__"
glaring__perception

Generate a name phrase with more words:

$ fname --size 3
vengeful-toy-identified

$ fname --size 4
spellbinding-project-presented-fully

Note: the minimum phrase size is 2 (default), and the maximum is 4.

Specify the seed for generating names:

$ fname --seed 123 --quantity 2
pleasant-joy
eligible-tenant

$ fname --seed 123 --quantity 2
pleasant-joy
eligible-tenant
Library
Install
go get github.com/splode/fname
Basic Usage
package main

import (
  "fmt"

  "github.com/splode/fname"
)

func main() {
  rng := fname.NewGenerator()
  phrase, err := rng.Generate()
  fmt.Println(phrase)
  // => "influential-length"
}
Customization
package main

import (
  "fmt"

  "github.com/splode/fname"
)

func main() {
  rng := fname.NewGenerator(fname.WithDelimiter("__"), fname.WithSize(3))
  phrase, err := rng.Generate()
  fmt.Println(phrase)
  // => "established__shark__destroyed"
}

Disclaimers

fname is not cryptographically secure, and should not be used for anything that requires a truly unique identifier. It is meant to be a fun, human-friendly alternative to UUIDs.

fname's dictionary is curated to exclude words that are offensive, or could be considered offensive, either alone or when generated in a phrase. Nevertheless, all cases are not and cannot be covered. If you find a word that you think should be removed, please open an issue.

License

MIT License

Documentation

Overview

Package fname contains functions for generating random, human-friendly names.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Casing added in v0.2.0

type Casing int
const (
	Lower Casing = iota
	Upper
	Title
)

func CasingFromString added in v0.4.0

func CasingFromString(casing string) (Casing, error)

func (Casing) String added in v0.4.0

func (c Casing) String() string

type Dictionary

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

Dictionary is a collection of words.

func NewDictionary

func NewDictionary() *Dictionary

NewDictionary creates a new dictionary.

func (*Dictionary) LengthAdjective

func (d *Dictionary) LengthAdjective() int

LengthAdjective returns the number of adjectives in the dictionary.

func (*Dictionary) LengthAdverb

func (d *Dictionary) LengthAdverb() int

LengthAdverb returns the number of adverbs in the dictionary.

func (*Dictionary) LengthNoun

func (d *Dictionary) LengthNoun() int

LengthNoun returns the number of nouns in the dictionary.

func (*Dictionary) LengthVerb

func (d *Dictionary) LengthVerb() int

LengthVerb returns the number of verbs in the dictionary.

type Generator

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

func NewGenerator

func NewGenerator(opts ...GeneratorOption) *Generator

NewGenerator creates a new Generator.

func (*Generator) Generate

func (g *Generator) Generate() (string, error)

Generate generates a random name.

type GeneratorOption

type GeneratorOption func(*Generator)

GeneratorOption is a function that configures a Generator.

func WithCasing added in v0.2.0

func WithCasing(casing Casing) GeneratorOption

WithCasing sets the casing used to format the generated name.

func WithDelimiter

func WithDelimiter(delimiter string) GeneratorOption

WithDelimiter sets the delimiter used to join words.

func WithSeed

func WithSeed(seed int64) GeneratorOption

WithSeed sets the seed used to generate random numbers.

func WithSize

func WithSize(size uint) GeneratorOption

WithSize sets the number of words in the generated name.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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