simujs
Version:
Tanzanian phone number detection library based on public TCRA numbering data (not affiliated with TCRA).
17 lines (16 loc) • 528 B
JavaScript
import { PhoneNumberUtil } from "google-libphonenumber";
export const normalize = (phone) => {
var _a;
const phoneUtil = PhoneNumberUtil.getInstance();
try {
const parsed = phoneUtil.parseAndKeepRawInput(phone, "TZ");
if (!phoneUtil.isValidNumber(parsed))
return;
if (parsed.getCountryCode() !== 255)
return;
return (_a = parsed.getNationalNumber()) === null || _a === void 0 ? void 0 : _a.toString();
}
catch (_b) {
return undefined;
}
};