mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
1 parent
03099a149b
commit
0620f57691
6 files changed
+93809
-1822
No files matched your search
+1946
-1812
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -1,13 +1,12 @@
|
||||
import { type Page, expect, test } from '@playwright/test';
|
||||
|
||||
async function extractIbanInfo({ page }: { page: Page }) {
|
||||
const itemsLines = await page
|
||||
.locator('.c-key-value-list__item').all();
|
||||
const itemsLines = await page.locator('.c-key-value-list__item').all();
|
||||
|
||||
return await Promise.all(
|
||||
itemsLines.map(async item => [
|
||||
(await item.locator('.c-key-value-list__key').textContent() ?? '').trim(),
|
||||
(await item.locator('.c-key-value-list__value').textContent() ?? '').trim(),
|
||||
itemsLines.map(async (item) => [
|
||||
((await item.locator('.c-key-value-list__key').textContent()) ?? '').trim(),
|
||||
((await item.locator('.c-key-value-list__value').textContent()) ?? '').trim(),
|
||||
]),
|
||||
);
|
||||
}
|
||||
@@ -32,6 +31,12 @@ test.describe('Tool - Iban validator and parser', () => {
|
||||
['Country code', 'DE'],
|
||||
['BBAN', '370400440532013000'],
|
||||
['IBAN friendly format', 'DE89 3704 0044 0532 0130 00'],
|
||||
['Country', 'Germany / The Federal Republic of Germany'],
|
||||
['Bank Identifier', '37040044'],
|
||||
['Branch Identifier', 'N/A'],
|
||||
['Account Number', '0532013000'],
|
||||
['BIC', 'COBADEFFXXX'],
|
||||
['Bank Name', 'Commerzbank Köln'],
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -47,6 +52,12 @@ test.describe('Tool - Iban validator and parser', () => {
|
||||
['Country code', 'N/A'],
|
||||
['BBAN', 'N/A'],
|
||||
['IBAN friendly format', 'FR76 3000 6060 0112 3456 7890 189'],
|
||||
['Country', 'undefined / undefined'],
|
||||
['Bank Identifier', 'N/A'],
|
||||
['Branch Identifier', 'N/A'],
|
||||
['Account Number', 'N/A'],
|
||||
['BIC', 'N/A'],
|
||||
['Bank Name', 'Unknown'],
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
// extractBICInfo.spec.ts
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { extractBICInfo } from './iban-validator-and-parser.service';
|
||||
|
||||
describe('extractBICInfo – predefined IBANs', () => {
|
||||
it('extracts BIC info for French IBAN', () => {
|
||||
const iban = 'FR76 3000 6000 0112 3456 7890 189';
|
||||
const result = extractBICInfo(iban);
|
||||
|
||||
expect(result).to.deep.eq({
|
||||
bankCode: '30006',
|
||||
bankName: 'Crédit Agricole S.A.',
|
||||
bic: 'AGRIFRPPXXX',
|
||||
});
|
||||
});
|
||||
|
||||
it('extracts BIC info for German IBAN', () => {
|
||||
const iban = 'DE89 3704 0044 0532 0130 00';
|
||||
const result = extractBICInfo(iban);
|
||||
|
||||
expect(result).to.deep.eq({
|
||||
bankCode: '37040044',
|
||||
bankName: 'Commerzbank Köln',
|
||||
bic: 'COBADEFFXXX',
|
||||
});
|
||||
});
|
||||
|
||||
it('extracts BIC info for UK IBAN', () => {
|
||||
const iban = 'GB29 NWBK 6016 1331 9268 19';
|
||||
const result = extractBICInfo(iban);
|
||||
|
||||
expect(result).to.deep.eq({
|
||||
bankCode: 'NWBK',
|
||||
bankName: 'NATIONAL WESTMINSTER BANK PUBLIC LIMITED COMPANY',
|
||||
bic: 'NWBKGB2LXXX',
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,8 +1,11 @@
|
||||
import { ValidationErrorsIBAN } from 'ibantools';
|
||||
import { extractIBAN } from 'ibantools';
|
||||
|
||||
import BanksInfos from './banks-infos.json';
|
||||
|
||||
import { translate as t } from '@/plugins/i18n.plugin';
|
||||
|
||||
export { getFriendlyErrors };
|
||||
export { getFriendlyErrors, extractBICInfo };
|
||||
|
||||
const ibanErrorToMessage = {
|
||||
[ValidationErrorsIBAN.NoIBANProvided]: t('tools.iban-validator-and-parser.service.text.no-iban-provided'),
|
||||
@@ -11,10 +14,38 @@ const ibanErrorToMessage = {
|
||||
[ValidationErrorsIBAN.WrongBBANFormat]: t('tools.iban-validator-and-parser.service.text.wrong-bban-format'),
|
||||
[ValidationErrorsIBAN.ChecksumNotNumber]: t('tools.iban-validator-and-parser.service.text.checksum-is-not-a-number'),
|
||||
[ValidationErrorsIBAN.WrongIBANChecksum]: t('tools.iban-validator-and-parser.service.text.wrong-iban-checksum'),
|
||||
[ValidationErrorsIBAN.WrongAccountBankBranchChecksum]: t('tools.iban-validator-and-parser.service.text.wrong-account-bank-branch-checksum'),
|
||||
[ValidationErrorsIBAN.WrongAccountBankBranchChecksum]: t(
|
||||
'tools.iban-validator-and-parser.service.text.wrong-account-bank-branch-checksum',
|
||||
),
|
||||
[ValidationErrorsIBAN.QRIBANNotAllowed]: t('tools.iban-validator-and-parser.service.text.qr-iban-not-allowed'),
|
||||
};
|
||||
|
||||
function getFriendlyErrors(errorCodes: ValidationErrorsIBAN[]) {
|
||||
return errorCodes.map(errorCode => ibanErrorToMessage[errorCode]).filter(Boolean);
|
||||
return errorCodes.map((errorCode) => ibanErrorToMessage[errorCode]).filter(Boolean);
|
||||
}
|
||||
|
||||
const unknownBank = {
|
||||
bic: '',
|
||||
bankCode: '',
|
||||
bankName: 'Unknown',
|
||||
};
|
||||
|
||||
function extractBICInfo(iban: string) {
|
||||
if (!iban) {
|
||||
return unknownBank;
|
||||
}
|
||||
const { countryCode, bankIdentifier: bankCode } = extractIBAN(iban);
|
||||
const banksInfos = BanksInfos[countryCode as keyof typeof BanksInfos] as Record<string, { b: string; n: string }>;
|
||||
if (!banksInfos || !bankCode) {
|
||||
return { ...unknownBank, bankCode };
|
||||
}
|
||||
const bankInfos = banksInfos[bankCode];
|
||||
if (!bankInfos) {
|
||||
return { ...unknownBank, bankCode };
|
||||
}
|
||||
return {
|
||||
bic: bankInfos.b,
|
||||
bankCode,
|
||||
bankName: bankInfos.n,
|
||||
};
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { extractIBAN, friendlyFormatIBAN, isQRIBAN, validateIBAN } from 'ibantools';
|
||||
import { getFriendlyErrors } from './iban-validator-and-parser.service';
|
||||
import { extractBICInfo, getFriendlyErrors } from './iban-validator-and-parser.service';
|
||||
import type { CKeyValueListItems } from '@/ui/c-key-value-list/c-key-value-list.types';
|
||||
import { useQueryParam } from '@/composable/queryParams';
|
||||
import CountriesDB from 'countries-db';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
@@ -32,8 +33,10 @@ const ibansInfo = computed<IbanInfo[]>(() => {
|
||||
|
||||
for (const iban of ibans) {
|
||||
const { valid: isIbanValid, errorCodes } = validateIBAN(iban);
|
||||
const { countryCode, bban } = extractIBAN(iban);
|
||||
const { countryCode, bban, bankIdentifier, branchIdentifier, accountNumber } = extractIBAN(iban);
|
||||
const { bic, bankName } = extractBICInfo(iban);
|
||||
const errors = getFriendlyErrors(errorCodes);
|
||||
const country = CountriesDB.getCountry(countryCode || '');
|
||||
|
||||
results.push({
|
||||
iban,
|
||||
@@ -66,6 +69,30 @@ const ibansInfo = computed<IbanInfo[]>(() => {
|
||||
label: t('tools.iban-validator-and-parser.texts.label-iban-friendly-format'),
|
||||
value: friendlyFormatIBAN(iban),
|
||||
},
|
||||
{
|
||||
label: t('tools.phone-parser-and-formatter.texts.label-country'),
|
||||
value: `${country?.name} / ${country?.officialName}`,
|
||||
},
|
||||
{
|
||||
label: t('tools.iban-validator-and-parser.texts.bank-identifier'),
|
||||
value: bankIdentifier,
|
||||
},
|
||||
{
|
||||
label: t('tools.iban-validator-and-parser.texts.branch-identifier'),
|
||||
value: branchIdentifier,
|
||||
},
|
||||
{
|
||||
label: t('tools.iban-validator-and-parser.texts.account-number'),
|
||||
value: accountNumber,
|
||||
},
|
||||
{
|
||||
label: t('tools.iban-validator-and-parser.texts.bic'),
|
||||
value: bic,
|
||||
},
|
||||
{
|
||||
label: t('tools.iban-validator-and-parser.texts.bank-name'),
|
||||
value: bankName,
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user