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) 1.5 kB
/** * `fetch`-backed resource loader for CDN / HTTP-hosted `.bson` tables. * * Use this when resources are deployed alongside the function (e.g. via * `assets` in Vercel, or a public R2 / S3 bucket fronted by a CDN). The * loader has no platform deps — `fetch` is global on all modern runtimes. */ import type { ResourceLoader } from '../../types'; export interface FetchResourceLoaderOptions { /** * Base URL where the `resources/` tree is hosted. Must include the trailing * `/` because relative paths (`geocodes/en/41.bson`) are appended verbatim. */ baseUrl: string; /** * Extra headers to attach to each fetch (e.g. `Authorization` for a * private bucket). Defaults to no extra headers. */ headers?: Record<string, string>; /** * Per-request timeout in milliseconds. The loader uses `AbortSignal.timeout` * which is supported on Node 17.3+ and every edge runtime. Defaults to * 5000 ms. */ timeoutMs?: number; /** * Optional `fetch` override (tests inject `mock-fetch`; some runtimes prefer * a custom implementation). Defaults to `globalThis.fetch`. */ fetch?: typeof fetch; } export declare class FetchResourceLoader implements ResourceLoader { private readonly baseUrl; private readonly headers; private readonly timeoutMs; private readonly fetchImpl; constructor(options: FetchResourceLoaderOptions); loadResource(path: string): Promise<Uint8Array | null>; }