-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathAUS.coffee
63 lines (51 loc) · 2.09 KB
/
AUS.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
62
63
Phone = require('../Phone')
PhoneNumber = require('../PhoneNumber')
class Australia
constructor: ->
@countryName = "Australia"
@countryNameAbbr = "AUS"
@countryCode = '61'
@regex = /^(?:(?:(?:\+|)(?:61|)(?:0|)|))([1-5,7-8])[0-9]{8,9}$/
@optionalTrunkPrefix = '0'
@nationalNumberSeparator = ' '
@nationalDestinationCode =
["1","2","3","4","5","7","8"]
@mobileDestinationCode = ["4"]
@internationalFormatRegex = /^((?:\+|)(61))(\d{0,10})$/
specialRules: (withoutCountryCode, withoutNDC, ndc) =>
phone = new PhoneNumber(@countryNameAbbr, @countryCode, ndc, withoutNDC)
isInternationalFormat = @internationalFormatRegex.test(withoutCountryCode)
if isInternationalFormat
countryCodeRegex = new RegExp "^"+@countryCode+'('+@optionalTrunkPrefix+'|)'
withoutCountryCode = withoutCountryCode.replace(countryCodeRegex, "")
ndc = withoutCountryCode[0]
phone = new PhoneNumber(@countryNameAbbr, @countryCode, ndc, withoutCountryCode.substr 1)
if withoutCountryCode[0] in @mobileDestinationCode
phone.isMobile = true
return phone
format: (phone, format = Phone.NATIONAL) =>
resultString = ""
fullNumber = phone.nationalDestinationCode + phone.number
separator = @nationalNumberSeparator
if phone.nationalDestinationCode
isMobile = phone.nationalDestinationCode in @mobileDestinationCode
if isMobile
resultString += @optionalTrunkPrefix + phone.nationalDestinationCode
resultString += @splitNumber(phone.number, isMobile).join(separator)
else
resultString += '(' + @optionalTrunkPrefix + phone.nationalDestinationCode + ') '
resultString += @splitNumber(phone.number).join(separator)
return resultString
splitNumber: (number, isMobile = false) =>
if number.length is 8 and isMobile
return Phone.compact number.split(/(\d{2})(\d{3})(\d{3})/)
else if number.length is 8
return Phone.compact number.split(/(\d{4})(\d{4})/)
else if number.length is 9
return Phone.compact number.split(/(\d{3})(\d{3})(\d{3})/)
return [number]
# register
australia = new Australia()
Phone.countries['61'] = australia
# exports
module.exports = australia