Skip to content

bearaujus/bemailparts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BEmailParts - Email Parsing Utilities in Go

License Go Report Card

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.

Installation

To install BEmailParts, run the following command:

go get github.com/bearaujus/bemailparts

Import

import "github.com/bearaujus/bemailparts"

Features

  • 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.

Usage

1. Basic Parsing Workflow

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

2. Advanced Creation by Parts

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
}

3. Rebuilding the Email

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]

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Email Parsing Utilities in Go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages