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.

45 lines (44 loc) 1.44 kB
/** * Minimal flag parser for the `phone-validate` CLI. * * Hand-rolled because the surface is small (~12 flags) and pulling in * `commander` / `yargs` would balloon the published bundle for every * consumer regardless of whether they use the CLI. * * The parser is table-driven: `BOOLEAN_FLAGS` and `VALUE_FLAGS` map flag * names to small applicator functions that mutate the result. New flags get * one new map entry — no extra switch cases. */ import type { CarrierLocale, GeocoderLocale } from '../types'; export interface ParsedArgs { /** Phone number to validate (positional). */ phoneNumber: string; defaultCountry?: string; locale: GeocoderLocale; carrierLocale: CarrierLocale; enrichGeocode: boolean; enrichCarrier: boolean; enrichTimezones: boolean; /** Output format. */ format: 'text' | 'json' | 'pretty'; quiet: boolean; debug: boolean; /** Directory to write the JSON result; null disables file logging. */ logDir: string | null; } export interface ParsedHelp { kind: 'help'; } export interface ParsedVersion { kind: 'version'; } export interface CliArgError { kind: 'error'; messages: string[]; exitCode: number; } export type ParseResult = ({ kind: 'args'; } & ParsedArgs) | ParsedHelp | ParsedVersion | CliArgError; export declare function parseArgs(argv: readonly string[]): ParseResult; export declare function helpText(): string;