Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Iban #168

Open
lil5 opened this issue Feb 19, 2024 · 0 comments
Open

Generate Iban #168

lil5 opened this issue Feb 19, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@lil5
Copy link

lil5 commented Feb 19, 2024

Inspired by https://github.com/fzaninotto/Faker/blob/5ffe7db6c80f441f150fc88008d64e64af66634b/src/Faker/Provider/Payment.php#L71

package fakeriban

import (
	Faker "github.com/jaswdr/faker"
)

func format(t rune, size int) string {
	s := ""
	o := ""
	if t == 'n' {
		o = "#"
	} else if t == 'a' {
		o = "?"
	} else if t == 'c' {
		o = "*"
	}

	for i := 0; i < size; i++ {
		s += o
	}
	return s
}

/**
 * @var array list of IBAN formats, source: @link https://www.swift.com/standards/data-standards/iban
 */
var iban = []string{
	"AD" + format('n', 4) + format('n', 4) + format('c', 12),
	"AE" + format('n', 3) + format('n', 16),
	"AL" + format('n', 8) + format('c', 16),
	"AT" + format('n', 5) + format('n', 11),
	"AZ" + format('a', 4) + format('c', 20),
	"BA" + format('n', 3) + format('n', 3) + format('n', 8) + format('n', 2),
	"BE" + format('n', 3) + format('n', 7) + format('n', 2),
	"BG" + format('a', 4) + format('n', 4) + format('n', 2) + format('c', 8),
	"BH" + format('a', 4) + format('c', 14),
	"BR" + format('n', 8) + format('n', 5) + format('n', 10) + format('a', 1) + format('c', 1),
	"CH" + format('n', 5) + format('c', 12),
	"CR" + format('n', 4) + format('n', 14),
	"CY" + format('n', 3) + format('n', 5) + format('c', 16),
	"CZ" + format('n', 4) + format('n', 6) + format('n', 10),
	"DE" + format('n', 8) + format('n', 10),
	"DK" + format('n', 4) + format('n', 9) + format('n', 1),
	"DO" + format('c', 4) + format('n', 20),
	"EE" + format('n', 2) + format('n', 2) + format('n', 11) + format('n', 1),
	"ES" + format('n', 4) + format('n', 4) + format('n', 1) + format('n', 1) + format('n', 10),
	"FI" + format('n', 6) + format('n', 7) + format('n', 1),
	"FR" + format('n', 5) + format('n', 5) + format('c', 11) + format('n', 2),
	"GB" + format('a', 4) + format('n', 6) + format('n', 8),
	"GE" + format('a', 2) + format('n', 16),
	"GI" + format('a', 4) + format('c', 15),
	"GR" + format('n', 3) + format('n', 4) + format('c', 16),
	"GT" + format('c', 4) + format('c', 20),
	"HR" + format('n', 7) + format('n', 10),
	"HU" + format('n', 3) + format('n', 4) + format('n', 1) + format('n', 15) + format('n', 1),
	"IE" + format('a', 4) + format('n', 6) + format('n', 8),
	"IL" + format('n', 3) + format('n', 3) + format('n', 13),
	"IS" + format('n', 4) + format('n', 2) + format('n', 6) + format('n', 10),
	"IT" + format('a', 1) + format('n', 5) + format('n', 5) + format('c', 12),
	"KW" + format('a', 4) + format('n', 22),
	"KZ" + format('n', 3) + format('c', 13),
	"LB" + format('n', 4) + format('c', 20),
	"LI" + format('n', 5) + format('c', 12),
	"LT" + format('n', 5) + format('n', 11),
	"LU" + format('n', 3) + format('c', 13),
	"LV" + format('a', 4) + format('c', 13),
	"MC" + format('n', 5) + format('n', 5) + format('c', 11) + format('n', 2),
	"MD" + format('c', 2) + format('c', 18),
	"ME" + format('n', 3) + format('n', 13) + format('n', 2),
	"MK" + format('n', 3) + format('c', 10) + format('n', 2),
	"MR" + format('n', 5) + format('n', 5) + format('n', 11) + format('n', 2),
	"MT" + format('a', 4) + format('n', 5) + format('c', 18),
	"MU" + format('a', 4) + format('n', 2) + format('n', 2) + format('n', 12) + format('n', 3) + format('a', 3),
	"NL" + format('a', 4) + format('n', 10),
	"NO" + format('n', 4) + format('n', 6) + format('n', 1),
	"PK" + format('a', 4) + format('c', 16),
	"PL" + format('n', 8) + format('n', 16),
	"PS" + format('a', 4) + format('c', 21),
	"PT" + format('n', 4) + format('n', 4) + format('n', 11) + format('n', 2),
	"RO" + format('a', 4) + format('c', 16),
	"RS" + format('n', 3) + format('n', 13) + format('n', 2),
	"SA" + format('n', 2) + format('c', 18),
	"SE" + format('n', 3) + format('n', 16) + format('n', 1),
	"SI" + format('n', 5) + format('n', 8) + format('n', 2),
	"SK" + format('n', 4) + format('n', 6) + format('n', 10),
	"SM" + format('a', 1) + format('n', 5) + format('n', 5) + format('c', 12),
	"TN" + format('n', 2) + format('n', 3) + format('n', 13) + format('n', 2),
	"TR" + format('n', 5) + format('n', 1) + format('c', 16),
	"VG" + format('a', 4) + format('n', 16),
}

func Iban(f Faker.Faker) string {
	out := f.RandomStringElement(iban)
	out = f.Lexify(out)
	out = f.Numerify(out)
	out = f.Asciify(out)
	return out
}
@lil5 lil5 added the enhancement New feature or request label Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant