package com.seven.ikar.kotlin.core.contacts

object PhoneNumberNormalizer {
    fun normalize(phoneNumber: String?): String? {
        if (phoneNumber.isNullOrBlank()) {
            return null
        }

        val digits = phoneNumber.filter(Char::isDigit)
        if (digits.length < 10) {
            return null
        }

        return if (digits.length == 10) digits else digits.takeLast(10)
    }
}
