@beenotung/tslib
Version:
utils library in Typescript
62 lines (61 loc) • 1.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.is_mo_mobile_phone_prefix = is_mo_mobile_phone_prefix;
exports.is_mo_mobile_phone = is_mo_mobile_phone;
exports.to_full_mo_mobile_phone = to_full_mo_mobile_phone;
exports.format_mo_mobile_phone = format_mo_mobile_phone;
const utils_1 = require("./utils");
/** ******************************
* Macau mobile phone number *
*********************************/
/**
* starts with 6
* news: https://en.wikipedia.org/wiki/Telephone_numbers_in_Macau
* */
function is_mo_mobile_phone_prefix(tel) {
tel = tel.replace(/^\+853/, '').trim();
switch (tel[0]) {
case '6':
return true;
default:
return false;
}
}
/**
* with/without +853 prefix
*/
function is_mo_mobile_phone(tel) {
return to_full_mo_mobile_phone(tel) !== '';
}
/**
* very forgiving
*
* @return +853xxxxyyyy if valid
* empty string if not valid
* */
function to_full_mo_mobile_phone(tel) {
tel = (0, utils_1.to_tel_digits)(tel);
if (tel.length === 8 && is_mo_mobile_phone_prefix(tel)) {
return '+853' + tel;
}
if (tel.length === 8 + 3 &&
tel.startsWith('853') &&
is_mo_mobile_phone_prefix(tel.substring(3))) {
return '+' + tel;
}
if (tel.length === 8 + 4 &&
tel.startsWith('+853') &&
is_mo_mobile_phone_prefix(tel.substring(4))) {
return tel;
}
return '';
}
/**
* @returns +853 xxxx yyyy if valid
*/
function format_mo_mobile_phone(tel) {
tel = to_full_mo_mobile_phone(tel);
if (!tel)
return tel;
return (0, utils_1.format_tel_with_pattern)(tel, '+853 xxxx yyyy');
}