1.0.5 • Published 3 years ago
phone-carrier v1.0.5
phone-carrier
Installation
npm install phone-carrier
Description
- You have a VALID cell phone number.
- You want the cell phone carrier's name!
- Input it into the mapper this package provides to get it.
- Use it as you would Google's libphonenumber's PhoneNumberToCarrierMapper in Java
- Is a TypeScript rendition of PhoneNumberToCarrierMapper because the JavaScript version of libphonenumber on NPM didn't have a PhoneNumberToCarrierMapper
- Batteries included. Mobile carrier names are read from included binary-encoded files.
- Has no error handling (we read from files). Be sure to try-catch your async functions and .catch your promises.
- Depends upon NPM package libphonenumber-js
Quick Start / API
// Example 1: ESM and await syntax
import PhoneNumberToCarrierMapper from 'phone-carrier';
async function lookup(msisdn) {
const mapper = PhoneNumberToCarrierMapper.getInstance();
const carrierName = await mapper.getNameForValidNumber(msisdn);
return carrierName;
}
console.log(lookup(`+41798765432`)); // Swisscom
// Example 2: CommonJS and promise syntax
const { PhoneNumberToCarrierMapper } = require('phone-carrier')
const mapper = PhoneNumberToCarrierMapper.getInstance()
mapper.getNameForValidNumber(`+917897888888`).then(console.log) // AirTel