Skip to content

Commit

Permalink
Merge remote-tracking branch 'codemanx/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Marak committed Feb 10, 2017
2 parents fa99a52 + 94b65cb commit c4dcdfb
Show file tree
Hide file tree
Showing 6 changed files with 1,240 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* -crlf
76 changes: 71 additions & 5 deletions lib/finance.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @namespace faker.finance
*/
var Finance = function (faker) {
var ibanLib = require("./iban");
var Helpers = faker.helpers,
self = this;

Expand Down Expand Up @@ -41,15 +42,15 @@ var Finance = function (faker) {
* @method faker.finance.mask
* @param {number} length
* @param {boolean} parens
* @param {boolean} elipsis
* @param {boolean} ellipsis
*/
self.mask = function (length, parens, elipsis) {
self.mask = function (length, parens, ellipsis) {


//set defaults
length = (length == 0 || !length || typeof length == 'undefined') ? 4 : length;
parens = (parens === null) ? true : parens;
elipsis = (elipsis === null) ? true : elipsis;
ellipsis = (ellipsis === null) ? true : ellipsis;

//create a template for length
var template = '';
Expand All @@ -58,8 +59,8 @@ var Finance = function (faker) {
template = template + '#';
}

//prefix with elipsis
template = (elipsis) ? ['...', template].join('') : template;
//prefix with ellipsis
template = (ellipsis) ? ['...', template].join('') : template;

template = (parens) ? ['(', template, ')'].join('') : template;

Expand Down Expand Up @@ -150,6 +151,71 @@ var Finance = function (faker) {

return address;
}

/**
* iban
*
* @method faker.finance.iban
*/
self.iban = function (formatted) {
var ibanFormat = faker.random.arrayElement(ibanLib.formats);
var s = "";
var count = 0;
for (var b = 0; b < ibanFormat.bban.length; b++) {
var bban = ibanFormat.bban[b];
var c = bban.count;
count += bban.count;
while (c > 0) {
if (bban.type == "a") {
s += faker.random.arrayElement(ibanLib.alpha);
} else if (bban.type == "c") {
if (faker.random.number(100) < 80) {
s += faker.random.number(9);
} else {
s += faker.random.arrayElement(ibanLib.alpha);
}
} else {
if (c >= 3 && faker.random.number(100) < 30) {
if (faker.random.boolean()) {
s += faker.random.arrayElement(ibanLib.pattern100);
c -= 2;
} else {
s += faker.random.arrayElement(ibanLib.pattern10);
c--;
}
} else {
s += faker.random.number(9);
}
}
c--;
}
s = s.substring(0, count);
}
var checksum = 98 - ibanLib.mod97(ibanLib.toDigitString(s + ibanFormat.country + "00"));
if (checksum < 10) {
checksum = "0" + checksum;
}
var iban = ibanFormat.country + checksum + s;
return formatted ? iban.match(/.{1,4}/g).join(" ") : iban;
}

/**
* bic
*
* @method faker.finance.bic
*/
self.bic = function () {
var vowels = ["A", "E", "I", "O", "U"];
var prob = faker.random.number(100);
return Helpers.replaceSymbols("???") +
faker.random.arrayElement(vowels) +
faker.random.arrayElement(ibanLib.iso3166) +
Helpers.replaceSymbols("?") + "1" +
(prob < 10 ?
Helpers.replaceSymbols("?" + faker.random.arrayElement(vowels) + "?") :
prob < 40 ?
Helpers.replaceSymbols("###") : "");
}
}

module['exports'] = Finance;
6 changes: 3 additions & 3 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ var Helpers = function (faker) {
*/
self.replaceSymbols = function (string) {
string = string || "";
var alpha = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
var alpha = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
var str = '';

for (var i = 0; i < string.length; i++) {
if (string.charAt(i) == "#") {
str += faker.random.number(9);
} else if (string.charAt(i) == "?") {
str += faker.random.arrayElement(alpha);
} else if (string.charAt(i) == "?") {
str += faker.random.arrayElement(alpha);
} else {
str += string.charAt(i);
}
Expand Down
Loading

0 comments on commit c4dcdfb

Please sign in to comment.