URL-friendly slugify with multiple languages support.

Overview

slug

Package slug generate slug from unicode string, URL-friendly slugify with multiple languages support.

GoDoc Build Status

Documentation online

Example

package main

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

func main() {
	text := slug.Make("Hellö Wörld хелло ворлд")
	fmt.Println(text) // Will print: "hello-world-khello-vorld"

	someText := slug.Make("影師")
	fmt.Println(someText) // Will print: "ying-shi"

	enText := slug.MakeLang("This & that", "en")
	fmt.Println(enText) // Will print: "this-and-that"

	deText := slug.MakeLang("Diese & Dass", "de")
	fmt.Println(deText) // Will print: "diese-und-dass"
	
	slug.Lowercase = false // Keep uppercase characters
	deUppercaseText := slug.MakeLang("Diese & Dass", "de")
        fmt.Println(deUppercaseText) // Will print: "Diese-und-Dass"

	slug.CustomSub = map[string]string{
		"water": "sand",
	}
	textSub := slug.Make("water is hot")
	fmt.Println(textSub) // Will print: "sand-is-hot"
}

Requests or bugs?

https://github.com/gosimple/slug/issues

Installation

go get -u github.com/gosimple/slug

License

The source files are distributed under the Mozilla Public License, version 2.0, unless otherwise noted. Please read the FAQ if you have further questions regarding the license.

Issues
  • IsSlug for empty string

    IsSlug for empty string

    IDK exatly if it's a bug or it's supose to be this way really hehe.

    package main
    
    import (
            "fmt"
    
            "github.com/gosimple/slug"
    )
    
    func main() {
            text := ""
            fmt.Printf("IsSlug: %t\n", slug.IsSlug(text))
    }
    

    the output is:

    IsSlug: true
    

    IMO an empty string should not be considred a slug but before opening a PR I wanted to know if it should be 😄

    opened by xescugc 8
  • TestSubstituteLang is flaky

    TestSubstituteLang is flaky

    It fails about 12% of the time for me:

    --- FAIL: TestSubstituteLang (0.00s)
        slug_test.go:155: 1. Substitute("o a o", map[string]string{"o":"no", "a":"or"}) = "no nor no"; want "no or no"
    FAIL
    
    opened by mwhudson 6
  • Add MinLength

    Add MinLength

    As it exists the validation for MaxLength of a slug, I thought it sould exists MinLength also.

    The 2 main functions in which this will affect are MakeLang (Make uses it so no need for it) and IsSlug.

    For IsSlug it's easy, it's just a validation and if not then return false. For MakeLang is more complex as the current signature does not return an error, and changing that would be a HUGE change on the API, so not an option, the other options would be:

    • Fill the missing characters with something, maybe defined by the user on another var
    • Only use it on the IsSlug and not on the MakeLang

    WDYT?

    opened by xescugc 5
  • Add Go modules support

    Add Go modules support

    When working on implementing #37 I noticed that there were no Go module files. This pull request adds the go.mod and go.sum to the project.

    Thank you!

    opened by antonlindstrom 4
  • Code panics for Unicode U+10000

    Code panics for Unicode U+10000

    This code panics:

    slug.Make("𐀀")
    

    This is due to the internal use of rainycape/unidecode, which can not handle Unicode character U+10000, see https://github.com/rainycape/unidecode/issues/8.

    Given the inactivity of the upstream package, it might be worth filtering out the character in question before passing it to unidecode.

    opened by tja 3
  • Substitute @ with at in german

    Substitute @ with at in german

    I would suggest replacing the character @ with at. To be honest, I've never heard anyone say "xyz AN gmail.com" while providing their email address.

    opened by kunzese 3
  • slug.Make() returns non-slug

    slug.Make() returns non-slug

    Hi there! Thanks for this awesome lib! I'm not sure if this is a valid use-case or not, but I've found a set of custom substitutions that seem to break Make(). In the code below, IsSlug() returns false for every item in slugs.

    names := []string{
    	"Ciudad Autónoma de Buenos Aires AR",
    	"Córdoba AR",
    	"Entre Ríos AR",
    	"Neuquén AR",
    	"Tucumán AR",
    }
    
    slug.CustomSub = map[string]string{
    	"AR": "",
    	"BR": "",
    	"CL": "",
    	"UY": "",
    }
    
    slug.CustomRuneSub = map[rune]string{
        'á': "aa",
        'é': "ee",
        'í': "ii",
        'ó': "oo",
        'ú': "uu",
        ' ': "_",
    }
    
    var slugs []string
    
    for _, n := range names {
    	slugs = append(slugs, slug.Make(n))
    }
    

    I've already found a way to work around this in my code, using SubstituteRune() first.

    opened by micabot 3
  • Use a buffer instead of

    Use a buffer instead of "naive" concatenation in SubstituteRune

    Current string concatenation makes a lot of memory allocations. Using a buffer should be more efficient.

    See : http://herman.asia/efficient-string-concatenation-in-go

    opened by hectorj 2
  • fix edge case in truncate function allowing too long slugs

    fix edge case in truncate function allowing too long slugs

    Fixes https://github.com/gosimple/slug/issues/72

    I'm not using operations on strings to avoid unnecessary allocations. I've added a test case for the fixed issue.

    opened by Redlinkk 1
  • Slug length can be MaxLength+1

    Slug length can be MaxLength+1

    When using the truncate function, the slug can be longer than MaxLength on specific conditions. See this example:

    • original string (of length 11): "abcde-fghij"
    • MaxLength: 10
    • expected string: "abcde"
    • output string: "abcde-fghij"

    Current function fails on this edge case because the last word doesn't end with a "-" during the max length test here so the - 1 is wrongfully applied.

    opened by Redlinkk 0
  • Add Italian language substitutions

    Add Italian language substitutions

    Substitutions:

    • & -> e (https://dictionary.cambridge.org/dictionary/english-italian/and)
    • @ -> chiocciola (https://dictionary.cambridge.org/dictionary/english-italian/at-sign)
    opened by TomOne 1
  • should not be english

    should not be english

    text := slug.Make("Hellö Wörld & хелло ворлд") fmt.Println(text) // Will print: "hello-world-(and)-khello-vorld"

    correct fmt.Println(text) // Will print: "hello-world-khello-vorld"

    opened by eturerer 0
Releases(v1.12.0)
Owner
GoSimple
GoSimple
Produces a set of tags from given source. Source can be either an HTML page, Markdown document or a plain text. Supports English, Russian, Chinese, Hindi, Spanish, Arabic, Japanese, German, Hebrew, French and Korean languages.

Tagify Gets STDIN, file or HTTP address as an input and returns a list of most popular words ordered by popularity as an output. More info about what

ZoomIO 23 Jul 17, 2022
Go Humans! (formatters for units to human friendly sizes)

Humane Units Just a few functions for helping humanize times and sizes. go get it as github.com/dustin/go-humanize, import it as "github.com/dustin/go

Dustin Sallings 3.3k Aug 15, 2022
[Crawler/Scraper for Golang]🕷A lightweight distributed friendly Golang crawler framework.一个轻量的分布式友好的 Golang 爬虫框架。

Goribot 一个分布式友好的轻量的 Golang 爬虫框架。 完整文档 | Document !! Warning !! Goribot 已经被迁移到 Gospider|github.com/zhshch2002/gospider。修复了一些调度问题并分离了网络请求部分到另一个仓库。此仓库会继续

null 208 Jul 4, 2022
Generate a global index for multiple markdown files recursively

markdown index Markdown-index is a library to help you generate a global index for multiple markdown files recursively in a directory, containing a su

Mateus Miranda 16 Jul 26, 2022
A simple action that looks for multiple regex matches, in a input text, and returns the key of the first found match.

Key Match Action A simple action that looks for multiple regex matches, in a input text, and returns the key of the first found match. TO RUN Add the

Chris 1 Aug 4, 2022
A shell parser, formatter, and interpreter with bash support; includes shfmt

sh A shell parser, formatter, and interpreter. Supports POSIX Shell, Bash, and mksh. Requires Go 1.14 or later. Quick start To parse shell scripts, in

Daniel Martí 5k Aug 18, 2022
Show Languages In Code. A fast and lightweight CLI to generate stats on the languages inside your project

slic Show Languages In Code. Usage Run it with an -h flag to list all commands. -d flag can be used to specify the directory of search -i flag can be

Saurav Pal 3 Dec 25, 2021
A Go slugify application that handles string

slugify A Go slugify application that handles string Example: package main import ( "fmt" "github.com/avelino/slugify" ) func main() { text := "E

Avelino 31 Jan 24, 2022
:steam_locomotive: Decodes url.Values into Go value(s) and Encodes Go value(s) into url.Values. Dual Array and Full map support.

Package form Package form Decodes url.Values into Go value(s) and Encodes Go value(s) into url.Values. It has the following features: Supports map of

Go Playgound 549 Aug 17, 2022
Go-based search engine URL collector , support Google, Bing, can be based on Google syntax batch collection URL

Go-based search engine URL collector , support Google, Bing, can be based on Google syntax batch collection URL

Re 54 Aug 7, 2022
Translate your Go program into multiple languages.

go-i18n go-i18n is a Go package and a command that helps you translate Go programs into multiple languages. Supports pluralized strings for all 200+ l

Nick Snyder 2.1k Aug 9, 2022
go-i18n is a Go package and a command that helps you translate Go programs into multiple languages.

go-i18n is a Go package and a command that helps you translate Go programs into multiple languages.

Nick Snyder 2.1k Aug 8, 2022
Translate your Go program into multiple languages with similar fmt.Sprintf format syntax.

Loafer-i18n Loafer-i18n is a Go package and a command that helps you translate Go programs into multiple languages. Supports pluralized strings with =

EasyGram 0 Dec 22, 2021
Stalin sort in multiple languages!

stalin-sort Stalin sort in multiple languages, contributions are welcome! Motivation This repo is motivated by this tweet, this tweet contains a refer

CaKrome 0 Jan 14, 2022
Super short, fully unique, non-sequential and URL friendly Ids

Generator of unique non-sequential short Ids The package shortidenables the generation of short, fully unique, non-sequential and by default URL frien

teris.io 782 Aug 5, 2022
A drop-in replacement for Go errors, with some added sugar! Unwrap user-friendly messages, HTTP status code, easy wrapping with multiple error types.

Errors Errors package is a drop-in replacement of the built-in Go errors package with no external dependencies. It lets you create errors of 11 differ

Kamaleshwar 42 May 18, 2022
High-Performance Shortlink ( Short URL ) app creator in Golang. For privacy reasons, you may prefer to host your own short URL app and this is the one to use.

About The Project Shortlink App in Golang Multiple Node based Architecture to create and scale at ease Highly performant key-value storage system Cent

null 124 Aug 1, 2022
A productivity tools to diagnose list of exported URL status from Google Search Console, Analytics, Sitemap URL...etc.

google-url-checker A productivity tools to diagnose list of exported URL status from Google Search Console, Analytics, Sitemap URL...etc. A quick way

null 0 Dec 31, 2021
Putty-url-scheme - Open PuTTY as a url scheme

PuTTY URL Scheme Helper Open PuTTY as a url scheme Install download release bina

Dark495 4 Apr 25, 2022
Test-app-url-shortner - A sample url shortener app to test Keploy integration capabilities

test-app-url-shortner A sample url shortener app to test Keploy integration capa

null 1 Jan 23, 2022
Get any cryptocurrencies ticker and trade data in real time from multiple exchanges and then save it in multiple storage systems.

Cryptogalaxy is an app which will get any cryptocurrencies ticker and trade data in real time from multiple exchanges and then saves it in multiple storage systems.

Pavan Shetty 100 Jul 23, 2022
S3pd - CLI utility that downloads multiple s3 objects at a time, with multiple range-requests issued per object

S3 Parallel Downloader CLI utility that downloads multiple s3 objects at a time,

Colin Bookman 2 May 13, 2022
Produces a set of tags from given source. Source can be either an HTML page, Markdown document or a plain text. Supports English, Russian, Chinese, Hindi, Spanish, Arabic, Japanese, German, Hebrew, French and Korean languages.

Tagify Gets STDIN, file or HTTP address as an input and returns a list of most popular words ordered by popularity as an output. More info about what

ZoomIO 23 Jul 17, 2022
DockerSlim (docker-slim): Don't change anything in your Docker container image and minify it by up to 30x (and for compiled languages even more) making it secure too! (free and open source)

Minify and Secure Docker containers (free and open source!) Don't change anything in your Docker container image and minify it by up to 30x making it

docker-slim 14.7k Aug 8, 2022
Tool that can parse Go files into an abstract syntax tree and translate it to several programming languages.

GoDMT GoDMT, the one and only Go Data Model Translator. The goal of this project is to provide a tool that can parse Go files that include var, const,

Josep Jesus Bigorra Algaba 42 Jan 29, 2022
libraries for various programming languages that make it easy to generate per-process trace files that can be loaded into chrome://tracing

chrometracing: chrome://tracing trace_event files The chrometracing directory contains libraries for various programming languages that make it easy t

Google 22 Jul 8, 2022
Lightweight static analysis for many languages. Find bug variants with patterns that look like source code.

Lightweight static analysis for many languages. Find bugs and enforce code standards. Semgrep is a fast, open-source, static analysis tool that finds

r2c 6.9k Aug 10, 2022
Distributed web crawler admin platform for spiders management regardless of languages and frameworks. 分布式爬虫管理平台,支持任何语言和框架

Crawlab 中文 | English Installation | Run | Screenshot | Architecture | Integration | Compare | Community & Sponsorship | CHANGELOG | Disclaimer Golang-

Crawlab Team 9k Aug 10, 2022
An interpreted languages written in Go

Monkey My changes 1. Installation Source Installation go <= 1.11 Source installation go >= 1.12 Binary Releases 1.1 Usage 2 Syntax 2.1 Definitions 2.2

Steve Kemp 176 Aug 13, 2022