aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMarak <[email protected]>2014-09-13 20:27:50 +0200
committerMarak <[email protected]>2014-09-13 20:27:50 +0200
commit9f3fa0f8b7a8cc4f06fe545af02aca34e473c521 (patch)
treedc3b59ba68063106907416f9127c8826eea1e007 /lib
parentc39e254f2775aa4fcf48b05c9a61b78b74843830 (diff)
parenta5da426f33aab13d0946be2c14ae0dae7c302500 (diff)
downloadfaker-9f3fa0f8b7a8cc4f06fe545af02aca34e473c521.tar.xz
faker-9f3fa0f8b7a8cc4f06fe545af02aca34e473c521.zip
[api] Added basic financial generators Closes #32
Merge https://github.com/josefsalyer/Faker.js
Diffstat (limited to 'lib')
-rw-r--r--lib/definitions.js4
-rw-r--r--lib/finance.js70
-rw-r--r--lib/helpers.js14
3 files changed, 87 insertions, 1 deletions
diff --git a/lib/definitions.js b/lib/definitions.js
index 36bde57d..5b805c23 100644
--- a/lib/definitions.js
+++ b/lib/definitions.js
@@ -1405,3 +1405,7 @@ exports.avatar_uri = [];
for (var i = 0; i < avatarUri.length; i++) {
exports.avatar_uri.push("https://s3.amazonaws.com/uifaces/faces/twitter/" + avatarUri[i]);
};
+
+exports.account_type = ["Checking","Savings","Money Market", "Investment", "Home Loan", "Credit Card", "Auto Loan", "Personal Loan"];
+
+exports.transaction_type = ["deposit", "withdrawal", "payment", "invoice"]; \ No newline at end of file
diff --git a/lib/finance.js b/lib/finance.js
new file mode 100644
index 00000000..4bf50bff
--- /dev/null
+++ b/lib/finance.js
@@ -0,0 +1,70 @@
+var Helpers = require('./helpers');
+var definitions = require('./definitions');
+
+var finance = {
+
+ account: function (length) {
+
+ length = length || 8;
+
+ var template = '';
+
+ for (var i = 0; i < length; i++) {
+ template = template + '#';
+ }
+ length = null;
+ return Helpers.replaceSymbolWithNumber(template);
+ },
+
+ accountName: function () {
+
+ return [Helpers.randomize(definitions.account_type), 'Account'].join(' ');
+ },
+
+ mask: function (length, parens, elipsis) {
+
+
+ //set defaults
+ length = (length == 0 || !length || typeof length == 'undefined') ? 4 : length;
+ parens = (parens === null) ? true : parens;
+ elipsis = (elipsis === null) ? true : elipsis;
+
+ //create a template for length
+ var template = '';
+
+ for (var i = 0; i < length; i++) {
+ template = template + '#';
+ }
+
+ //prefix with elipsis
+ template = (elipsis) ? ['...', template].join('') : template;
+
+ template = (parens) ? ['(', template, ')'].join('') : template;
+
+ //generate random numbers
+ template = Helpers.replaceSymbolWithNumber(template);
+
+ return template;
+
+ },
+
+ //min and max take in minimum and maximum amounts, dec is the decimal place you want rounded to, symbol is $, €, £, etc
+ //NOTE: this returns a string representation of the value, if you want a number use parseFloat and no symbol
+
+ amount: function (min, max, dec, symbol) {
+
+ min = min || 0;
+ max = max || 1000;
+ dec = dec || 2;
+ symbol = symbol || '';
+
+ return symbol + (Math.round((Math.random() * (max - min) + min) * Math.pow(10, dec)) / Math.pow(10, dec)).toFixed(dec);
+
+ },
+
+ transactionType: function () {
+ return Helpers.randomize(definitions.transaction_type);
+ }
+};
+
+module.exports = finance; \ No newline at end of file
diff --git a/lib/helpers.js b/lib/helpers.js
index 7d146c8d..31819615 100644
--- a/lib/helpers.js
+++ b/lib/helpers.js
@@ -84,7 +84,8 @@ exports.createCard = function () {
"sentences": faker.Lorem.sentences(),
"paragraph": faker.Lorem.paragraph()
}
- ]
+ ],
+ "accountHistory": [faker.Helpers.createTransaction(), faker.Helpers.createTransaction(), faker.Helpers.createTransaction()]
};
};
@@ -114,6 +115,16 @@ exports.userCard = function () {
};
};
+exports.createTransaction = function(){
+ return {
+ "amount" : faker.Finance.amount(),
+ "date" : new Date(2012, 1, 2), //TODO: add a ranged date method
+ "business": faker.Company.companyName(),
+ "name": [faker.Finance.accountName(), faker.Finance.mask()].join(' '),
+ "type" : exports.randomize(faker.definitions.transaction_type),
+ "account" : faker.Finance.account()
+ };
+};
/*
String.prototype.capitalize = function () { //v1.0
@@ -122,3 +133,4 @@ String.prototype.capitalize = function () { //v1.0
});
};
*/
+