Skip to content

Commit

Permalink
Merge pull request #423 from uphold-forks/feature/add-finance-routing…
Browse files Browse the repository at this point in the history
…-number

Add ABA routing number generator
  • Loading branch information
Marak authored Oct 12, 2017
2 parents 29de77a + d998170 commit 4beccd1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/finance.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@ var Finance = function (faker) {
return [Helpers.randomize(faker.definitions.finance.account_type), 'Account'].join(' ');
};

/**
* routingNumber
*
* @method faker.finance.routingNumber
*/
self.routingNumber = function () {

var routingNumber = Helpers.replaceSymbolWithNumber('########');

// Modules 10 straight summation.
var sum = 0;

for (var i = 0; i < routingNumber.length; i += 3) {
sum += Number(routingNumber[i]) * 3;
sum += Number(routingNumber[i + 1]) * 7;
sum += Number(routingNumber[i + 2]) || 0;
}

return routingNumber + (Math.ceil(sum / 10) * 10 - sum);
}

/**
* mask
*
Expand Down
11 changes: 11 additions & 0 deletions test/finance.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ describe('finance.js', function () {

});

describe('routingNumber()', function () {

it("should return a routing number", function () {

var actual = faker.finance.routingNumber();

assert.ok(actual);

});

});

describe('mask( length, parens, ellipsis )', function () {
it("should set a default length", function () {
Expand Down

0 comments on commit 4beccd1

Please sign in to comment.