UNPKG

phone-number-lookup

Version:

phone-number-lookup is TS written library that provides information about a phone number, such as: Country, Prefix, Type (Mobile/Fixed/VoIP), Carrier etc. Every data is processed locally, so no internet connection is needed. Made primarily for personal-us

32 lines (31 loc) 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getInformation = void 0; function getInformation(number, data) { let phoneInformation = { name: '', dialCode: '', isoCode: '', flag: '', type: '', }; let prefixLength = 2; data.forEach((value, key) => { if (number.startsWith(key.dialCode)) { const splittedInfromation = value[0].Destination.split(' - '); phoneInformation = Object.assign(Object.assign({}, key), { type: splittedInfromation[1], carrier: splittedInfromation[2] }); for (let index = 0; index < value.length; index++) { if (number.startsWith('+' + value[index].Prefix.toString())) { if (value[index].Prefix.toString().length > prefixLength) { prefixLength = value[index].Prefix.toString().length; const splittedInfromation = value[index].Destination.split(' - '); phoneInformation.type = splittedInfromation[1]; phoneInformation.carrier = splittedInfromation[2]; } } } } }); return phoneInformation; } exports.getInformation = getInformation;