Add IBAN generator tool
This commit is contained in:
parent
068bb1d36b
commit
faabc828d6
@ -58,6 +58,7 @@ export default {
|
||||
'str_to_nato_alphabet': 'Str to NATO alphabet',
|
||||
'url_encode_decode': 'URL encode/decode',
|
||||
'url_query_viewer': 'URL query viewer',
|
||||
'iban_generator': 'IBAN generator',
|
||||
},
|
||||
'PHP': {
|
||||
'str_to_php_array': 'Str to PHP array',
|
||||
|
@ -115,6 +115,11 @@ const router = createRouter({
|
||||
name: 'fix_ru_en_keyboard',
|
||||
component: () => import('../views/strings/FixRuEnKeyboard.vue'),
|
||||
},
|
||||
{
|
||||
path: '/iban_generator',
|
||||
name: 'iban_generator',
|
||||
component: () => import('../views/strings/IbanGenerator.vue'),
|
||||
},
|
||||
|
||||
/**
|
||||
* PHP
|
||||
|
179
src/views/strings/IbanGenerator.vue
Normal file
179
src/views/strings/IbanGenerator.vue
Normal file
@ -0,0 +1,179 @@
|
||||
<template>
|
||||
<h2 class="tool-title">IBAN generator</h2>
|
||||
<hr class="mt-5 mb-5">
|
||||
|
||||
<div class="input-group">
|
||||
<label for="style">Country</label>
|
||||
<div>
|
||||
<select id="style" v-model="toolData.country" v-on:change="result">
|
||||
<option value="">Select Country</option>
|
||||
<option v-for="(structure, code) in ibanStructure" :key="code" :value="code">
|
||||
{{ structure.country }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="mt-5 mb-5">
|
||||
|
||||
<div class="input-group">
|
||||
<label for="result">Result</label>
|
||||
<MonacoEditor name="result" language="text" :value="toolResult"></MonacoEditor>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import MonacoEditor from "@/components/MonacoEditor.vue";
|
||||
|
||||
function generateRandomNumber(length) {
|
||||
let result = "";
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += Math.floor(Math.random() * 10);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function generateRandomString(length) {
|
||||
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
let result = '';
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += characters.charAt(Math.floor(Math.random() * characters.length));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function mod97(string) {
|
||||
let checksum = string.slice(0, 2);
|
||||
for (let i = 2; i < string.length; i += 7) {
|
||||
checksum = (parseInt(checksum + string.slice(i, i + 7), 10) % 97).toString().padStart(2, '0');
|
||||
}
|
||||
return parseInt(checksum);
|
||||
}
|
||||
|
||||
function calculateCheckDigits(iban) {
|
||||
const rearranged = iban.slice(4) + iban.slice(0, 4);
|
||||
const digits = rearranged.split('').map(char => {
|
||||
if (char >= 'A' && char <= 'Z') {
|
||||
return (char.charCodeAt(0) - 55).toString();
|
||||
}
|
||||
return char;
|
||||
}).join('');
|
||||
const remainder = mod97(digits);
|
||||
return ('0' + (98 - remainder)).slice(-2);
|
||||
}
|
||||
|
||||
export default {
|
||||
components: {
|
||||
MonacoEditor
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
toolData: {
|
||||
country: "",
|
||||
},
|
||||
toolResult: "",
|
||||
ibanStructure: {
|
||||
AD: { country: "Andorra", length: 24, structure: "F04F04F12" },
|
||||
AE: { country: "United Arab Emirates", length: 23, structure: "F03F16" },
|
||||
AT: { country: "Austria", length: 20, structure: "F05F11" },
|
||||
BA: { country: "Bosnia and Herzegovina", length: 20, structure: "F03F03F08F02" },
|
||||
BE: { country: "Belgium", length: 16, structure: "F03F07F02" },
|
||||
BG: { country: "Bulgaria", length: 22, structure: "U04F04F02F08" },
|
||||
BH: { country: "Bahrain", length: 22, structure: "U04F14" },
|
||||
BR: { country: "Brazil", length: 29, structure: "F08F05F10U01U01" },
|
||||
CH: { country: "Switzerland", length: 21, structure: "F05U12" },
|
||||
CY: { country: "Cyprus", length: 28, structure: "F03F05U16" },
|
||||
CZ: { country: "Czech Republic", length: 24, structure: "F04F06F10" },
|
||||
DE: { country: "Germany", length: 22, structure: "F08F10" },
|
||||
DK: { country: "Denmark", length: 18, structure: "F04F09F01" },
|
||||
EE: { country: "Estonia", length: 20, structure: "F02F02F11F01" },
|
||||
ES: { country: "Spain", length: 24, structure: "F04F04F01F01F10" },
|
||||
FI: { country: "Finland", length: 18, structure: "F06F07F01" },
|
||||
FR: { country: "France", length: 27, structure: "F05F05U11F02" },
|
||||
GB: { country: "United Kingdom", length: 22, structure: "U04F06F08" },
|
||||
GE: { country: "Georgia", length: 22, structure: "U02F16" },
|
||||
GI: { country: "Gibraltar", length: 23, structure: "U04U15" },
|
||||
GR: { country: "Greece", length: 27, structure: "F03F04U16" },
|
||||
HR: { country: "Croatia", length: 21, structure: "F07F10" },
|
||||
HU: { country: "Hungary", length: 28, structure: "F03F04F01F15F01" },
|
||||
IE: { country: "Ireland", length: 22, structure: "U04F06F08" },
|
||||
IL: { country: "Israel", length: 23, structure: "F03F03F13" },
|
||||
IS: { country: "Iceland", length: 26, structure: "F04F02F06F10" },
|
||||
IT: { country: "Italy", length: 27, structure: "U01F05F05U12" },
|
||||
JO: { country: "Jordan", length: 30, structure: "U04F04U18" },
|
||||
KW: { country: "Kuwait", length: 30, structure: "U04U22" },
|
||||
KZ: { country: "Kazakhstan", length: 20, structure: "F03U13" },
|
||||
LB: { country: "Lebanon", length: 28, structure: "F04U20" },
|
||||
LI: { country: "Liechtenstein", length: 21, structure: "F05U12" },
|
||||
LT: { country: "Lithuania", length: 20, structure: "F05F11" },
|
||||
LU: { country: "Luxembourg", length: 20, structure: "F03U13" },
|
||||
LV: { country: "Latvia", length: 21, structure: "U04U13" },
|
||||
MC: { country: "Monaco", length: 27, structure: "F05F05U11F02" },
|
||||
MD: { country: "Moldova", length: 24, structure: "U02F18" },
|
||||
ME: { country: "Montenegro", length: 22, structure: "F03F13F02" },
|
||||
MK: { country: "North Macedonia", length: 19, structure: "F03U10F02" },
|
||||
MR: { country: "Mauritania", length: 27, structure: "F05F05F11F02" },
|
||||
MT: { country: "Malta", length: 31, structure: "U04F05U18" },
|
||||
MU: { country: "Mauritius", length: 30, structure: "U04F02F02F12F03U03" },
|
||||
NL: { country: "Netherlands", length: 18, structure: "U04F10" },
|
||||
NO: { country: "Norway", length: 15, structure: "F04F06F01" },
|
||||
PK: { country: "Pakistan", length: 24, structure: "U04U16" },
|
||||
PL: { country: "Poland", length: 28, structure: "F08F16" },
|
||||
PT: { country: "Portugal", length: 25, structure: "F04F04F11F02" },
|
||||
QA: { country: "Qatar", length: 29, structure: "U04U21" },
|
||||
RO: { country: "Romania", length: 24, structure: "U04U16" },
|
||||
RS: { country: "Serbia", length: 22, structure: "F03F13F02" },
|
||||
SA: { country: "Saudi Arabia", length: 24, structure: "F02U18" },
|
||||
SE: { country: "Sweden", length: 24, structure: "F03F16F01" },
|
||||
SI: { country: "Slovenia", length: 19, structure: "F05F08F02" },
|
||||
SK: { country: "Slovakia", length: 24, structure: "F04F06F10" },
|
||||
SM: { country: "San Marino", length: 27, structure: "U01F05F05U12" },
|
||||
TN: { country: "Tunisia", length: 24, structure: "F02F03F13F02" },
|
||||
TR: { country: "Turkey", length: 26, structure: "F05U01U16" },
|
||||
UA: { country: "Ukraine", length: 29, structure: "F06F19" },
|
||||
},
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
result() {
|
||||
if (!this.toolData.country.length) {
|
||||
this.toolResult = 'Select a country';
|
||||
return;
|
||||
}
|
||||
|
||||
const structure = this.ibanStructure[this.toolData.country];
|
||||
if (!structure) {
|
||||
this.toolResult = 'Unsupported country';
|
||||
return;
|
||||
}
|
||||
|
||||
let iban = this.toolData.country + '00'; // Add placeholder check digits
|
||||
const parts = structure.structure.match(/([FU])(\d+)/g);
|
||||
|
||||
for (const part of parts) {
|
||||
const type = part[0];
|
||||
const length = parseInt(part.slice(1));
|
||||
|
||||
switch (type) {
|
||||
case 'F':
|
||||
iban += generateRandomNumber(length);
|
||||
break;
|
||||
case 'U':
|
||||
iban += generateRandomString(length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate and replace check digits
|
||||
const checkDigits = calculateCheckDigits(iban);
|
||||
iban = iban.slice(0, 2) + checkDigits + iban.slice(4);
|
||||
|
||||
this.toolResult = iban;
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
Loading…
x
Reference in New Issue
Block a user