degachejs
Version:
A Tunisian utility library for working with CIN, phone numbers, addresses, and more
18 lines (17 loc) • 740 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatPhoneNumber = void 0;
const constants_1 = require("../constants");
const validators_1 = require("../validators");
/**
* Formats a Tunisian phone number
* @param phoneNumber - The phone number to format
* @returns formatted phone number with country code and proper spacing, null phone number is not valid
*/
const formatPhoneNumber = (phoneNumber) => {
if (!(0, validators_1.validatePhoneNumber)(phoneNumber))
return null;
const cleaned = phoneNumber.replace(/\D/g, "");
return `${constants_1.COUNTRY_CODE} ${cleaned.slice(0, 2)} ${cleaned.slice(2, 5)} ${cleaned.slice(5)}`;
};
exports.formatPhoneNumber = formatPhoneNumber;