photoprism/pkg/clean/color.go
Michael Mayer 826addb4c1 PWA: Create manifest.json in code without using a template #3181
Signed-off-by: Michael Mayer <michael@photoprism.app>
2023-02-10 15:53:01 +01:00

25 lines
456 B
Go

package clean
import (
"strings"
)
// Color sanitizes HTML color codes and returns them in lowercase if they are valid, or an empty string otherwise.
func Color(s string) string {
s = strings.ToLower(s)
// Remove unwanted characters.
s = strings.Map(func(r rune) rune {
if r < 48 && r > 57 && 97 < r && r > 102 && r != 35 {
return -1
}
return r
}, s)
// Invalid?
if l := len(s); l != 4 && l != 7 && l != 9 {
return ""
}
return s
}