nanoid

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

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

Go to latest
Published: Mar 30, 2024 License: MIT Imports: 4 Imported by: 0

README

NanoID

NanoID is a lightweight/developer-friendly Go library for generating unique IDs.

Installation

To use NanoID in your Go project, simply run:

go get github.com/ephemeralforge/nanoid

Usage

package main

import (
	"fmt"
	"github.com/ephemeralforge/nanoid"
)

func main() {
	id, err := nanoid.New()
	if err != nil {
		fmt.Println("Error generating NanoID:", err)
		return
	}
	fmt.Println("Generated NanoID:", id.String())
}

Documentation

Index

Constants

View Source
const CanonicNanoIDLenght = 21

Variables

View Source
var ErrInvalidByte = errors.New("invalid byte reading")

Functions

func WithAlphabet

func WithAlphabet(alphabet Alphabet) func(*Option) *Option

func WithLength

func WithLength(length int) func(*Option) *Option

Types

type Alphabet

type Alphabet []rune
var CanonicAlphabet Alphabet = []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', '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', '0', '1', '2',
	'3', '4', '5', '6', '7',
	'8', '9', '-', '_',
}

func AlphabetFromString

func AlphabetFromString(s string) Alphabet

type NanoID

type NanoID []rune

func Must

func Must(id NanoID, err error) NanoID

func New

func New(options ...func(*Option) *Option) (NanoID, error)

func Parse

func Parse[T any](id T, options ...func(*Option) *Option) (NanoID, error)

func ParseFromString

func ParseFromString(id string, options ...func(*Option) *Option) (NanoID, error)

func (*NanoID) String

func (n *NanoID) String() string

type Option

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

Jump to

Keyboard shortcuts

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