package logger

import (
	"regexp"
	"strings"
)

// MaskEmail removes all identifying chars except first from email username
func MaskEmail(s string) string {
	tmp := strings.Split(s, "@")
	addr := tmp[0]
	domain := tmp[1]
	if len(addr) <= 0 || len(domain) <= 0 {
		return ""
	}

	addr = addr[:1] + strings.Repeat("*", len(addr)-1)
	return addr + "@" + domain
}

// MaskPassword replaces all characters
func MaskPassword(s string) string {
	return strings.Repeat("*", len(s))
}

// MaskPhoneNumber replaces all nums except first from number string
func MaskPhoneNumber(s string) string {
	m := regexp.MustCompile(`\B\d`)
	return m.ReplaceAllString(s, "*")
}
