UNPKG

@takentrade/takentrade-libs

Version:
18 lines (17 loc) 641 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatPhoneNumber = formatPhoneNumber; exports.maskPhoneNumber = maskPhoneNumber; function formatPhoneNumber(phone) { // Remove any non-digit characters const cleaned = phone.replace(/\D/g, ''); // Ensure the number starts with country code if (!cleaned.startsWith('234') && cleaned.startsWith('0')) { return '234' + cleaned.slice(1); } return cleaned; } function maskPhoneNumber(phone) { const cleaned = formatPhoneNumber(phone); return (cleaned.slice(0, 4) + '*'.repeat(cleaned.length - 7) + cleaned.slice(-3)); }