nationid - v2.2.1
    Preparing search index...

    Function mod11WeightedSum

    • Compute weighted sum mod 11, given digits and weights.

      Weights are applied 1-to-1 with digits from left to right. If weights is shorter than digits, an error is thrown — country-specific code must pre-extend or cycle weights as needed.

      Returns the raw sum (NOT yet mod 11). Country-specific code typically applies 11 - (sum % 11) and maps the special cases (0 / 10 / 11) per its own variant.

      Parameters

      • digits: string

        Digit-only string. Each char must be '0'..'9'.

      • weights: readonly number[]

        Array of integer weights with weights.length === digits.length.

      Returns number

      The raw weighted sum (not yet reduced).

      if digits and weights differ in length, or if digits contains a non-digit character.

      import { mod11WeightedSum } from "nationid/algorithms";

      // BR CPF first check-digit weights are [10,9,8,7,6,5,4,3,2]
      const sum = mod11WeightedSum("111444777", [10,9,8,7,6,5,4,3,2]);
      const checkDigit = ((sum * 10) % 11) % 10; // CPF-specific reduction