slugme

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: MIT Imports: 5 Imported by: 0

README

slugme

slugme is a golang package to convert any string to it's slug according to some options.

Usage

    import "github.com/colbee1/slugme"

    title := slugme.New(slugme.DefaultOptions)
    slug := title.Slug(" L'oiseau à   deux becs ")
    // l-oiseau-a-deux-becs


    ref := slugme.New(slugme.Options{
        Allowed:  "-+*/",
        Replace:  "",
        KeepCase: true,
    })
    slug = ref.Slug("MF 218 F/A_LIMF 218 FA")
    // MF218F/A_LIMF218FA

Options

  • Allowed (string) List of allowed characters in slug (excluding letters and numbers). Default is "-_".

  • Replace (string) Set the character to use to replace each disallowed characters. Default is "-".

  • KeepCase (bool) Do not convert slug to lower case. Default is false.

  • KeepNonAscii (bool) Do not try to remove diacritics. Default is false.

  • NoShrink (bool) Do not replace repetition of Options.Replace by only one instance. Default is false.

  • NoTrim (bool) Do not trim (begin and end) the slug. Default if false.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	Allowed: "-_",
	Replace: "-",
}

Functions

func New

func New(opt Options) *slugme

func ToASCII

func ToASCII(input string) string

ToASCII removes diacritical characters and replaces them with their ASCII representation

Types

type Options

type Options struct {
	Allowed      string // Allowed symbols in slug in addition to letters (a-Z) and numbers (0-9).
	Replace      string // Replace all disallowed symbols by this one.
	KeepCase     bool   // Do not lower case the slug
	KeepNonAscii bool   // Do not try to convert letters to ASCII7, aka: do not remove diacritics.
	NoShrink     bool   // Do not shrink repetition of Replace char.
	NoTrim       bool   // Do not trim slug start/end for Replace character.
}

Jump to

Keyboard shortcuts

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