forked from catamphetamine/libphonenumber-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexports.min.test.js
123 lines (90 loc) · 5.74 KB
/
exports.min.test.js
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import {
ParseError,
parsePhoneNumber,
parsePhoneNumberFromString,
findNumbers,
searchNumbers,
PhoneNumberMatcher,
AsYouType,
Metadata,
isSupportedCountry,
getCountryCallingCode,
getExtPrefix,
formatIncompletePhoneNumber,
parseIncompletePhoneNumber,
parsePhoneNumberCharacter,
parseDigits,
getExampleNumber,
parseRFC3966,
formatRFC3966
} from '../min/index'
import examples from '../examples.mobile.json'
describe('exports/min', () => {
it('should export ES6', () => {
expect(ParseError).to.be.a('function')
parsePhoneNumber('+12133734253').nationalNumber.should.equal('2133734253')
parsePhoneNumber('2133734253', 'US').nationalNumber.should.equal('2133734253')
parsePhoneNumber('2133734253', { defaultCountry: 'US' }).nationalNumber.should.equal('2133734253')
parsePhoneNumber('2133734253', undefined, { defaultCountry: 'US' }).nationalNumber.should.equal('2133734253')
parsePhoneNumberFromString('+12133734253').nationalNumber.should.equal('2133734253')
expect(parsePhoneNumberFromString('2133734253')).to.be.undefined
// Test "min" metadata.
expect(parsePhoneNumber('9150000000', 'RU').getType()).to.be.undefined
expect(parsePhoneNumber('91187654321', 'AR').getType()).to.be.undefined
expect(parsePhoneNumber('51234567', 'EE').getType()).to.be.undefined
findNumbers('+12133734253').should.deep.equal([{ country: 'US', phone: '2133734253', startsAt: 0, endsAt: 12 }])
findNumbers('2133734253', 'US').should.deep.equal([{ country: 'US', phone: '2133734253', startsAt: 0, endsAt: 10 }])
findNumbers('2133734253', { defaultCountry: 'US' }).should.deep.equal([{ country: 'US', phone: '2133734253', startsAt: 0, endsAt: 10 }])
findNumbers('2133734253', undefined, { defaultCountry: 'US' }).should.deep.equal([{ country: 'US', phone: '2133734253', startsAt: 0, endsAt: 10 }])
searchNumbers('+12133734253')[Symbol.iterator]().next.should.be.a('function')
searchNumbers('2133734253', 'US')[Symbol.iterator]().next.should.be.a('function')
searchNumbers('2133734253', { defaultCountry: 'US' })[Symbol.iterator]().next.should.be.a('function')
searchNumbers('2133734253', undefined, { defaultCountry: 'US' })[Symbol.iterator]().next.should.be.a('function')
new PhoneNumberMatcher('+12133734253').find.should.be.a('function')
new AsYouType().input('+12133734253').should.equal('+1 213 373 4253')
new AsYouType('US').input('2133734253').should.equal('(213) 373-4253')
isSupportedCountry('KZ').should.equal(true)
getCountryCallingCode('KZ').should.equal('7')
getExtPrefix('US').should.equal(' ext. ')
formatIncompletePhoneNumber('+121337342').should.deep.equal('+1 213 373 42')
formatIncompletePhoneNumber('21337342', 'US').should.deep.equal('(213) 373-42')
parseIncompletePhoneNumber('+1 213 373 42').should.equal('+121337342')
parsePhoneNumberCharacter('+').should.equal('+')
parseDigits('+123').should.equal('123')
getExampleNumber('RU', examples).nationalNumber.should.equal('9123456789')
parseRFC3966('tel:+12133734253').should.deep.equal({ number: '+12133734253' })
formatRFC3966({ number: '+12133734253' }).should.equal('tel:+12133734253')
})
it('should export CommonJS', () => {
const Library = require('../min/index.commonjs')
expect(Library.ParseError).to.be.a('function')
Library.parsePhoneNumber('+12133734253').nationalNumber.should.equal('2133734253')
Library.parsePhoneNumber('2133734253', 'US').nationalNumber.should.equal('2133734253')
Library.parsePhoneNumber('2133734253', { defaultCountry: 'US' }).nationalNumber.should.equal('2133734253')
Library.parsePhoneNumber('2133734253', undefined, { defaultCountry: 'US' }).nationalNumber.should.equal('2133734253')
Library.parsePhoneNumberFromString('+12133734253').nationalNumber.should.equal('2133734253')
expect(Library.parsePhoneNumberFromString('2133734253')).to.be.undefined
Library.findNumbers('+12133734253').should.deep.equal([{ country: 'US', phone: '2133734253', startsAt: 0, endsAt: 12 }])
Library.findNumbers('2133734253', 'US').should.deep.equal([{ country: 'US', phone: '2133734253', startsAt: 0, endsAt: 10 }])
Library.findNumbers('2133734253', { defaultCountry: 'US' }).should.deep.equal([{ country: 'US', phone: '2133734253', startsAt: 0, endsAt: 10 }])
Library.findNumbers('2133734253', undefined, { defaultCountry: 'US' }).should.deep.equal([{ country: 'US', phone: '2133734253', startsAt: 0, endsAt: 10 }])
Library.searchNumbers('+12133734253')[Symbol.iterator]().next.should.be.a('function')
Library.searchNumbers('2133734253', 'US')[Symbol.iterator]().next.should.be.a('function')
Library.searchNumbers('2133734253', { defaultCountry: 'US' })[Symbol.iterator]().next.should.be.a('function')
Library.searchNumbers('2133734253', undefined, { defaultCountry: 'US' })[Symbol.iterator]().next.should.be.a('function')
new Library.PhoneNumberMatcher('+12133734253', undefined).find.should.be.a('function')
new Library.AsYouType().input('+12133734253').should.equal('+1 213 373 4253')
new Library.AsYouType('US').input('2133734253').should.equal('(213) 373-4253')
Library.isSupportedCountry('KZ').should.equal(true)
Library.getCountryCallingCode('KZ').should.equal('7')
Library.getExtPrefix('US').should.equal(' ext. ')
Library.formatIncompletePhoneNumber('+121337342').should.deep.equal('+1 213 373 42')
Library.formatIncompletePhoneNumber('21337342', 'US').should.deep.equal('(213) 373-42')
Library.parseIncompletePhoneNumber('+1 213 373 42').should.equal('+121337342')
Library.parsePhoneNumberCharacter('+').should.equal('+')
Library.parseDigits('+123').should.equal('123')
Library.getExampleNumber('RU', examples).nationalNumber.should.equal('9123456789')
Library.parseRFC3966('tel:+12133734253').should.deep.equal({ number: '+12133734253' })
Library.formatRFC3966({ number: '+12133734253' }).should.equal('tel:+12133734253')
})
})