@beenotung/tslib
Version:
utils library in Typescript
60 lines (59 loc) • 2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.is_au_mobile_phone_prefix = is_au_mobile_phone_prefix;
exports.is_au_mobile_phone = is_au_mobile_phone;
exports.to_full_au_mobile_phone = to_full_au_mobile_phone;
exports.format_au_mobile_phone = format_au_mobile_phone;
const utils_1 = require("./utils");
/** ******************************
* Australia mobile phone number *
*********************************/
function is_au_mobile_phone_prefix(tel) {
tel = tel.replace(/^\+61/, '').trim();
return tel.startsWith('4') || tel.startsWith('04');
}
/**
* with/without +61 prefix
*/
function is_au_mobile_phone(tel) {
return to_full_au_mobile_phone(tel) !== '';
}
/**
* landline number example:
* excluding area code: xxxx xxxx
* including area code: (07) xxxx xxxx
* including country and area code: +61 7 xxxx xxxx
* the area code can be 2-digit, being "0x", or 1 digit, being "1"
*
* mobile number example:
* country code: +61
* mobile prefix: e.g. starting with 4 (area and operator code)
* local number: 8 digits
*
* Within Australia, mobile phone numbers begin with 04– the Australian national trunk code 0,
* plus the mobile indicator 4 – followed by eight digits.
*
* This is generally written as 04XX XXX XXX within Australia,
* or as +61 4XX XXX XXX for an international audience.
*
* reference: https://en.wikipedia.org/wiki/Telephone_numbers_in_Australia
*/
function to_full_au_mobile_phone(tel) {
tel = (0, utils_1.to_tel_digits)(tel);
if (tel.length == 8 + 4 && tel.startsWith('+614')) {
return tel;
}
if (tel.length == 8 + 3 && tel.startsWith('614')) {
return '+' + tel;
}
if (tel.length == 8 + 2 && tel.startsWith('04')) {
return '+614' + tel.substring(2);
}
return '';
}
function format_au_mobile_phone(tel) {
tel = to_full_au_mobile_phone(tel);
if (!tel)
return tel;
return (0, utils_1.format_tel_with_pattern)(tel, '+61 4xx xxx xxx');
}