diff options
| author | Martin Parsiegla <[email protected]> | 2020-09-01 19:13:58 +0200 |
|---|---|---|
| committer | Martin Parsiegla <[email protected]> | 2020-09-01 19:19:07 +0200 |
| commit | 8820484e159bead9be36d200f181302e2a45636e (patch) | |
| tree | 7c07f1222dc214247abc4a7937fa9c2b2965f80e /lib | |
| parent | ecac64c468f486f45144a2fe18837dab334b74ac (diff) | |
| download | faker-8820484e159bead9be36d200f181302e2a45636e.tar.xz faker-8820484e159bead9be36d200f181302e2a45636e.zip | |
Add optional country code parameter for iban method
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/finance.js | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/finance.js b/lib/finance.js index 19bc0c19..2939a659 100644 --- a/lib/finance.js +++ b/lib/finance.js @@ -248,10 +248,19 @@ self.litecoinAddress = function () { /** * iban * + * @param {boolean} [formatted=false] - Return a formatted version of the generated IBAN. + * @param {string} [countryCode] - The country code from which you want to generate an IBAN, if none is provided a random country will be used. + * @throws Will throw an error if the passed country code is not supported. + * * @method faker.finance.iban */ - self.iban = function (formatted) { - var ibanFormat = faker.random.arrayElement(ibanLib.formats); + self.iban = function (formatted, countryCode) { + var findFormat = function(currentFormat) { return currentFormat.country === countryCode; }; + var ibanFormat = countryCode ? ibanLib.formats.find(findFormat) : faker.random.arrayElement(ibanLib.formats); + if (!ibanFormat) { + throw new Error('Country code ' + countryCode + ' not supported.'); + } + var s = ""; var count = 0; for (var b = 0; b < ibanFormat.bban.length; b++) { |
