@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.
59 lines (58 loc) • 1.96 kB
TypeScript
/**
* Request body classification shared by every serverless adapter.
*
* Every adapter accepts the same JSON shape:
* { phoneNumber: "+14155552671", defaultCountry?: "US", locale?: "en", carrierLocale?: "en" }
*
* Or a batch:
* { phoneNumbers: ["+14155552671", "+442079460958"], defaultCountry?: "US", ... }
*
* Centralising the shape (and the 100-entry batch cap) means a future change
* lands in one place instead of six adapter files.
*/
import type { CarrierLocale, GeocoderLocale } from '../../types';
export declare const MAX_BATCH_SIZE = 100;
/** Fields shared by request bodies and downstream `BatchOptions`. */
interface ValidationCommon {
defaultCountry?: string;
locale?: GeocoderLocale;
carrierLocale?: CarrierLocale;
/** Run the geocoder lookup (default: true). */
geocode?: boolean;
/** Run the carrier lookup (default: true). */
carrier?: boolean;
/** Run the timezone lookup (default: true). */
timezones?: boolean;
}
export interface ValidationRequestBody extends ValidationCommon {
phoneNumber?: string;
phoneNumbers?: string[];
}
export type BatchOptions = ValidationCommon;
export type ValidationDispatch = {
kind: 'single';
phoneNumber: string;
options: BatchOptions;
} | {
kind: 'batch';
phoneNumbers: string[];
options: BatchOptions;
};
export interface ValidationFailure {
kind: 'invalid';
status: 400;
message: string;
}
export type BatchValidation = {
ok: true;
phoneNumbers: string[];
} | {
ok: false;
status: 400;
message: string;
};
/** Lift the locale + enrichment fields out of a request body. */
export declare function extractBatchOptions(body: ValidationRequestBody): BatchOptions;
export declare function validateBatchField(phoneNumbers: unknown): BatchValidation;
export declare function classifyRequest(body: ValidationRequestBody | null | undefined): ValidationDispatch | ValidationFailure;
export {};