diff --git a/example/example_phone_number.dart b/example/example_phone_number.dart index 740536a..f40d87f 100644 --- a/example/example_phone_number.dart +++ b/example/example_phone_number.dart @@ -15,7 +15,6 @@ void main() { print(operatorDetail?.base); // کشوری print(operatorDetail?.type); // SimCartType.both - /// you can also use this methods as String extension method // phone number validator diff --git a/lib/src/core/get_bank_name_from_card_number/get_bank_name_from_card_number.dart b/lib/src/core/get_bank_name_from_card_number/get_bank_name_from_card_number.dart index d8ba1a9..a1b0b42 100644 --- a/lib/src/core/get_bank_name_from_card_number/get_bank_name_from_card_number.dart +++ b/lib/src/core/get_bank_name_from_card_number/get_bank_name_from_card_number.dart @@ -1,6 +1,22 @@ +import 'package:dart_persian_tools/src/constants/get_bank_name_from_card_number/constants.dart'; + import 'models.dart'; +/// checks the [cardNumber] is a valid bank card and returns the [Bank] info +/// if its not a valid card or not related to a bank +/// it will returns null Bank? getBankNameFromCardNumber(String cardNumber) { + if (cardNumber.length == 16) { + /// split the card number and cut the init code from it + final initCode = cardNumber.substring(0, 6); + + final findBank = bankInformation.firstWhere( + (element) => element?.initCode == initCode, + orElse: () => null, + ); + + if (findBank != null) return findBank; + } return null; } diff --git a/lib/src/core/phone_number/phone_number.dart b/lib/src/core/phone_number/phone_number.dart index 60b1f31..79ebee4 100644 --- a/lib/src/core/phone_number/phone_number.dart +++ b/lib/src/core/phone_number/phone_number.dart @@ -17,7 +17,6 @@ String getPhonePrefix(String phoneNumber) { return ''; } - /// find information such as province, type and model of [phoneNumber] /// this function used the [getPhonePrefix] to find out the [phoneNumber] prefix number and /// used the [phoneNumberValidator] function to validate the [phoneNumber]. diff --git a/test/test_get_bank_name_from_card_number.dart b/test/test_get_bank_name_from_card_number.dart index 10a5b14..d827554 100644 --- a/test/test_get_bank_name_from_card_number.dart +++ b/test/test_get_bank_name_from_card_number.dart @@ -4,7 +4,8 @@ import 'package:test/test.dart'; void main() { group('test get_bank_name_from_card_number.dart', () { test('test getBankNameFromCardNumber method', () { - expect(getBankNameFromCardNumber('6037701689095443')?.name, 'بانک کشاورزی'); + expect( + getBankNameFromCardNumber('6037701689095443')?.name, 'بانک کشاورزی'); expect(getBankNameFromCardNumber('6219861034529007')?.name, 'بانک سامان'); expect(getBankNameFromCardNumber('6219861034529007')?.name, 'بانک سامان');