BEmailParts is a simple and efficient utility for parsing and handling email addresses. It provides a structured way to extract different parts of an email address and reassemble it with ease. This library is useful for applications requiring email validation or detailed email manipulation.
To install BEmailParts, run the following command:
go get github.com/bearaujus/bemailparts
import "github.com/bearaujus/bemailparts"
- Parse an email address into its components (username, domain, domain name, and TLD).
- Validate the email format using a regular expression.
- Rebuild the email address from its components.
Use the New function to parse an email into its parts:
e, err := bemailparts.New("[email protected]")
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println(e.Email()) // Output: [email protected]"
fmt.Println(e.Username()) // Output: test
fmt.Println(e.Domain()) // Output: domain.com
fmt.Println(e.DomainName()) // Output: domain
fmt.Println(e.DomainTLD()) // Output: .com
fmt.Println(e.DomainTLDWithoutDot()) // Output: com
You can also create an email from its components using helper functions:
e, err := bemailparts.NewFromUsernameAndDomain("test", "domain.com")
if err != nil {
fmt.Println("Error:", err)
return
}
e, err := bemailparts.NewFromFullParts("test", "domain", "com")
if err != nil {
fmt.Println("Error:", err)
return
}
The Email() function reassembles the email from its parts:
e, err := bemailparts.New("[email protected]")
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Email:", e.Email()) // Output: [email protected]
This project is licensed under the MIT License - see the LICENSE file for details.