feat(IBAN Validator): allow multiple IBANs

Fix #1642
This commit is contained in:
ShareVB committed 2025-10-04 22:14:50 +02:00
1 parent ca64d2a018
commit 92a0dda3e7
1 file changed
+65 -40
@@ -7,50 +7,67 @@ import { useQueryParam } from '@/composable/queryParams';
const { t } = useI18n(); const { t } = useI18n();
const rawIban = useQueryParam({ tool: 'iban-validator', name: 'iban', defaultValue: '' }); const rawIbans = useQueryParam({ tool: 'iban-validator', name: 'iban', defaultValue: '' });
const ibanInfo = computed<CKeyValueListItems>(() => { interface IbanInfo {
const iban = rawIban.value.toUpperCase().replace(/\s/g, '').replace(/-/g, ''); iban: string
infos: CKeyValueListItems
}
if (iban === '') { const ibansInfo = computed<IbanInfo[]>(() => {
if (!rawIbans.value?.trim()) {
return [];
}
const ibans = rawIbans.value.toUpperCase()
.split(/\n/).map(iban => iban.replace(/\s/g, '').replace(/-/g, ''))
.filter(Boolean);
if (!ibans.length) {
return []; return [];
} }
const { valid: isIbanValid, errorCodes } = validateIBAN(iban); const results: IbanInfo[] = [];
const { countryCode, bban } = extractIBAN(iban);
const errors = getFriendlyErrors(errorCodes);
return [ for (const iban of ibans) {
const { valid: isIbanValid, errorCodes } = validateIBAN(iban);
const { countryCode, bban } = extractIBAN(iban);
const errors = getFriendlyErrors(errorCodes);
{ results.push({
label: t('tools.iban-validator-and-parser.texts.label-is-iban-valid'), iban,
value: isIbanValid, infos: [
showCopyButton: false, {
}, label: t('tools.iban-validator-and-parser.texts.label-is-iban-valid'),
{ value: isIbanValid,
label: t('tools.iban-validator-and-parser.texts.label-iban-errors'), showCopyButton: false,
value: errors.length === 0 ? undefined : errors, },
hideOnNil: true, {
showCopyButton: false, label: t('tools.iban-validator-and-parser.texts.label-iban-errors'),
}, value: errors.length === 0 ? undefined : errors,
{ hideOnNil: true,
label: t('tools.iban-validator-and-parser.texts.label-is-iban-a-qr-iban'), showCopyButton: false,
value: isQRIBAN(iban), },
showCopyButton: false, {
}, label: t('tools.iban-validator-and-parser.texts.label-is-iban-a-qr-iban'),
{ value: isQRIBAN(iban),
label: t('tools.iban-validator-and-parser.texts.label-country-code'), showCopyButton: false,
value: countryCode, },
}, {
{ label: t('tools.iban-validator-and-parser.texts.label-country-code'),
label: t('tools.iban-validator-and-parser.texts.label-bban'), value: countryCode,
value: bban, },
}, {
{ label: t('tools.iban-validator-and-parser.texts.label-bban'),
label: t('tools.iban-validator-and-parser.texts.label-iban-friendly-format'), value: bban,
value: friendlyFormatIBAN(iban), },
}, {
]; label: t('tools.iban-validator-and-parser.texts.label-iban-friendly-format'),
value: friendlyFormatIBAN(iban),
},
],
});
}
return results;
}); });
const ibanExamples = [ const ibanExamples = [
@@ -62,10 +79,18 @@ const ibanExamples = [
<template> <template>
<div> <div>
<c-input-text v-model:value="rawIban" :placeholder="t('tools.iban-validator-and-parser.texts.placeholder-enter-an-iban-to-check-for-validity')" test-id="iban-input" /> <c-input-text
v-model:value="rawIbans"
multiline
rows="4"
:placeholder="t('tools.iban-validator-and-parser.texts.placeholder-enter-an-iban-to-check-for-validity')"
test-id="iban-input"
/>
<c-card v-if="ibanInfo.length > 0" mt-5> <c-card v-for="ibanInfo in ibansInfo" :key="ibanInfo.iban" :title="ibanInfo.iban" mt-3>
<c-key-value-list :items="ibanInfo" data-test-id="iban-info" /> <c-card mt-5>
<c-key-value-list :items="ibanInfo.infos" data-test-id="iban-info" />
</c-card>
</c-card> </c-card>
<c-card :title="t('tools.iban-validator-and-parser.texts.title-valid-iban-examples')" mt-5> <c-card :title="t('tools.iban-validator-and-parser.texts.title-valid-iban-examples')" mt-5>