Documentation
¶
Overview ¶
Package areacode provides information about North American Numbering Plan telephone area codes.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Abbreviation ¶
type Abbreviation string
Abbreviation represents a two-letter abbreviation for a region in the North American Numbering Plan.
func Abbreviations ¶
func Abbreviations() []Abbreviation
Abbreviations returns a list of all two-letter abbreviations for regions in the North American Numbering Plan sorted in ascending order.
Example ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/areacode"
)
func main() {
codes := areacode.Abbreviations()
fmt.Println(codes[0])
}
Output: AB
type NAN ¶
type NAN int
NAN represents a North American Numbering Plan area code.
func AreaCodes ¶
func AreaCodes() []NAN
AreaCodes returns a list of all NANP area codes sorted in ascending order.
func (NAN) HTML ¶
HTML returns the NANP code as an HTML span element.
Example:
212 - New York (NY)
Example ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/areacode"
)
func main() {
fmt.Println(areacode.NAN(403).HTML())
}
Output: <span>403 - Alberta (AB) + Yukon (YT)</span><br>
type Region ¶ added in v1.10.6
type Region struct {
Name string // Name of the state, province, or territory.
Abbreviation Abbreviation // Two-letter abbreviation.
AreaCodes []NAN // Three-digit NAN code used for telephone area codes.
}
Region represents a region in the North American Numbering Plan.
func Lookup ¶
Lookup returns a list of regions that match the given input. The input can be a string, integer, or NAN. If the input is a string, it will match against region names and abbreviations. If the input is an integer, it will match against NANP codes.
Example ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/areacode"
)
func main() {
t := areacode.Lookup("texas")
fmt.Println(t[0])
t = areacode.Lookup("tx")
fmt.Println(t[0])
t = areacode.Lookup(214)
fmt.Println(t[0])
}
Output: {Texas TX [210 214 409 512 713 806 817 903 915]} {Texas TX [210 214 409 512 713 806 817 903 915]} {Texas TX [210 214 409 512 713 806 817 903 915]}
func Lookups ¶
Lookups returns a list of regions that match the given inputs.
See Lookup for more information.
Example ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/areacode"
)
func main() {
t := areacode.Lookups(817, "iowa", 202)
for _, v := range t {
fmt.Println(v)
}
}
Output: {Texas TX [210 214 409 512 713 806 817 903 915]} {Iowa IA [319 515 712]} {District of Columbia DC [202]}
func RegionByAbbr ¶ added in v1.10.6
func RegionByAbbr(abbr Abbreviation) Region
RegionByAbbr returns the region with the given two-letter abbreviation.
Example ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/areacode"
)
func main() {
t := areacode.RegionByAbbr("CT")
fmt.Println(t.Name, t.Abbreviation, t.AreaCodes)
}
Output: Connecticut CT [203]
func RegionByCode ¶ added in v1.10.6
RegionByCode returns the regions for the given North American Numbering code.
Generally, this will return a single region, but it is possible for a NAN code to be used in multiple regions, such as provinces in Canada.
Example ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/areacode"
)
func main() {
t := areacode.RegionByCode(212)
fmt.Println(t[0].Name, t[0].Abbreviation, t[0].AreaCodes)
t = areacode.RegionByCode(902)
for _, v := range t {
fmt.Println(v.Name, v.Abbreviation, v.AreaCodes)
}
}
Output: New York NY [212 315 516 518 607 716 718 914 917] Nova Scotia NS [902] Prince Edward Island PE [902]
func RegionByName ¶ added in v1.10.6
RegionByName returns the region with the given name. The name can be a US state, Canadian province, or other territory.
Example ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/areacode"
)
func main() {
t := areacode.RegionByName("ontario")
fmt.Println(t.AreaCodes)
}
Output: [416 519 613 705 807 905]
func RegionContains ¶ added in v1.10.6
RegionContains returns a list of regions with names that contain the given string.
Example ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/areacode"
)
func main() {
t := areacode.RegionContains("south")
for _, v := range t {
fmt.Println(v)
}
}
Output: {South Carolina SC [803]} {South Dakota SD [605]}
func Regions ¶ added in v1.10.6
func Regions() []Region
Regions returns a list of all regions in the North American Numbering Plan sorted by name in ascending order.
Example ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/areacode"
)
func main() {
t := areacode.Regions()
name := t[0].Name
alpha := t[0].Abbreviation
area := t[0].AreaCodes
fmt.Printf("%s %s %d\n", name, alpha, area)
fmt.Println(len(t), "regions")
}
Output: Alabama AL [205] 66 regions
type Result ¶
Result represents the result of a query, which can be an area code or a list of regions.
func Queries ¶
Queries returns a list of results for multiple queries from a form input.
Example ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/areacode"
)
func main() {
q := areacode.Queries("az", "arizona", "ut", "602")
for _, result := range q {
s := result.AreaCode.HTML()
if s != "" {
fmt.Println(s)
}
for _, t := range result.Region {
fmt.Println(t.HTML())
}
}
}
Output: <span>Arizona (AZ) - 602</span><br> <span>Arizona (AZ) - 602</span><br> <span>Utah (UT) - 801</span><br> <span>602 - Arizona (AZ)</span><br>
func Query ¶
Query returns the result of a query from a form input.
Example ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/areacode"
)
func main() {
fmt.Println(areacode.Query("az").Region)
fmt.Println(areacode.Query("arizona").Region[0].HTML())
fmt.Println(areacode.Query("ut").Region[0].HTML())
fmt.Println(areacode.Query("602").AreaCode.HTML())
}
Output: [{Arizona AZ [602]}] <span>Arizona (AZ) - 602</span><br> <span>Utah (UT) - 801</span><br> <span>602 - Arizona (AZ)</span><br>