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: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
⌂ 换网址