-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathFRA.coffee
59 lines (47 loc) · 1.62 KB
/
FRA.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
Phone = require('../Phone')
PhoneNumber = require('../PhoneNumber')
# For more info check:
# http://www.howtocallabroad.com/france/
# https://en.wikipedia.org/wiki/Telephone_numbers_in_France
class France
constructor: ->
@countryName = "France"
@countryNameAbbr = "FRA"
@countryCode = '33'
@regex = /^(?:(?:(?:\+|)33)|)(?:0|)[1-9]\d{8}$/
@optionalTrunkPrefix = '0'
@nationalNumberSeparator = ' '
@nationalDestinationCode = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
specialRules: (withoutCountryCode, withoutNDC, ndc) =>
if withoutCountryCode[0] is 0
# Sometimes Frenchs may type their phones with a leading zero
# we should strip that
ndc = withoutCountryCode[1]
withoutNDC = withoutCountryCode.slice(2)
phone = new PhoneNumber(@countryNameAbbr, @countryCode, ndc, withoutNDC)
if ndc in ['6', '7']
phone.isMobile = true
phone.nationalDestinationCode = ''
phone.number = ndc + withoutNDC
else
phone.isMobile = false
return phone
format: (phone, format) =>
separator = @nationalNumberSeparator
fullNumber = phone.nationalDestinationCode + phone.number
switch format
when Phone.NATIONAL, Phone.LOCAL
return @splitNumber('0' + fullNumber).join(separator)
else
return "+" + phone.countryCode + " " + @splitNumber(fullNumber).join(separator)
splitNumber: (number) =>
if number.length is 10
return Phone.compact number.split(/(\d{2})(\d{2})(\d{2})(\d{2})/)
else if number.length is 9
return Phone.compact number.split(/(\d{1})(\d{2})(\d{2})(\d{2})/)
return [number]
# register
france = new France()
Phone.countries['33'] = france
# exports
module.exports = france