Skip to content

Golang library for providing a canonical representation of email address.

License

Notifications You must be signed in to change notification settings

dimuska139/go-email-normalizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-email-normalizer - email normalization for Go

Build Status codecov Go Report Card License Mentioned in Awesome Go

This is Golang library for providing a canonical representation of email address. It allows to prevent multiple signups. go-email-normalizer contains some popular providers but you can easily append others.

Download

go get -u github.com/dimuska139/go-email-normalizer/v3

Usage

package main

import (
	"fmt"
	"strings"
	normalizer "github.com/dimuska139/go-email-normalizer/v3"
)

type customRule struct {}

func (rule *customRule) ProcessUsername(username string) string {
	return strings.Replace(username, "-", "", -1)
}

func (rule *customRule) ProcessDomain(domain string) string {
	return domain
}

func main() {
	n := normalizer.NewNormalizer()
	fmt.Println(n.Normalize("[email protected]")) // [email protected]
	fmt.Println(n.Normalize("[email protected]")) // [email protected]
	fmt.Println(n.Normalize("[email protected]"))      // [email protected]
	fmt.Println(n.Normalize("[email protected]")) // [email protected]
	fmt.Println(n.Normalize("[email protected]"))     // [email protected]
	
	n.AddRule("customrules.com", &customRule{})
	fmt.Println(n.Normalize(" [email protected].")) // [email protected]
}

Supported providers

  • Apple
  • Fastmail
  • Google
  • Microsoft
  • Protonmail
  • Rackspace
  • Rambler
  • Yahoo
  • Yandex
  • Zoho

Also you can integrate other rules using AddRule function (see an example above)