phone

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package phone holds the platform's shared phone-number helpers: redaction for logs, and three normalisers with deliberately different contracts.

Redaction

Redact masks the middle of a number for safe logging, keeping the first six digits (country code plus network prefix) and the last three, so "254711222111" becomes "254711***111". A leading "+" is preserved, and a number too short to have a maskable middle is returned unchanged.

Normalisation

Three functions convert to international form, and they are not interchangeable — pick by how much you trust the input:

  • Normalize is the most lenient: it trims whitespace and ensures a leading "+", nothing more. Use it when the number is already known to carry a country code (e.g. a YellowCard destination).
  • E164 is the strictest: it strips separators, turns a "00" prefix into "+", and returns "" for a national-format number (leading "0", no country code) rather than guess a country. Use it where a wrong number is worse than none, such as the SEP-9 mobile_number sent to anchors.
  • Format strips non-digits and prepends a country code (default +254) when the number is not already international.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func E164

func E164(phone string) string

E164 normalises a phone number to the "+<country><subscriber>" form. Separators are removed, a "00" international prefix becomes "+", and a bare international number gains a "+". A national-format number (leading "0", no country code) cannot be resolved without country context and yields "" so the caller omits the field rather than sending a wrong one.

func Format

func Format(phoneNumber, countryCode string) string

Format strips non-digits from a phone number and prepends a country code when the number is not already international. countryCode defaults to "+254" (Kenya) when empty.

func Normalize

func Normalize(phone string) string

Normalize ensures the number is in international format with a leading "+", trimming surrounding whitespace. It neither strips separators nor validates.

func Redact

func Redact(phone string) string

Redact masks the middle of a phone number for safe logging, keeping the first six and last three digits: "254711222111" becomes "254711***111". A leading "+" is preserved. Numbers with nine or fewer digits are returned unchanged — there is nothing in the middle worth masking.

Types

This section is empty.

Jump to

Keyboard shortcuts

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