mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
28 lines
507 B
Go
28 lines
507 B
Go
package name
|
|
|
|
import "strings"
|
|
|
|
func GuessPluralName(name string) string {
|
|
if name == "" {
|
|
return name
|
|
}
|
|
|
|
if strings.EqualFold(name, "Endpoints") {
|
|
return name
|
|
}
|
|
|
|
if suffix(name, "s") || suffix(name, "ch") || suffix(name, "x") {
|
|
return name + "es"
|
|
}
|
|
|
|
if suffix(name, "y") && len(name) > 2 && !strings.ContainsAny(name[len(name)-2:len(name)-1], "[aeiou]") {
|
|
return name[0:len(name)-1] + "ies"
|
|
}
|
|
|
|
return name + "s"
|
|
}
|
|
|
|
func suffix(str, end string) bool {
|
|
return strings.HasSuffix(str, end)
|
|
}
|