nationid - v2.2.1
    Preparing search index...

    Function lastN

    • Returns the trailing n characters of input after normalization.

      Always operates on the canonical (normalized) form so that any user-visible formatting variation collapses to the same suffix. Common use case: index a last4 column for search alongside the encrypted full document.

      Parameters

      • code: DocumentTypeCode

        Document type whose normalization rules apply.

      • input: string

        Raw user input.

      • n: number = DEFAULT_N

        Number of trailing chars to return (default 4). Values <= 0 return the empty string. If the normalized form is shorter than n, the full normalized form is returned.

      Returns string

      The last n chars of the normalized form.

      if code is not registered.

      import { lastN } from "nationid/pii";

      lastN("BR_CNPJ", "12.345.678/0001-90"); // "0190"
      lastN("BR_CNPJ", "12345678000190", 6); // "000190"
      lastN("SV_DUI", "04567890-3"); // "8903"