nationid - v2.2.1
    Preparing search index...

    Function getSpec

    • Lookup a DocumentSpec by its stable code.

      Useful when you need direct access to the spec's regex, mask, country, or confidence metadata without going through the wrapped validate/format helpers. The returned spec is the same singleton instance held in the internal registry; do not mutate it.

      Generic over the document type code: passing a literal narrows the returned spec to DocumentSpec<"MX_CURP"> so .code keeps its literal type instead of widening to the whole DocumentTypeCode union. The runtime invariant REGISTRY.get(code).code === code justifies the cast at the boundary.

      Type Parameters

      • C extends DocumentTypeCode

        The literal DocumentTypeCode of the requested spec.

      Parameters

      • code: C

        Stable DocumentTypeCode such as "SV_DUI" or "BR_CNPJ".

      Returns DocumentSpec<C>

      The DocumentSpec<C> registered for code, with a code-narrowed return type for richer IDE inference.

      if code is not registered. Call listSupportedCodes() to inspect the set of known codes.

      import { getSpec } from "nationid";

      const dui = getSpec("SV_DUI");
      dui.code; // "SV_DUI" — literal, not the whole union
      console.log(dui.country); // "SV"
      console.log(dui.confidence); // "moderate"