nationid - v2.2.1
    Preparing search index...

    Function luhnCheckDigit

    • Compute the Luhn check digit for a body of digits (without the check digit).

      Returns the check digit (0-9) that, when appended, makes the full number Luhn-valid. Useful for generating synthetic test data or for the trailing digit on emitted document numbers.

      Parameters

      • body: string

        Digit-only string WITHOUT the check digit position.

      Returns number

      Integer in [0, 9] — the digit to append to make body Luhn-valid.

      if body contains non-digit characters.

      import { luhnCheckDigit, luhnValid } from "nationid/algorithms";

      const body = "7992739871";
      const cd = luhnCheckDigit(body); // 3
      luhnValid(body + String(cd)); // true