Skip to content
/ slug Public

Package slug generate slug from Unicode string.

License

Notifications You must be signed in to change notification settings

goloop/slug

Repository files navigation

Go Report Card License License Stay with Ukraine

slug

Package slug generates URL-friendly slugs from Unicode strings with support for multiple languages. It provides both simple functions and a more configurable object-oriented approach.

Features

  • Clean, URL-safe slug generation.
  • Multi-language support through transliteration t13n.
  • Customizable character replacement.
  • Thread-safe operations.
  • High performance.
  • No external dependencies for core functionality.

Installation

go get -u github.com/goloop/slug

Quick Start

To use this module import it as: github.com/goloop/slug

package main

import (
    "fmt"
    "github.com/goloop/slug"
)

func main() {
    // Simple usage
    fmt.Println(slug.Make("Hello 世界"))
    // Output: Hello-Shi-Jie

    // With language-specific settings
    s := slug.New()
    fmt.Println(s.Lang("uk").Make("Привіт Світ"))
    // Output: Pryvit-Svit
}

Conversion functions

Fast conversion.

Use the Make method to convert a string to slug.

package main

import (
	"fmt"

	"github.com/goloop/slug"
)

func main() {
	// Simple generate slug from the string.
	s := slug.Make("Hello 世界")
	h := "https://example.com/"

	fmt.Printf("%s%s\n", h, s)
	// Output: https://example.com/Hello-Shi-Jie
}

API Reference

Functions

  • Make(t string) string - Generate a slug from a string.
  • Lower(t string) string - Generate a lowercase slug.
  • Upper(t string) string - Generate an uppercase slug.
  • New() *Slug - Create a new Slug instance for advanced configuration.

Slug Methods

  • Lang(l string) *Slug - Set language for transliteration.
  • Make(t string) string - Generate a slug.
  • Lower(t string) string - Generate a lowercase slug.
  • Upper(t string) string - Generate an uppercase slug.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Package slug generate slug from Unicode string.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages