nationid - v2.2.1
    Preparing search index...

    Function getErrorMessage

    • Returns a localized human-readable error message for a ParseError.

      Falls back to DEFAULT_LOCALE when locale is unsupported, and to a generic per-locale message when the error kind is unknown (forward-compat with future kinds added in core/types.ts).

      When documentName is omitted, the message uses neutral phrasing ("the document" / "el documento" / "o documento").

      Parameters

      • error: ParseError

        The ParseError returned by parse() on failure.

      • Optionallocale: Locale

        Target locale. Unsupported values fall back to DEFAULT_LOCALE.

      • OptionaldocumentName: string

        Optional human-readable document name to interpolate into the {document} slot (e.g. "DUI", "CPF").

      Returns string

      A fully-rendered localized error message.

      import { parse } from "nationid";
      import { getErrorMessage } from "nationid/i18n";

      const r = parse("SV_DUI", "12");
      if (!r.ok) {
      getErrorMessage(r.error, "es", "DUI"); // "El DUI es demasiado corto."
      }

      getErrorMessage({ kind: "empty" }, "en");
      // "Please enter a value."

      getErrorMessage({ kind: "invalid_format" }, "pt", "CPF");
      // "O formato do CPF não é válido."