A glossary of intuitive, universally unambiguous phone definitions and useful procedures.
declare a universally unambiguous serialization format for phones
UniPhoneNumber
= E.164UniPhone
={ number: UniPhoneNumber }
usecases
- clarify the format a string should be in (
const phoneNumber: UniPhoneNumber = '+13231110101'
) - cast date to universal format (
const phoneNumber: UniPhoneNumber = asUniPhoneNumber('(323) 111-0101')
) - narrow type of strings with runtime validation (
if (!isUniPhoneNumber(input)) throw new Error('wrong format')
)
npm install domain-glossary-phone
const phone: UniPhone;
const phoneNumber: UniPhoneNumber;
const phone: UniPhone = { number: isUniPhoneNumber.assure('+13231110101') }
const phone: UniPhone = { number: asUniPhoneNumber('(323) 111-0101') }