tranxs
Version:
Tranxs is a powerful and easy-to-use Node.js library for integrating M-Pesa payment services into your application. It provides seamless support for all major M-Pesa transactions, including STK Push, B2C, B2B, C2B, Reversal, Account Balance, and Transacti
17 lines • 589 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.cleanPhoneNumber = cleanPhoneNumber;
function cleanPhoneNumber(input) {
const normalized = input.replace(/[\s\-+]/g, "");
if (/^07\d{8}$/.test(normalized)) {
return "254" + normalized.slice(1);
}
if (/^01[0-1]\d{7}$/.test(normalized)) {
return "254" + normalized.slice(1);
}
if (/^254(7\d{8}|1[0-1]\d{7})$/.test(normalized)) {
return normalized;
}
throw new Error("Invalid phone number format for M-Pesa.");
}
//# sourceMappingURL=cleanPhone.js.map