nationalES function

String nationalES(
  1. String bban,
  2. BbanStructure structure
)

Implementation

String nationalES(String bban, BbanStructure structure) {
  const List<int> weights = [1, 2, 4, 8, 5, 10, 9, 7, 3, 6];
  final String combined = [PartType.BANK_CODE, PartType.BRANCH_CODE]
      .map((p) => structure.extractValueMust(bban, p))
      .join("");

  int to11(int v) {
    if (v == 10) {
      return 1;
    } else if (v == 11) {
      return 0;
    }
    return v;
  }

  final d1 = to11(mod11("00$combined", weights));
  final d2 = to11(mod11(
      structure.extractValueMust(bban, PartType.ACCOUNT_NUMBER), weights));

  return "$d1$d2";
}