You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"fmt""github.com/kashifkhan0771/utils/slugger"
)
funcmain() {
s:=slugger.New(map[string]string{}, false)
// Will use the default separatorfmt.Println(s.Slug("Wôrķšpáçè ~~sèťtïñğš~~", ""))
// Will use the custom separatorfmt.Println(s.Slug("Wôrķšpáçè ~~sèťtïñğš~~", "/"))
}
Output:
workspace-settings
workspace/settings
Generate slugs with substitutions
package main
import (
"fmt""github.com/kashifkhan0771/utils/slugger"
)
funcmain() {
s:=slugger.New(map[string]string{"%": "percent", "€": "euro"}, false)
fmt.Println(s.Slug("10% or 5€", ""))
}
Output:
10-percent-or-5-euro
Generate slugs with emoji replacement
package main
import (
"fmt""github.com/kashifkhan0771/utils/slugger"
)
funcmain() {
s:=slugger.New(map[string]string{}, true)
fmt.Println(s.Slug("a 😺, 🐈⬛, and a 🦁 go to 🏞️", ""))
}
package main
import (
"fmt""github.com/kashifkhan0771/utils/slugger"
)
funcmain() {
s:=slugger.New(map[string]string{"and": "", "the": "", "of": ""}, false)
fmt.Println(s.Slug("The Beauty and the Power of Nature", ""))
}
Output:
beauty-power-nature
Remove stop words
package main
import (
"fmt""github.com/kashifkhan0771/utils/slugger"
)
funcmain() {
s:=slugger.New(map[string]string{"and": "", "the": "", "of": ""}, false)
fmt.Println(s.Slug("The Beauty and the Power of Nature", ""))
}
Output:
beauty-power-nature
Change substitutions dynamically
package main
import (
"fmt""github.com/kashifkhan0771/utils/slugger"
)
funcmain() {
constinput="The Beauty and the Power of Nature"s:=slugger.New(map[string]string{}, false)
fmt.Println(s.Slug(input, ""))
s.AddSubstitution("and", "")
fmt.Println(s.Slug(input, ""))
s.AddSubstitution("the", "")
fmt.Println(s.Slug(input, ""))
s.RemoveSubstitution("and")
fmt.Println(s.Slug(input, ""))
s.ReplaceSubstitution("the", "a")
fmt.Println(s.Slug(input, ""))
}