slug

package module
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: GPL-2.0 Imports: 7 Imported by: 0

README

golang-slug

This Go package makes it easy to generate slugs from human-readable text.

Go Reference Go Report Card

Example

package main

import (
	"fmt"

	slug "github.com/theTardigrade/golang-slug"
)

func main() {
	defaultOptions := slug.NewOptionsWithDefaults()
	result, err := slug.GetWithOptions("!=this is the text's slug=!", &slug.Options{
		WholeWords:    false,
		MaxLen:        20,
		Replacement:   "_",
		RunesToRemove: defaultOptions.RunesToRemove,
	})
	if err != nil {
		panic(err)
	}

	fmt.Println(result) // prints "this_is_the_texts_sl"
}

Support

If you use this package, or find any value in it, please consider donating:

ko-fi

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUniqueAttempts = errors.New("too many unique slugs attempted with no success")
	ErrUniqueLength   = errors.New("not enough length to make all unique attempts")
)

Functions

func Get

func Get(text string) (slug string, err error)

func GetWithOptions

func GetWithOptions(text string, options *Options) (slug string, err error)

Types

type Options

type Options struct {
	MaxLen         int
	Replacement    string
	RunesToRemove  []rune
	WholeWords     bool
	Unique         bool
	UniqueAttempts int
}

func NewOptionsWithDefaults added in v1.4.0

func NewOptionsWithDefaults() *Options

Jump to

Keyboard shortcuts

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