aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMarak <[email protected]>2021-02-04 17:39:06 -0500
committerGitHub <[email protected]>2021-02-04 17:39:06 -0500
commit90fc05df437f5193bfc9e759bd94a4c8917d4bde (patch)
tree055274cce7aae5a07ad3f80d3cf45814dfe2203e /lib
parente61e8455c45555786ff10e5c9f15b85cf91f66ef (diff)
parentb4c3c745632bbdcc09fc35fc3bdcbfe601e2cf91 (diff)
downloadfaker-90fc05df437f5193bfc9e759bd94a4c8917d4bde.tar.xz
faker-90fc05df437f5193bfc9e759bd94a4c8917d4bde.zip
Merge pull request #989 from rebuy-de/patch-iban-country
Add optional country code parameter for iban method
Diffstat (limited to 'lib')
-rw-r--r--lib/finance.js19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/finance.js b/lib/finance.js
index 91d41b5c..f9afa3a1 100644
--- a/lib/finance.js
+++ b/lib/finance.js
@@ -248,10 +248,25 @@ 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 ibanFormat;
+ if (countryCode) {
+ var findFormat = function(currentFormat) { return currentFormat.country === countryCode; };
+ ibanFormat = ibanLib.formats.find(findFormat);
+ } else {
+ ibanFormat = 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++) {