Finished IBAN generator base functionalities, Advanced features still missing

Update iban-generator.yml, iban-generator.yml, and 3 more files...
This commit is contained in:
2025-03-18 21:01:02 +01:00
parent 18bb55cea9
commit 05ea0ca732
5 changed files with 95 additions and 5 deletions

View File

@@ -195,6 +195,10 @@ export class StandardIban extends SimpleIban {
}
}
export const charsN = "0123456789";
export const charsA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
export const charsC = charsN + charsA;
export class IbanSpecification {
/**
* ISO-3166 Country Code
@@ -264,6 +268,50 @@ export class IbanSpecification {
getFormattedIban(iban) {
return iban.match(/.{1,4}/g).join(' ');
}
generateRandomBban(preferNumbers = false) {
let returnedBban = "";
let patternParts = ("_" + this.bbanFormat + "0").split("!");
for(let i = 0; i < patternParts.length; i++) {
let elementCount = parseInt(patternParts[i].substring(1));
if(elementCount === 0) {
continue;
}
let elementType = patternParts[i + 1].substring(0, 1);
let elementChoices;
switch(elementType) {
case 'n':
case 'N':
elementChoices = charsN;
break;
case 'c':
case 'C':
if(preferNumbers) {
elementChoices = charsN;
} else {
elementChoices = charsC;
}
break;
case 'a':
case 'A':
elementChoices = charsA;
break;
}
if(elementChoices === undefined || elementChoices === null) {
throw new IncorrectIbanFormatError(
`The format '${this.bbanFormat}' contains an unhandled element type '${elementType}' !`)
}
for (let i = 0; i < elementCount; i++) {
returnedBban += elementChoices.charAt(Math.floor(Math.random() * elementChoices.length));
}
}
return returnedBban;
}
}
export const countriesSpecs = {