medol-be/utils/service/string.service.go

32 lines
512 B
Go
Raw Normal View History

2024-04-30 03:53:50 +00:00
package service
2024-11-22 15:58:15 +00:00
import (
"strings"
"unicode"
)
2024-04-30 03:53:50 +00:00
func IsNumeric(str string) bool {
for _, char := range str {
if !unicode.IsDigit(char) {
return false
}
}
return true
}
2024-11-22 15:58:15 +00:00
func MakeSlug(s string) string {
// Convert to lowercase
s = strings.ToLower(s)
// Replace spaces with hyphens
s = strings.ReplaceAll(s, " ", "-")
// Remove non-alphanumeric characters
return strings.Map(func(r rune) rune {
if unicode.IsLetter(r) || unicode.IsDigit(r) || r == '-' {
return r
}
return -1
}, s)
}