slug

package module
v0.0.0-...-5ab8191 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2015 License: BSD-3-Clause Imports: 2 Imported by: 10

README

slug

slug is a package that sanitizes and normalizes strings for use in things like URLs by removing / converting characters that are not in the set [0-9A-Za-z]:

package main

import github.com/stvp/slug

func main() {
  slug.Clean("L'école 24") // "l_ecole_24"
  slug.Clean("\x00\x08clean") // "clean"
}

You can also customize the replacement string:

package main

import github.com/stvp/slug

func main() {
  slug.Replacement = '-'
  slug.Clean("L'école 24") // "l-ecole-24"
}

API docs

Documentation

Overview

Package slug provides utility functions for normalizing strings into "slugs". Slugs are lower-case, sanitized strings that are safe for use in sensitive environments like URLs.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Replace non-alphanumeric characters with this byte.
	Replacement = '_'
)

Functions

func Clean

func Clean(s string) string

Slug replaces each run of characters which are not ASCII letters or numbers with the Replacement character, except for leading or trailing runs. Letters will be stripped of diacritical marks and lowercased. Letter or number codepoints that do not have combining marks or a lower-cased variant will be passed through unaltered.

Types

This section is empty.

Jump to

Keyboard shortcuts

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