nhb-toolbox
Version:
A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.
12 lines (11 loc) • 597 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCountryByPhone = getCountryByPhone;
const primitives_1 = require("../guards/primitives");
const countries_1 = require("../object/countries");
function getCountryByPhone(phone) {
if (!(0, primitives_1.isNonEmptyString)(phone) && !(0, primitives_1.isNumber)(phone))
return [];
const normalized = ((0, primitives_1.isString)(phone) ? phone : String(phone)).replace(/\D/g, '');
return countries_1.COUNTRIES.filter((country) => normalized.startsWith(country.country_code.replace(/-/g, '')));
}