Skip to content

theTardigrade/golang-slug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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