gosimple / slug Goto Github PK
View Code? Open in Web Editor NEWURL-friendly slugify with multiple languages support.
License: Mozilla Public License 2.0
URL-friendly slugify with multiple languages support.
License: Mozilla Public License 2.0
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
Hello,
Can you please tag and version this project?
I am the Debian Maintainer for slug and versioning would help Debian keep up with development.
When trying to truncate a string with a value greater than its size, we get the below error.
Example of failed test: {"DOBROSLAWZYBORT", 17, "dobroslawzybort", false}
--- FAIL: TestSlugMakeSmartTruncate (0.01s)
panic: runtime error: slice bounds out of range [:17] with length 15 [recovered]
panic: runtime error: slice bounds out of range [:17] with length 15
Hello,
Please update to latest the import path for unidecode to: github.com/rainycape/unidecode
. See: https://github.com/rainycape/unidecode
This seems like a silly use case at first, but when creating a slug from a string containing emojis or pictograms, there is no representation of those characters. For example:
slug.Make("🐛")
slug.Make("☺")
slug.Make("𝕗𝕒𝕟𝕔𝕪 𝕥𝕖𝕩𝕥")
all yield empty strings.
I'm not sure how such a character would best be represented in a slug, but simply removing them could be problematic in some cases. Is this intentional?
Looks like default substitutions are not running for some langs:
slug/languages_substitution.go
Line 10 in aba3e10
More tests needed and fixing it in a way that will not force adding every lang by hand.
When something new is added there should be info if it's tested properly.
For German, @
is replaced with en
. I am a native speaker, and I have never heard of read this “en”. Where does it come from? It is mostly called “at” in German (as in English). Other Geman words for it are very long.
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"
getting- started ##
should become getting-started
How to achieve this ?
It would be awesome if there's a function that checks whether an input string is a valid slug or not like this one: https://github.com/extemporalgenome/slug/blob/master/slug.go#L94
What is the reason because is removing -
and _
from the begging and the end of the name. I want to represent an endpoint for a item that is named ______
. How to do it in your case?
Real example: Magic The Gathering card
Debug to understand why tests are passing if 'trSub' is not added in init?
slug/languages_substitution.go
Line 11 in a57e999
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:
var
IsSlug
and not on the MakeLang
WDYT?
Would be great if there was an option to allow uppercase characters to not be converted.
Thanks!
This code panics:
slug.Make("𐀀")
This is due to the internal use of rainycape/unidecode
, which can not handle Unicode character U+10000, see rainycape/unidecode#8.
Given the inactivity of the upstream package, it might be worth filtering out the character in question before passing it to unidecode
.
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 😄
When using the truncate function, the slug can be longer than MaxLength
on specific conditions. See this example:
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.
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.
Is there any way we could have it auto detect the language with the slug.Make
and then default to English?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.