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.

69 lines (68 loc) 2.4 kB
/** * Workers KV surface — overloaded to match the runtime contract. The * `arrayBuffer` overload satisfies the resource loader's `KvNamespace`; the * `json` overload powers `KvResultCache`. */ interface KVNamespace { get(key: string, type: 'arrayBuffer'): Promise<ArrayBuffer | null>; get<T = unknown>(key: string, type: 'json'): Promise<T | null>; get(key: string, type?: 'text'): Promise<string | null>; put(key: string, value: string | ArrayBuffer | ReadableStream, options?: { expirationTtl?: number; }): Promise<void>; delete(key: string): Promise<void>; } interface DurableObjectNamespace { idFromName(name: string): DurableObjectId; get(id: DurableObjectId): DurableObjectStub; } interface DurableObjectId { toString(): string; } interface DurableObjectStub { fetch(request: Request): Promise<Response>; } interface DurableObjectState { storage: DurableObjectStorage; } interface DurableObjectStorage { get<T = unknown>(key: string): Promise<T | undefined>; put<T = unknown>(key: string, value: T): Promise<void>; delete(key: string): Promise<void>; } export interface CloudflareRequest extends Request { cf?: { country?: string; colo?: string; timezone?: string; }; } export interface CloudflareEnv { /** Optional KV namespace holding the BSON resources tree. */ PHONE_RESOURCES?: KVNamespace; /** Optional KV namespace caching per-number validation results. */ RESULT_CACHE?: KVNamespace; /** Optional Durable Object binding. */ PHONE_VALIDATOR?: DurableObjectNamespace; [key: string]: unknown; } export interface CloudflareContext { waitUntil(promise: Promise<unknown>): void; passThroughOnException(): void; } declare function workerHandler(request: CloudflareRequest, env: CloudflareEnv, ctx: CloudflareContext): Promise<Response>; /** * Durable Object that owns a per-instance in-memory LRU. Useful when you want * a single warm node per geography to avoid cold BSON deserialization. */ export declare class PhoneValidatorDO { constructor(_state: DurableObjectState, _env: CloudflareEnv); fetch(request: Request): Promise<Response>; } declare const _default: { fetch: typeof workerHandler; workerHandler: typeof workerHandler; PhoneValidatorDO: typeof PhoneValidatorDO; }; export default _default; export { workerHandler };