aboutsummaryrefslogtreecommitdiff
path: root/lib/finance.js
blob: 4bf50bff87d927db6b00ff9f661f247d496ea377 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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;