LCOV - code coverage report
Current view: top level - lib - extensions.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 103 103 100.0 %
Date: 2022-09-21 09:53:35 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:iban_utilities_lib/enums_countries.dart';
       2             : 
       3             : extension StringExtensions on String {
       4             :   /// Ülkeye göre 'Ülke Kodu' bilgisini geri döndürür.
       5           2 :   String getCountryCode(Country country) {
       6             :     switch (country) {
       7           2 :       case Country.turkish:
       8             :         {
       9           4 :           return prepareIban().substring(0, 2);
      10             :         }
      11             : 
      12           2 :       case Country.england:
      13             :         {
      14           2 :           return prepareIban().substring(0, 2);
      15             :         }
      16             : 
      17           2 :       case Country.germany:
      18             :         {
      19           2 :           return prepareIban().substring(0, 2);
      20             :         }
      21             : 
      22           2 :       case Country.france:
      23             :         {
      24           2 :           return prepareIban().substring(0, 2);
      25             :         }
      26             : 
      27           2 :       case Country.italy:
      28             :         {
      29           2 :           return prepareIban().substring(0, 2);
      30             :         }
      31             : 
      32             :       default:
      33             :         {
      34             :           return "";
      35             :         }
      36             :     }
      37             :   }
      38             : 
      39             :   /// Ülkeye göre 'Kontrol Numarası' bilgisini geri döndürür.
      40           2 :   String getCheckDigits(Country country) {
      41             :     switch (country) {
      42           2 :       case Country.turkish:
      43             :         {
      44           2 :           return prepareIban().substring(2, 4);
      45             :         }
      46             : 
      47           2 :       case Country.england:
      48             :         {
      49           2 :           return prepareIban().substring(2, 4);
      50             :         }
      51             : 
      52           2 :       case Country.germany:
      53             :         {
      54           2 :           return prepareIban().substring(2, 4);
      55             :         }
      56             : 
      57           2 :       case Country.france:
      58             :         {
      59           2 :           return prepareIban().substring(2, 4);
      60             :         }
      61             : 
      62           2 :       case Country.italy:
      63             :         {
      64           2 :           return prepareIban().substring(2, 4);
      65             :         }
      66             : 
      67             :       default:
      68             :         {
      69             :           return "";
      70             :         }
      71             :     }
      72             :   }
      73             : 
      74             :   /// Ülkeye göre 'Banka Kodu' bilgisini geri döndürür.
      75           2 :   String getBankCode(Country country) {
      76             :     switch (country) {
      77           2 :       case Country.turkish:
      78             :         {
      79           2 :           return prepareIban().substring(4, 9);
      80             :         }
      81             : 
      82           2 :       case Country.england:
      83             :         {
      84           2 :           return prepareIban().substring(4, 8);
      85             :         }
      86             : 
      87           2 :       case Country.germany:
      88             :         {
      89           2 :           return prepareIban().substring(4, 12);
      90             :         }
      91             : 
      92           2 :       case Country.france:
      93             :         {
      94           2 :           return prepareIban().substring(4, 9);
      95             :         }
      96             : 
      97           2 :       case Country.italy:
      98             :         {
      99           2 :           return prepareIban().substring(5, 10);
     100             :         }
     101             : 
     102             :       default:
     103             :         {
     104             :           return "";
     105             :         }
     106             :     }
     107             :   }
     108             : 
     109             :   /// Ülkeye göre 'Şube Kodu' bilgisini geri döndürür.
     110           2 :   String getBranchCode(Country country) {
     111             :     switch (country) {
     112           2 :       case Country.turkish:
     113             :         {
     114             :           return "";
     115             :         }
     116             : 
     117           2 :       case Country.england:
     118             :         {
     119             :           return "";
     120             :         }
     121             : 
     122           2 :       case Country.germany:
     123             :         {
     124             :           return "";
     125             :         }
     126             : 
     127           2 :       case Country.france:
     128             :         {
     129           2 :           return prepareIban().substring(9, 14);
     130             :         }
     131             : 
     132           2 :       case Country.italy:
     133             :         {
     134           4 :           return prepareIban().substring(10, 15);
     135             :         }
     136             : 
     137             :       default:
     138             :         {
     139             :           return "";
     140             :         }
     141             :     }
     142             :   }
     143             : 
     144             :   /// Ülkeye göre 'Sıralama Kodu' bilgisini geri döndürür.
     145           2 :   String getSortCode(Country country) {
     146             :     switch (country) {
     147           2 :       case Country.turkish:
     148             :         {
     149             :           return "";
     150             :         }
     151             : 
     152           2 :       case Country.england:
     153             :         {
     154           4 :           return prepareIban().substring(8, 14);
     155             :         }
     156             : 
     157           2 :       case Country.germany:
     158             :         {
     159             :           return "";
     160             :         }
     161             : 
     162           1 :       case Country.france:
     163             :         {
     164             :           return "";
     165             :         }
     166             : 
     167           1 :       case Country.italy:
     168             :         {
     169             :           return "";
     170             :         }
     171             : 
     172             :       default:
     173             :         {
     174             :           return "";
     175             :         }
     176             :     }
     177             :   }
     178             : 
     179             :   /// Ülkeye göre 'Ulusal Kontrol Sayısı' bilgisini geri döndürür.
     180           2 :   String getNationalCheckDigit(Country country) {
     181             :     switch (country) {
     182           2 :       case Country.turkish:
     183             :         {
     184           4 :           return prepareIban().substring(9, 10);
     185             :         }
     186             : 
     187           2 :       case Country.england:
     188             :         {
     189             :           return "";
     190             :         }
     191             : 
     192           2 :       case Country.germany:
     193             :         {
     194             :           return "";
     195             :         }
     196             : 
     197           2 :       case Country.france:
     198             :         {
     199           2 :           return prepareIban().substring(25, 27);
     200             :         }
     201             : 
     202           2 :       case Country.italy:
     203             :         {
     204           2 :           return prepareIban().substring(4, 5);
     205             :         }
     206             : 
     207             :       default:
     208             :         {
     209             :           return "";
     210             :         }
     211             :     }
     212             :   }
     213             : 
     214             :   /// Ülkeye göre 'Banka Hesap Numarası' bilgisini geri döndürür.
     215           2 :   String getBankAccountNumber(Country country) {
     216             :     switch (country) {
     217           2 :       case Country.turkish:
     218             :         {
     219           4 :           return prepareIban().substring(10, 26);
     220             :         }
     221             : 
     222           2 :       case Country.england:
     223             :         {
     224           2 :           return prepareIban().substring(14, 22);
     225             :         }
     226             : 
     227           2 :       case Country.germany:
     228             :         {
     229           2 :           return prepareIban().substring(12, 22);
     230             :         }
     231             : 
     232           2 :       case Country.france:
     233             :         {
     234           2 :           return prepareIban().substring(14, 25);
     235             :         }
     236             : 
     237           2 :       case Country.italy:
     238             :         {
     239           2 :           return prepareIban().substring(15, 27);
     240             :         }
     241             : 
     242             :       default:
     243             :         {
     244             :           return "";
     245             :         }
     246             :     }
     247             :   }
     248             : 
     249             :   /// Global.. Iban'ı kontrol için hazır.
     250             :   /// Tüm boşlukları ve geçersiz karakterleri kaldırır ve iban'ı büyük harfle geri döndürür.
     251           2 :   String prepareIban() {
     252           6 :     return replaceAll(RegExp(r'[^a-zA-Z0-9]'), '').toUpperCase();
     253             :   }
     254             : 
     255             :   /// Iban'ı belirli boşluklarala yazarak baskı formatında görüntüler.
     256           1 :   String toPrintFormat([String separator = ' ']) {
     257           1 :     var every4Chars = RegExp(r'(.{4})(?!$)');
     258           1 :     return prepareIban()
     259           4 :         .replaceAllMapped(every4Chars, (match) => '${match.group(0)}$separator');
     260             :   }
     261             : }
     262             : 
     263             : extension ValidatorExtensions on String {
     264             :   /// Global.. Iban içerisindeki karakterlerin Alfanümerik olup olmadığını kontrol eder.
     265           2 :   bool checkIsAlphaNumericWithRegEx() {
     266           2 :     final alphaNumericRegex = RegExp(r'^([A-Z0-9]*)$', caseSensitive: true);
     267           2 :     return alphaNumericRegex.hasMatch(this);
     268             :   }
     269             : 
     270             :   /// Global.. Iban içerisindeki karakterlerin Metin olup olmadığını kontrol eder.
     271           3 :   bool checkIsAlphaWithRegEx() {
     272           3 :     final alphaNumericRegex = RegExp(r'^([A-Z]*)$', caseSensitive: true);
     273           3 :     return alphaNumericRegex.hasMatch(this);
     274             :   }
     275             : 
     276             :   /// Global.. Iban içerisindeki karakterlerin Nümerik olup olmadığını kontrol eder.
     277           2 :   bool checkIsNumericWithRegEx() {
     278           2 :     final numericRegex = RegExp(r'^([0-9]*)$');
     279           2 :     return numericRegex.hasMatch(this);
     280             :   }
     281             : 
     282             :   /// Ülkeye göre Iban'a ait Mod97 kontrolünü yaparak, geçerli bir Iban olup olmadığını bildirir.
     283           2 :   bool checkIbanMod97Algorithm(Country country){
     284           2 :     List<String> strArr =  ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
     285           2 :     List<String> intArr =  ["10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35"];
     286             : 
     287             :     switch (country) {
     288           2 :       case Country.turkish:
     289             :         {
     290           2 :           var iban = prepareIban();
     291           6 :           iban = iban.substring(4) + iban.substring(0, 4);
     292             : 
     293           6 :           for (int i = 0; i < strArr.length; i++){
     294           6 :             iban = iban.replaceAll(strArr[i], intArr[i]);
     295             :           }
     296             : 
     297           2 :           var ibanInt = BigInt.parse(iban);
     298           6 :           var remainder = ibanInt.remainder(BigInt.from(97)).toInt();
     299           2 :           return (remainder == 1) ? true : false;
     300             :         }
     301             : 
     302             :       default:
     303             :         {
     304             :           return false;
     305             :         }
     306             :     }
     307             :   }
     308             : 
     309             :   /// Ülkeye göre Iban'nın geçerli olup olmadığını kontrol eder.
     310           2 :   bool ibanValidate(Country country) {
     311           2 :     var iban = prepareIban();
     312             : 
     313             :     switch (country) {
     314           2 :       case Country.turkish:
     315             :         {
     316             :           return (
     317           2 :               iban.isEmpty
     318           4 :               || iban.length != 26
     319           2 :               || !iban.checkIsAlphaNumericWithRegEx()
     320           4 :               || !iban.getCountryCode(country).checkIsAlphaWithRegEx()
     321           4 :               || iban.getCountryCode(country) != "TR"
     322           2 :               || !iban.checkIbanMod97Algorithm(country)
     323             :           ) ? false : true;
     324             :         }
     325             : 
     326             :       default:
     327             :         {
     328             :           return false;
     329             :         }
     330             :     }
     331             :   }
     332             : }

Generated by: LCOV version 1.16