uni-phone
Version:
a glossary of universally intuitive time, date, and duration domain literals
22 lines • 856 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.asUniPhoneInHumanWords = void 0;
/**
* .what = casts a uni phone into human words
* .example
* - +13335557777 => (333) 555-7777
*/
const asUniPhoneInHumanWords = (input) => {
// Validate input: must start with '+' followed by digits
const phoneRegex = /^\+(\d{1,3})(\d{3})(\d{3})(\d{4})$/;
const match = input.number.match(phoneRegex);
if (!match) {
throw new Error('Invalid UniPhone format. Expected format: +<country-code><10-digit-phone>');
}
// Extract groups
const [, , areaCode, centralOfficeCode, lineNumber] = match;
// Format the phone number
return `(${areaCode}) ${centralOfficeCode}-${lineNumber}`;
};
exports.asUniPhoneInHumanWords = asUniPhoneInHumanWords;
//# sourceMappingURL=asUniPhoneInHumanWords.js.map
;