slugify

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2020 License: MIT Imports: 6 Imported by: 0

README

slugify

Package slugify generate a dash-connected slug from unicode string.

Go.Dev reference

Example

package main

import (
    "fmt"
    
    "github.com/owarai/slugify"
)

func main() {
    text := slugify.Format("hello, 你好,world! 世界!", true)
    fmt.Println(text) // Will print: "hello-你好-world-世界"
    
    someText := slugify.Format("hello, 你好,world! 世界!", false)
    fmt.Println(someText) // Will print: "hello-world"
}

Installation

# under module-aware mode
go get github.com/owarai/slugify

Documentation

Overview

Package slugify generate slug from unicode string, check Format() for details. Example:

package main

import (
	"fmt"

	"github.com/owarai/slugify"
)

func main() {
		text := slugify.Format("hello, 你好,world! 世界!", true)
		fmt.Println(text) // Will print: "hello-你好-world-世界"

		someText := slugify.Format("hello, 你好,world! 世界!", false)
		fmt.Println(someText) // Will print: "hello-world"
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(s string, allowUnicode bool) string

Format slugify the input(must be valid utf8 string), convert to ASCII if 'allowUnicode' is false(non-ascii character will be removed in this situation). Convert spaces or repeated dashes to single dashes. Remove characters that aren't letters, punctuations or separators. Convert to lowercase and replace other(may repeated) punctuations or separators to single dash.

Types

This section is empty.

Jump to

Keyboard shortcuts

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