slugify

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2017 License: MIT Imports: 3 Imported by: 36

README

Overview

Twitter GoDoc Build Status

Slugify is a small library that turns strings in to slugs.

License

Slugify is licensed under a MIT license.

Installation

A simple go get github.com/Machiel/slugify should suffice.

Usage

Example

package main

import (
	"fmt"

	"github.com/Machiel/slugify"
)

func main() {
	fmt.Println(slugify.Slugify("Hello, world!"))               // Will print: hello-world
	fmt.Println(slugify.Slugify("💻  I love this computer! 💻 ")) // Will print: i-love-this-computer

	dotSlugifier := slugify.New(slugify.Configuration{
		ReplaceCharacter: '.',
	})

	fmt.Println(dotSlugifier.Slugify("Hello, world!")) // Will print: hello.world

	numericOnlySlugifier := slugify.New(slugify.Configuration{
		IsValidCharacterChecker: func(c rune) bool {
			if c >= '0' && c <= '9' {
				return true
			}

			return false
		},
	})

	fmt.Println(numericOnlySlugifier.Slugify("3 eggs, 2 spoons of milk")) // Will print: 3-2

	replacementMapSlugifier := slugify.New(slugify.Configuration{
		ReplacementMap: map[rune]string{
			'a': "hello",
			'b': "hi",
		},
	})

	fmt.Println(replacementMapSlugifier.Slugify("a b")) // Will print: hello-hi
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDefaultReplacements

func GetDefaultReplacements() map[rune]string

func Slugify

func Slugify(value string) string

Slugify creates the slug for a given value

Types

type Configuration

type Configuration struct {
	IsValidCharacterChecker func(rune) bool
	ReplaceCharacter        rune
	ReplacementMap          map[rune]string
}

Configuration is the basic configuration for Slugifier

type Slugifier

type Slugifier struct {
	// contains filtered or unexported fields
}

Slugifier based on settings

func New

func New(config Configuration) *Slugifier

New initialize a new slugifier

func (Slugifier) Slugify

func (s Slugifier) Slugify(value string) string

Slugify creates a slug for a string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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