-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathGTM.coffee
61 lines (47 loc) · 1.49 KB
/
GTM.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Phone = require('../Phone')
PhoneNumber = require('../PhoneNumber')
# For more info check:
# https://en.wikipedia.org/wiki/Telephone_numbers_in_Guatemala
# http://www.howtocallabroad.com/guatemala/
class Guatemala
constructor: ->
@countryName = "Guatemala"
@countryNameAbbr = "GTM"
@countryCode = '502'
@regex = /^(?:(?:\+|)502|)(?:[2-7]\d{7})$/
@nationalNumberSeparator = ' '
@nationalDestinationCode = ['2', '6', '7', '3', '4', '5']
@mobileNumbers = ['3', '4', '5']
specialRules: (withoutCountryCode, withoutNDC, ndc) =>
phone = new PhoneNumber(@countryNameAbbr, @countryCode, ndc, withoutNDC)
if withoutCountryCode.length isnt 8
return null
if ndc and withoutNDC[0] in @mobileNumbers
phone.isMobile = true
phone.nationalDestinationCode = ''
phone.number = withoutCountryCode
else
phone.isMobile = false
return phone
format: (phone, format) =>
resultString = ""
fullNumber = phone.nationalDestinationCode + phone.number
splitNumber = @splitNumber(fullNumber)
switch format
when Phone.INTERNATIONAL
resultString = "+" + phone.countryCode + " "
resultString += splitNumber.join(" ")
else
separator = @nationalNumberSeparator
resultString += splitNumber.join(separator)
return resultString
splitNumber: (number) =>
switch number.length
when 8
return Phone.compact number.split(/(\d{4})(\d{4})/)
return [number]
# register
guatemala = new Guatemala()
Phone.countries['502'] = guatemala
# exports
module.exports = guatemala