UNPKG

@phonecheck/phone-number-validator-js

Version:

Validate, parse, and enrich international phone numbers — geocoding, carrier lookup, and timezone resolution. Sync (Node) + async (serverless) APIs, platform adapters, and a CLI.

40 lines (39 loc) 2.15 kB
import type { CarrierLocale, GeocoderLocale, MaybePhoneNumber, ResourceLoader } from './types'; /** Replace (or clear, with `null`) the loader used by every lookup function. */ export declare function setResourceLoader(loader: ResourceLoader | null): void; export declare function getResourceLoader(): ResourceLoader | null; /** * Geographical info (city / region) for the given phone number, in the * requested locale. Falls back to English when the locale-specific table is * missing for that country code. Returns `null` for landline-only, * unrecognized, or invalid numbers. */ export declare function geocoder(phoneNumber: MaybePhoneNumber, locale?: GeocoderLocale): string | null; /** * Original carrier of the phone number (Google libphonenumber's * carrier-mapping table — does **not** reflect ports). Returns `null` for * landlines and unmapped ranges. */ export declare function carrier(phoneNumber: MaybePhoneNumber, locale?: CarrierLocale): string | null; /** Timezones associated with the number (one or more IANA zone IDs). */ export declare function timezones(phoneNumber: MaybePhoneNumber): string[] | null; export declare function geocoderAsync(phoneNumber: MaybePhoneNumber, locale?: GeocoderLocale): Promise<string | null>; export declare function carrierAsync(phoneNumber: MaybePhoneNumber, locale?: CarrierLocale): Promise<string | null>; export declare function timezonesAsync(phoneNumber: MaybePhoneNumber): Promise<string[] | null>; export interface EnrichmentResult { geocode: string | null; carrier: string | null; timezones: string[] | null; } export interface EnrichOptions { /** Geocoder locale; falls back to `en` when missing. */ locale?: GeocoderLocale; /** Carrier locale; falls back to `en` when missing. */ carrierLocale?: CarrierLocale; } /** * One-shot lookup: geocode + carrier + timezones in parallel. Convenient when * you'd otherwise call all three async functions back-to-back. Sync callers * should call the three sync functions directly. */ export declare function enrichPhoneNumber(phoneNumber: MaybePhoneNumber, options?: EnrichOptions): Promise<EnrichmentResult>;