urns

package
v1.60.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 8 Imported by: 132

Documentation

Index

Constants

View Source
const (
	// FacebookRefPrefix is prefix used for facebook referral URNs
	FacebookRefPrefix string = "ref:"
)
View Source
const NilURN = URN("")

NilURN is our constant for nil URNs

Variables

View Source
var Discord = &Scheme{
	Prefix:   "discord",
	Name:     "Discord",
	Validate: func(path string) bool { return allDigitsRegex.MatchString(path) },
}
View Source
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) },
}
View Source
var ErrNotNumber = errors.New("not a possible number")
View Source
var External = &Scheme{
	Prefix: "ext",
	Name:   "External",
}
View Source
var Facebook = &Scheme{
	Prefix: "facebook",
	Name:   "Facebook",
	Validate: func(path string) bool {

		if strings.HasPrefix(path, FacebookRefPrefix) {
			return true
		}

		return allDigitsRegex.MatchString(path)
	},
}
View Source
var Firebase = &Scheme{
	Prefix: "fcm",
	Name:   "Firebase",
}
View Source
var FreshChat = &Scheme{
	Prefix:   "freshchat",
	Name:     "FreshChat",
	Validate: func(path string) bool { return freshchatRegex.MatchString(path) },
}
View Source
var Instagram = &Scheme{
	Prefix:   "instagram",
	Name:     "Instagram",
	Validate: func(path string) bool { return allDigitsRegex.MatchString(path) },
}
View Source
var JioChat = &Scheme{
	Prefix:   "jiochat",
	Name:     "JioChat",
	Validate: func(path string) bool { return allDigitsRegex.MatchString(path) },
}
View Source
var Line = &Scheme{
	Prefix:   "line",
	Name:     "LINE",
	Validate: func(path string) bool { return lineRegex.MatchString(path) },
}
View Source
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)
	},
}
View Source
var RocketChat = &Scheme{
	Prefix: "rocketchat",
	Name:   "Rocket.Chat",
}
View Source
var Schemes = []*Scheme{}
View Source
var Slack = &Scheme{
	Prefix: "slack",
	Name:   "Slack",
}
View Source
var Telegram = &Scheme{
	Prefix:   "telegram",
	Name:     "Telegram",
	Validate: func(path string) bool { return allDigitsRegex.MatchString(path) },
}
View Source
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) },
}
View Source
var TwitterID = &Scheme{
	Prefix:   "twitterid",
	Name:     "Twitter",
	Validate: func(path string) bool { return allDigitsRegex.MatchString(path) },
}
View Source
var VK = &Scheme{
	Prefix: "vk",
	Name:   "VK",
}
View Source
var Viber = &Scheme{
	Prefix:   "viber",
	Name:     "Viber",
	Validate: func(path string) bool { return viberRegex.MatchString(path) },
}
View Source
var WeChat = &Scheme{
	Prefix: "wechat",
	Name:   "WeChat",
}
View Source
var WebChat = &Scheme{
	Prefix:   "webchat",
	Name:     "WebChat",
	Validate: func(path string) bool { return webchatRegex.MatchString(path) },
}
View Source
var WhatsApp = &Scheme{
	Prefix:   "whatsapp",
	Name:     "WhatsApp",
	Validate: func(path string) bool { return allDigitsRegex.MatchString(path) },
}

Functions

func IsValidScheme

func IsValidScheme(scheme string) bool

IsValidScheme checks whether the provided scheme is valid

func ParseNumber added in v1.5.3

func ParseNumber(raw string, country i18n.Country, allowShort, allowSenderID bool) (string, error)

ParseNumber tries to extact a possible number or shortcode from the given string, returning an error if it can't.

func ToLocalPhone added in v1.54.0

func ToLocalPhone(u URN, country i18n.Country) string

ToLocalPhone converts a phone URN to a local phone number.. without any leading zeros. Kinda weird but used by Courier where channels want the number in that format.

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 New added in v1.54.0

func New(scheme *Scheme, path string) (URN, error)

New returns a validated URN for the given scheme and path

func NewFromParts added in v1.54.0

func NewFromParts(scheme, path string, query url.Values, display string) (URN, error)

NewFromParts returns a normalized and validated URN for the given scheme, path, query and display

func Parse added in v1.1.1

func Parse(s string) (URN, error)

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

func ParsePhone(raw string, country i18n.Country, allowShort, allowSenderID bool) (URN, error)

ParsePhone returns a validated phone URN or an error.

func (URN) Display

func (u URN) Display() string

Display returns the display portion for the URN (if any)

func (URN) Format

func (u URN) Format() string

Format formats this URN as a human friendly string

func (URN) Identity

func (u URN) Identity() URN

Identity returns the URN with any query or display attributes stripped

func (URN) Normalize

func (u URN) Normalize() URN

Normalize normalizes the URN into it's canonical form and should be performed before URN comparisons

func (URN) Path

func (u URN) Path() string

Path returns the path portion for the URN

func (URN) Query

func (u URN) Query() (url.Values, error)

Query returns the parsed query portion for the URN (if any)

func (URN) RawQuery

func (u URN) RawQuery() string

RawQuery returns the unparsed query portion for the URN (if any)

func (URN) Scheme

func (u URN) Scheme() string

Scheme returns the scheme portion for the URN

func (URN) String

func (u URN) String() string

String returns the string representation of this URN

func (URN) ToParts

func (u URN) ToParts() (string, string, string, string)

ToParts splits the URN into scheme, path and display parts

func (URN) Validate

func (u URN) Validate() error

Validate returns whether this URN is considered valid

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL