Documentation
¶
Overview ¶
Package sanja provides phone number normalization and formatting.
Overview: Sanja helps normalize phone numbers to international format with country code handling. It supports 250+ countries and bulk processing.
Example:
norm := sanja.NewNormalizer("US")
normalized, err := norm.Normalize("555-123-4567")
// Result: "+15551234567"
Features:
- Local to international number conversion
- Bulk phone number processing
- Country code detection
- Comprehensive country data
Index ¶
- Constants
- Variables
- type Country
- type Normalizer
- func (n *Normalizer) GetCountryByA2(a2 string) *Country
- func (n *Normalizer) GetCountryByCode(code string) *Country
- func (n *Normalizer) Normalize(phone string) (string, error)
- func (n *Normalizer) NormalizeBulk(phones []string) ([]string, []error)
- func (n *Normalizer) ValidatePhoneNumber(phone, countryA2 string) error
Constants ¶
View Source
const ( MinimumLocalDigitsLength int = 7 MaximumLocalDigitsLength int = 12 )
Variables ¶
View Source
var ErrDefaultCountryNotFound = errors.New("no default country set")
View Source
var ErrInvalidPhoneNumber = errors.New("invalid phone number")
View Source
var ErrPhoneNumberAndCountryCodeMismatch = errors.New("phone number does not match country code")
View Source
var ErrUnknownCountry = errors.New("invalid or unknown country")
Functions ¶
This section is empty.
Types ¶
type Normalizer ¶
type Normalizer struct {
// contains filtered or unexported fields
}
Normalizer hanldes phone numbder normalization
func NewNormalizer ¶
func NewNormalizer(defaultCountryA2 string) *Normalizer
NewNormalizer creatres a new phone number normalizer
func (*Normalizer) GetCountryByA2 ¶
func (n *Normalizer) GetCountryByA2(a2 string) *Country
GetCountryByA2 returns a countyr by its A2 code
func (*Normalizer) GetCountryByCode ¶
func (n *Normalizer) GetCountryByCode(code string) *Country
GetCountryByCode returns a country by its dialing code
func (*Normalizer) Normalize ¶
func (n *Normalizer) Normalize(phone string) (string, error)
Normalize adds the country code prefix to a phone number if missing
func (*Normalizer) NormalizeBulk ¶
func (n *Normalizer) NormalizeBulk(phones []string) ([]string, []error)
NormalizeBulk normalizes multiple phone numbers
func (*Normalizer) ValidatePhoneNumber ¶
func (n *Normalizer) ValidatePhoneNumber(phone, countryA2 string) error
ValidatePhoneNumber validates if a phone number matches a specific country
Click to show internal directories.
Click to hide internal directories.