16 lines
405 B
Swift
16 lines
405 B
Swift
import Foundation
|
|
import PhoneNumberKit
|
|
|
|
final class PhoneNumberNormalizer {
|
|
private let phoneNumberUtility = PhoneNumberUtility()
|
|
|
|
func normalize(_ input: String, region: String) -> String {
|
|
do {
|
|
let number = try phoneNumberUtility.parse(input, withRegion: region, ignoreType: true)
|
|
return phoneNumberUtility.format(number, toType: .e164)
|
|
} catch {
|
|
return input
|
|
}
|
|
}
|
|
}
|