mirror of
https://github.com/sky-systems/sky_phone.git
synced 2026-08-31 10:18:57 +00:00
13 lines
487 B
TypeScript
13 lines
487 B
TypeScript
export const PHONE_NUMBER_LENGTH = 10
|
|
|
|
export function normalizePhoneNumber(value: string): string | null {
|
|
const digits = value.replace(/\D/g, '')
|
|
return digits.length === PHONE_NUMBER_LENGTH ? digits : null
|
|
}
|
|
|
|
export function formatPhoneNumber(value: string | number): string {
|
|
const digits = String(value).replace(/\D/g, '').slice(0, PHONE_NUMBER_LENGTH)
|
|
const groups = [digits.slice(0, 3), digits.slice(3, 6), digits.slice(6, 10)]
|
|
return groups.filter(Boolean).join(' ')
|
|
}
|