Skip to content

Commit

Permalink
fix: parses internationalized phone number with leading zero
Browse files Browse the repository at this point in the history
i.e. +46 0700123456
  • Loading branch information
believer committed Dec 10, 2018
1 parent c697899 commit eff0010
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/__tests__/parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('#phoneNumberParser', () => {
})

it('parses numbers with +46', () => {
expect(phoneNumberParser('+46 0700123456')).toEqual('070-012 34 56')
expect(phoneNumberParser('+46701234567')).toEqual('070-123 45 67')
})

Expand Down
2 changes: 2 additions & 0 deletions lib/utils/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export const normalize = (phoneNumber: string): string => {

if (normalizedNumber.substr(0, 4) === '0046') {
return `0${normalizedNumber.substr(4)}`
} else if (normalizedNumber.substr(0, 3) === '460') {
return `0${normalizedNumber.substr(3)}`
} else if (normalizedNumber.substr(0, 2) === '46') {
return `0${normalizedNumber.substr(2)}`
}
Expand Down

0 comments on commit eff0010

Please sign in to comment.