/golang-slug

Go package that generates slugs from text

Primary LanguageGoGNU General Public License v3.0GPL-3.0

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)
	}

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

	result, err = slug.GetRandomWithOptions(&slug.Options{
		MaxLen: 20,
	})
	if err != nil {
		panic(err)
	}

	// prints slug made up of twenty randomly selected
	// uppercase letters, lowercase letters and digits
	fmt.Println(result)
}

Support

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

ko-fi