nanoid

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 2 Imported by: 1

README

NanoID Generator

Installation

go get -u github.com/metadiv-io/nanoid

Generate NanoID

uuid := nanoid.New(&nanoid.Opt{
    Numbers: true, // 0123456789
    Lowercase: true, // abcdefghijklmnopqrstuvwxyz
    Uppercase: true, // ABCDEFGHIJKLMNOPQRSTUVWXYZ
    Symbols: true, // _-
    Length: 21, // must be greater than 0
    ExcludeAlike: true, // exclude alike characters: 1lI0Oouv5Ss
})

Safe Generate NanoID

Generate NanoID with safe characters:

  1. Numbers
  2. Lowercase
  3. Uppercase
  4. Exclude Symbols
  5. Exclude Alike Characters
  6. Length: 21
uuid := nanoid.NewSafe()

Documentation

Index

Constants

View Source
const (
	CHARACTERS_NUMBERS    = "0123456789"
	CHARACTERS_LOWERCASE  = "abcdefghijklmnopqrstuvwxyz"
	CHARACTERS_UPPERCASE  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	CHARACTERS_SYMBOLS    = "_-"
	CHARACTERS_LOOK_ALIKE = "1lI0Oouv5Ss"

	SAFE_LENGTH = 21
)

Variables

This section is empty.

Functions

func New

func New(opts Opts) string

New returns a random string with the given options.

func NewSafe

func NewSafe() string

NewSafe quickly returns a random string with the safe options.

Types

type Opts added in v1.1.0

type Opts struct {
	Numbers   bool
	Lowercase bool
	Uppercase bool
	/*
		Symbols are "_-"
	*/
	Symbols bool
	/*
		LookAlike are "1lI0Oouv5Ss"
	*/
	ExcludeAlike bool
	Length       int
}

Jump to

Keyboard shortcuts

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