Documentation ¶
Index ¶
- Constants
- Variables
- func IsValidScheme(scheme string) bool
- func ParseNumber(raw string, country i18n.Country, allowShort, allowSenderID bool) (string, error)
- func ToLocalPhone(u URN, country i18n.Country) string
- type Scheme
- type URN
- func (u URN) Display() string
- func (u URN) Format() string
- func (u URN) Identity() URN
- func (u URN) Normalize() URN
- func (u URN) Path() string
- func (u URN) Query() (url.Values, error)
- func (u URN) RawQuery() string
- func (u URN) Scheme() string
- func (u URN) String() string
- func (u URN) ToParts() (string, string, string, string)
- func (u URN) Validate() error
Constants ¶
const ( // FacebookRefPrefix is prefix used for facebook referral URNs FacebookRefPrefix string = "ref:" )
const NilURN = URN("")
NilURN is our constant for nil URNs
Variables ¶
var Discord = &Scheme{ Prefix: "discord", Name: "Discord", Validate: func(path string) bool { return allDigitsRegex.MatchString(path) }, }
var Email = &Scheme{ Prefix: "mailto", Name: "Email", Normalize: func(path string) string { return strings.ToLower(path) }, Validate: func(path string) bool { return emailRegex.MatchString(path) }, }
var ErrNotNumber = errors.New("not a possible number")
var External = &Scheme{
Prefix: "ext",
Name: "External",
}
var Facebook = &Scheme{ Prefix: "facebook", Name: "Facebook", Validate: func(path string) bool { if strings.HasPrefix(path, FacebookRefPrefix) { return true } return allDigitsRegex.MatchString(path) }, }
var Firebase = &Scheme{
Prefix: "fcm",
Name: "Firebase",
}
var FreshChat = &Scheme{ Prefix: "freshchat", Name: "FreshChat", Validate: func(path string) bool { return freshchatRegex.MatchString(path) }, }
var Instagram = &Scheme{ Prefix: "instagram", Name: "Instagram", Validate: func(path string) bool { return allDigitsRegex.MatchString(path) }, }
var JioChat = &Scheme{ Prefix: "jiochat", Name: "JioChat", Validate: func(path string) bool { return allDigitsRegex.MatchString(path) }, }
var Line = &Scheme{ Prefix: "line", Name: "LINE", Validate: func(path string) bool { return lineRegex.MatchString(path) }, }
var Phone = &Scheme{ Prefix: "tel", Name: "Phone", Normalize: func(path string) string { norm, err := ParseNumber(path, "", true, true) if err != nil { return path } return norm }, Validate: func(path string) bool { return phoneRegex.MatchString(path) }, Format: func(path string) string { parsed, err := phonenumbers.Parse(path, "") if err != nil { return path } return phonenumbers.Format(parsed, phonenumbers.NATIONAL) }, }
var RocketChat = &Scheme{
Prefix: "rocketchat",
Name: "Rocket.Chat",
}
var Schemes = []*Scheme{}
var Slack = &Scheme{
Prefix: "slack",
Name: "Slack",
}
var Telegram = &Scheme{ Prefix: "telegram", Name: "Telegram", Validate: func(path string) bool { return allDigitsRegex.MatchString(path) }, }
var Twitter = &Scheme{ Prefix: "twitter", Name: "Twitter Handle", Normalize: func(path string) string { path = strings.ToLower(path) return strings.TrimPrefix(path, "@") }, Validate: func(path string) bool { return twitterHandleRegex.MatchString(path) }, }
var TwitterID = &Scheme{ Prefix: "twitterid", Name: "Twitter", Validate: func(path string) bool { return allDigitsRegex.MatchString(path) }, }
var VK = &Scheme{
Prefix: "vk",
Name: "VK",
}
var Viber = &Scheme{ Prefix: "viber", Name: "Viber", Validate: func(path string) bool { return viberRegex.MatchString(path) }, }
var WeChat = &Scheme{
Prefix: "wechat",
Name: "WeChat",
}
var WebChat = &Scheme{ Prefix: "webchat", Name: "WebChat", Validate: func(path string) bool { return webchatRegex.MatchString(path) }, }
var WhatsApp = &Scheme{ Prefix: "whatsapp", Name: "WhatsApp", Validate: func(path string) bool { return allDigitsRegex.MatchString(path) }, }
Functions ¶
func IsValidScheme ¶
IsValidScheme checks whether the provided scheme is valid
func ParseNumber ¶ added in v1.5.3
ParseNumber tries to extact a possible number or shortcode from the given string, returning an error if it can't.
Types ¶
type Scheme ¶ added in v1.54.0
type Scheme struct { Prefix string Name string Normalize func(string) string Validate func(string) bool Format func(string) string }
Scheme represents a URN scheme, e.g. tel, email, etc.
type URN ¶
type URN string
URN represents a Universal Resource Name, we use this for contact identifiers like phone numbers etc..
func NewFromParts ¶ added in v1.54.0
NewFromParts returns a normalized and validated URN for the given scheme, path, query and display
func Parse ¶ added in v1.1.1
Parse parses a URN from the given string. The returned URN is only guaranteed to be structurally valid.
func ParsePhone ¶ added in v1.54.0
ParsePhone returns a validated phone URN or an error.
func (URN) Normalize ¶
Normalize normalizes the URN into it's canonical form and should be performed before URN comparisons