24 lines
542 B
Go
24 lines
542 B
Go
package tools
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/mozillazg/go-pinyin"
|
|
"github.com/samber/lo"
|
|
)
|
|
|
|
func ContainsInsensitive(element string, slice []string) bool {
|
|
lowercasedElement := strings.TrimSpace(strings.ToLower(element))
|
|
return lo.Contains(slice, lowercasedElement)
|
|
}
|
|
|
|
func PinyinAbbr(source string) string {
|
|
abbr := pinyin.Pinyin(source, pinyin.NewArgs())
|
|
var abbrCollect = make([]string, 0)
|
|
for _, a := range abbr {
|
|
abbrCollect = append(abbrCollect, a[0][0:1])
|
|
}
|
|
finalAbbr := strings.Join(abbrCollect, "")
|
|
return finalAbbr
|
|
}
|