mirror of
				https://github.com/taigrr/wtf
				synced 2025-01-18 04:03:14 -08:00 
			
		
		
		
	
		
			
				
	
	
		
			36 lines
		
	
	
		
			789 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			789 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package utils
 | 
						|
 | 
						|
import (
 | 
						|
	"strings"
 | 
						|
)
 | 
						|
 | 
						|
// NameFromEmail takes an email address and returns the part that comes before the @ symbol
 | 
						|
//
 | 
						|
// Example:
 | 
						|
//
 | 
						|
//    NameFromEmail("test_user@example.com")
 | 
						|
//    > "Test_user"
 | 
						|
//
 | 
						|
func NameFromEmail(email string) string {
 | 
						|
	parts := strings.Split(email, "@")
 | 
						|
	return strings.Title(strings.Replace(parts[0], ".", " ", -1))
 | 
						|
}
 | 
						|
 | 
						|
// NamesFromEmails takes a slice of email addresses and returns a slice of the parts that
 | 
						|
// come before the @ symbol
 | 
						|
//
 | 
						|
// Example:
 | 
						|
//
 | 
						|
//    NamesFromEmail("test_user@example.com", "other_user@example.com")
 | 
						|
//    > []string{"Test_user", "Other_user"}
 | 
						|
//
 | 
						|
func NamesFromEmails(emails []string) []string {
 | 
						|
	names := make([]string, len(emails))
 | 
						|
 | 
						|
	for i, email := range emails {
 | 
						|
		names[i] = NameFromEmail(email)
 | 
						|
	}
 | 
						|
 | 
						|
	return names
 | 
						|
}
 |