diff options
| author | Matthew Bergman <[email protected]> | 2014-09-17 18:44:01 +0200 |
|---|---|---|
| committer | Matthew Bergman <[email protected]> | 2014-09-17 18:44:01 +0200 |
| commit | 7fb1370ddcedd9fd1aa77209aa96be99de5d5b87 (patch) | |
| tree | 0d2c8451e5c6818e4fa9a585991c6bbcf5ec3562 | |
| parent | 392c709924a97556058783641a6fef1b97c953d8 (diff) | |
| parent | ea627d9226e200db3b15f92d94aaee3b84672823 (diff) | |
| download | faker-7fb1370ddcedd9fd1aa77209aa96be99de5d5b87.tar.xz faker-7fb1370ddcedd9fd1aa77209aa96be99de5d5b87.zip | |
Merge pull request #123 from MQuy/master
[feature] - add faker for currency
| -rw-r--r-- | index.js | 2 | ||||
| -rw-r--r-- | lib/finance.js | 21 | ||||
| -rw-r--r-- | lib/locales/en.js | 681 | ||||
| -rw-r--r-- | lib/random.js | 9 | ||||
| -rw-r--r-- | test/all.functional.js | 4 | ||||
| -rw-r--r-- | test/finance.unit.js | 20 |
6 files changed, 725 insertions, 12 deletions
@@ -47,7 +47,7 @@ var _definitions = { "lorem": ["words"], "phone_number": ["formats"], "internet": ["avatar_uri", "domain_suffix", "free_email"], - "finance": ["account_type", "transaction_type"], + "finance": ["account_type", "transaction_type", "currency"], }; // Create a Getter for all definitions.foo.bar propetries diff --git a/lib/finance.js b/lib/finance.js index 67927281..3de96094 100644 --- a/lib/finance.js +++ b/lib/finance.js @@ -23,12 +23,12 @@ var finance = { 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 = ''; @@ -64,6 +64,23 @@ var finance = { transactionType: function () { return Helpers.randomize(faker.definitions.finance.transaction_type); + }, + + currencyCode: function () { + return faker.random.object_element(faker.definitions.finance.currency)['code']; + }, + + currencyName: function () { + return faker.random.object_element(faker.definitions.finance.currency, 'key'); + }, + + currencySymbol: function () { + var symbol; + + while (!symbol) { + symbol = faker.random.object_element(faker.definitions.finance.currency)['symbol']; + } + return symbol; } }; diff --git a/lib/locales/en.js b/lib/locales/en.js index b8c4b94a..fe493eba 100644 --- a/lib/locales/en.js +++ b/lib/locales/en.js @@ -8017,4 +8017,683 @@ en.app = { en.finance = {}; en.finance.account_type = ["Checking","Savings","Money Market", "Investment", "Home Loan", "Credit Card", "Auto Loan", "Personal Loan"]; -en.finance.transaction_type = ["deposit", "withdrawal", "payment", "invoice"];
\ No newline at end of file +en.finance.transaction_type = ["deposit", "withdrawal", "payment", "invoice"]; + +en.finance.currency = { + "UAE Dirham": { + "code": "AED", + "symbol": "" + }, + "Afghani": { + "code": "AFN", + "symbol": "؋" + }, + "Lek": { + "code": "ALL", + "symbol": "Lek" + }, + "Armenian Dram": { + "code": "AMD", + "symbol": "" + }, + "Netherlands Antillian Guilder": { + "code": "ANG", + "symbol": "ƒ" + }, + "Kwanza": { + "code": "AOA", + "symbol": "" + }, + "Argentine Peso": { + "code": "ARS", + "symbol": "$" + }, + "Australian Dollar": { + "code": "AUD", + "symbol": "$" + }, + "Aruban Guilder": { + "code": "AWG", + "symbol": "ƒ" + }, + "Azerbaijanian Manat": { + "code": "AZN", + "symbol": "ман" + }, + "Convertible Marks": { + "code": "BAM", + "symbol": "KM" + }, + "Barbados Dollar": { + "code": "BBD", + "symbol": "$" + }, + "Taka": { + "code": "BDT", + "symbol": "" + }, + "Bulgarian Lev": { + "code": "BGN", + "symbol": "лв" + }, + "Bahraini Dinar": { + "code": "BHD", + "symbol": "" + }, + "Burundi Franc": { + "code": "BIF", + "symbol": "" + }, + "Bermudian Dollar (customarily known as Bermuda Dollar)": { + "code": "BMD", + "symbol": "$" + }, + "Brunei Dollar": { + "code": "BND", + "symbol": "$" + }, + "Boliviano Mvdol": { + "code": "BOB BOV", + "symbol": "$b" + }, + "Brazilian Real": { + "code": "BRL", + "symbol": "R$" + }, + "Bahamian Dollar": { + "code": "BSD", + "symbol": "$" + }, + "Pula": { + "code": "BWP", + "symbol": "P" + }, + "Belarussian Ruble": { + "code": "BYR", + "symbol": "p." + }, + "Belize Dollar": { + "code": "BZD", + "symbol": "BZ$" + }, + "Canadian Dollar": { + "code": "CAD", + "symbol": "$" + }, + "Congolese Franc": { + "code": "CDF", + "symbol": "" + }, + "Swiss Franc": { + "code": "CHF", + "symbol": "CHF" + }, + "Chilean Peso Unidades de fomento": { + "code": "CLP CLF", + "symbol": "$" + }, + "Yuan Renminbi": { + "code": "CNY", + "symbol": "¥" + }, + "Colombian Peso Unidad de Valor Real": { + "code": "COP COU", + "symbol": "$" + }, + "Costa Rican Colon": { + "code": "CRC", + "symbol": "₡" + }, + "Cuban Peso Peso Convertible": { + "code": "CUP CUC", + "symbol": "₱" + }, + "Cape Verde Escudo": { + "code": "CVE", + "symbol": "" + }, + "Czech Koruna": { + "code": "CZK", + "symbol": "Kč" + }, + "Djibouti Franc": { + "code": "DJF", + "symbol": "" + }, + "Danish Krone": { + "code": "DKK", + "symbol": "kr" + }, + "Dominican Peso": { + "code": "DOP", + "symbol": "RD$" + }, + "Algerian Dinar": { + "code": "DZD", + "symbol": "" + }, + "Kroon": { + "code": "EEK", + "symbol": "" + }, + "Egyptian Pound": { + "code": "EGP", + "symbol": "£" + }, + "Nakfa": { + "code": "ERN", + "symbol": "" + }, + "Ethiopian Birr": { + "code": "ETB", + "symbol": "" + }, + "Euro": { + "code": "EUR", + "symbol": "€" + }, + "Fiji Dollar": { + "code": "FJD", + "symbol": "$" + }, + "Falkland Islands Pound": { + "code": "FKP", + "symbol": "£" + }, + "Pound Sterling": { + "code": "GBP", + "symbol": "£" + }, + "Lari": { + "code": "GEL", + "symbol": "" + }, + "Cedi": { + "code": "GHS", + "symbol": "" + }, + "Gibraltar Pound": { + "code": "GIP", + "symbol": "£" + }, + "Dalasi": { + "code": "GMD", + "symbol": "" + }, + "Guinea Franc": { + "code": "GNF", + "symbol": "" + }, + "Quetzal": { + "code": "GTQ", + "symbol": "Q" + }, + "Guyana Dollar": { + "code": "GYD", + "symbol": "$" + }, + "Hong Kong Dollar": { + "code": "HKD", + "symbol": "$" + }, + "Lempira": { + "code": "HNL", + "symbol": "L" + }, + "Croatian Kuna": { + "code": "HRK", + "symbol": "kn" + }, + "Gourde US Dollar": { + "code": "HTG USD", + "symbol": "" + }, + "Forint": { + "code": "HUF", + "symbol": "Ft" + }, + "Rupiah": { + "code": "IDR", + "symbol": "Rp" + }, + "New Israeli Sheqel": { + "code": "ILS", + "symbol": "₪" + }, + "Indian Rupee": { + "code": "INR", + "symbol": "" + }, + "Indian Rupee Ngultrum": { + "code": "INR BTN", + "symbol": "" + }, + "Iraqi Dinar": { + "code": "IQD", + "symbol": "" + }, + "Iranian Rial": { + "code": "IRR", + "symbol": "﷼" + }, + "Iceland Krona": { + "code": "ISK", + "symbol": "kr" + }, + "Jamaican Dollar": { + "code": "JMD", + "symbol": "J$" + }, + "Jordanian Dinar": { + "code": "JOD", + "symbol": "" + }, + "Yen": { + "code": "JPY", + "symbol": "¥" + }, + "Kenyan Shilling": { + "code": "KES", + "symbol": "" + }, + "Som": { + "code": "KGS", + "symbol": "лв" + }, + "Riel": { + "code": "KHR", + "symbol": "៛" + }, + "Comoro Franc": { + "code": "KMF", + "symbol": "" + }, + "North Korean Won": { + "code": "KPW", + "symbol": "₩" + }, + "Won": { + "code": "KRW", + "symbol": "₩" + }, + "Kuwaiti Dinar": { + "code": "KWD", + "symbol": "" + }, + "Cayman Islands Dollar": { + "code": "KYD", + "symbol": "$" + }, + "Tenge": { + "code": "KZT", + "symbol": "лв" + }, + "Kip": { + "code": "LAK", + "symbol": "₭" + }, + "Lebanese Pound": { + "code": "LBP", + "symbol": "£" + }, + "Sri Lanka Rupee": { + "code": "LKR", + "symbol": "₨" + }, + "Liberian Dollar": { + "code": "LRD", + "symbol": "$" + }, + "Lithuanian Litas": { + "code": "LTL", + "symbol": "Lt" + }, + "Latvian Lats": { + "code": "LVL", + "symbol": "Ls" + }, + "Libyan Dinar": { + "code": "LYD", + "symbol": "" + }, + "Moroccan Dirham": { + "code": "MAD", + "symbol": "" + }, + "Moldovan Leu": { + "code": "MDL", + "symbol": "" + }, + "Malagasy Ariary": { + "code": "MGA", + "symbol": "" + }, + "Denar": { + "code": "MKD", + "symbol": "ден" + }, + "Kyat": { + "code": "MMK", + "symbol": "" + }, + "Tugrik": { + "code": "MNT", + "symbol": "₮" + }, + "Pataca": { + "code": "MOP", + "symbol": "" + }, + "Ouguiya": { + "code": "MRO", + "symbol": "" + }, + "Mauritius Rupee": { + "code": "MUR", + "symbol": "₨" + }, + "Rufiyaa": { + "code": "MVR", + "symbol": "" + }, + "Kwacha": { + "code": "MWK", + "symbol": "" + }, + "Mexican Peso Mexican Unidad de Inversion (UDI)": { + "code": "MXN MXV", + "symbol": "$" + }, + "Malaysian Ringgit": { + "code": "MYR", + "symbol": "RM" + }, + "Metical": { + "code": "MZN", + "symbol": "MT" + }, + "Naira": { + "code": "NGN", + "symbol": "₦" + }, + "Cordoba Oro": { + "code": "NIO", + "symbol": "C$" + }, + "Norwegian Krone": { + "code": "NOK", + "symbol": "kr" + }, + "Nepalese Rupee": { + "code": "NPR", + "symbol": "₨" + }, + "New Zealand Dollar": { + "code": "NZD", + "symbol": "$" + }, + "Rial Omani": { + "code": "OMR", + "symbol": "﷼" + }, + "Balboa US Dollar": { + "code": "PAB USD", + "symbol": "B/." + }, + "Nuevo Sol": { + "code": "PEN", + "symbol": "S/." + }, + "Kina": { + "code": "PGK", + "symbol": "" + }, + "Philippine Peso": { + "code": "PHP", + "symbol": "Php" + }, + "Pakistan Rupee": { + "code": "PKR", + "symbol": "₨" + }, + "Zloty": { + "code": "PLN", + "symbol": "zł" + }, + "Guarani": { + "code": "PYG", + "symbol": "Gs" + }, + "Qatari Rial": { + "code": "QAR", + "symbol": "﷼" + }, + "New Leu": { + "code": "RON", + "symbol": "lei" + }, + "Serbian Dinar": { + "code": "RSD", + "symbol": "Дин." + }, + "Russian Ruble": { + "code": "RUB", + "symbol": "руб" + }, + "Rwanda Franc": { + "code": "RWF", + "symbol": "" + }, + "Saudi Riyal": { + "code": "SAR", + "symbol": "﷼" + }, + "Solomon Islands Dollar": { + "code": "SBD", + "symbol": "$" + }, + "Seychelles Rupee": { + "code": "SCR", + "symbol": "₨" + }, + "Sudanese Pound": { + "code": "SDG", + "symbol": "" + }, + "Swedish Krona": { + "code": "SEK", + "symbol": "kr" + }, + "Singapore Dollar": { + "code": "SGD", + "symbol": "$" + }, + "Saint Helena Pound": { + "code": "SHP", + "symbol": "£" + }, + "Leone": { + "code": "SLL", + "symbol": "" + }, + "Somali Shilling": { + "code": "SOS", + "symbol": "S" + }, + "Surinam Dollar": { + "code": "SRD", + "symbol": "$" + }, + "Dobra": { + "code": "STD", + "symbol": "" + }, + "El Salvador Colon US Dollar": { + "code": "SVC USD", + "symbol": "$" + }, + "Syrian Pound": { + "code": "SYP", + "symbol": "£" + }, + "Lilangeni": { + "code": "SZL", + "symbol": "" + }, + "Baht": { + "code": "THB", + "symbol": "฿" + }, + "Somoni": { + "code": "TJS", + "symbol": "" + }, + "Manat": { + "code": "TMT", + "symbol": "" + }, + "Tunisian Dinar": { + "code": "TND", + "symbol": "" + }, + "Pa'anga": { + "code": "TOP", + "symbol": "" + }, + "Turkish Lira": { + "code": "TRY", + "symbol": "TL" + }, + "Trinidad and Tobago Dollar": { + "code": "TTD", + "symbol": "TT$" + }, + "New Taiwan Dollar": { + "code": "TWD", + "symbol": "NT$" + }, + "Tanzanian Shilling": { + "code": "TZS", + "symbol": "" + }, + "Hryvnia": { + "code": "UAH", + "symbol": "₴" + }, + "Uganda Shilling": { + "code": "UGX", + "symbol": "" + }, + "US Dollar": { + "code": "USD", + "symbol": "$" + }, + "Peso Uruguayo Uruguay Peso en Unidades Indexadas": { + "code": "UYU UYI", + "symbol": "$U" + }, + "Uzbekistan Sum": { + "code": "UZS", + "symbol": "лв" + }, + "Bolivar Fuerte": { + "code": "VEF", + "symbol": "Bs" + }, + "Dong": { + "code": "VND", + "symbol": "₫" + }, + "Vatu": { + "code": "VUV", + "symbol": "" + }, + "Tala": { + "code": "WST", + "symbol": "" + }, + "CFA Franc BEAC": { + "code": "XAF", + "symbol": "" + }, + "Silver": { + "code": "XAG", + "symbol": "" + }, + "Gold": { + "code": "XAU", + "symbol": "" + }, + "Bond Markets Units European Composite Unit (EURCO)": { + "code": "XBA", + "symbol": "" + }, + "European Monetary Unit (E.M.U.-6)": { + "code": "XBB", + "symbol": "" + }, + "European Unit of Account 9(E.U.A.-9)": { + "code": "XBC", + "symbol": "" + }, + "European Unit of Account 17(E.U.A.-17)": { + "code": "XBD", + "symbol": "" + }, + "East Caribbean Dollar": { + "code": "XCD", + "symbol": "$" + }, + "SDR": { + "code": "XDR", + "symbol": "" + }, + "UIC-Franc": { + "code": "XFU", + "symbol": "" + }, + "CFA Franc BCEAO": { + "code": "XOF", + "symbol": "" + }, + "Palladium": { + "code": "XPD", + "symbol": "" + }, + "CFP Franc": { + "code": "XPF", + "symbol": "" + }, + "Platinum": { + "code": "XPT", + "symbol": "" + }, + "Codes specifically reserved for testing purposes": { + "code": "XTS", + "symbol": "" + }, + "Yemeni Rial": { + "code": "YER", + "symbol": "﷼" + }, + "Rand": { + "code": "ZAR", + "symbol": "R" + }, + "Rand Loti": { + "code": "ZAR LSL", + "symbol": "" + }, + "Rand Namibia Dollar": { + "code": "ZAR NAD", + "symbol": "" + }, + "Zambian Kwacha": { + "code": "ZMK", + "symbol": "" + }, + "Zimbabwe Dollar": { + "code": "ZWL", + "symbol": "" + } +};
\ No newline at end of file diff --git a/lib/random.js b/lib/random.js index 770bb90a..d4dcbc15 100644 --- a/lib/random.js +++ b/lib/random.js @@ -39,8 +39,15 @@ var random = { array_element: function (array) { var r = faker.random.number({ max: array.length - 1 }); return array[r]; - } + }, + // takes an object and returns the randomly key or value + object_element: function (object, field) { + var array = Object.keys(object); + var key = faker.random.array_element(array); + + return field === "key" ? key : object[key]; + } }; module.exports = random; diff --git a/test/all.functional.js b/test/all.functional.js index 02b801ac..1a2e836a 100644 --- a/test/all.functional.js +++ b/test/all.functional.js @@ -20,7 +20,9 @@ var modules = { name: ['firstName', 'lastName', 'findName'], - phone: ['phoneNumber'] + phone: ['phoneNumber'], + + finance: ['account', 'accountName', 'mask', 'amount', 'transactionType', 'currencyCode', 'currencyName', 'currencySymbol'] }; describe("functional tests", function () { diff --git a/test/finance.unit.js b/test/finance.unit.js index ee1ce0ee..ceb15244 100644 --- a/test/finance.unit.js +++ b/test/finance.unit.js @@ -74,17 +74,17 @@ describe('finance.js', function () { it("should set a specified length", function () { var expected = faker.random.number(20); - + expected = (expected == 0 || !expected || typeof expected == 'undefined') ? 4 : expected; - + var mask = faker.finance.mask(expected, false, false); var actual = mask.length; //picks 4 if the random number generator picks 0 - + assert.equal(actual, expected, 'The expected default mask length is ' + expected + ' but it was ' + actual); }); - + it("should set a default length of 4 for a zero value", function () { var expected = 4; @@ -92,11 +92,11 @@ describe('finance.js', function () { var mask = faker.finance.mask(0, false, false); var actual = 4; //picks 4 if the random number generator picks 0 - + assert.equal(actual, expected, 'The expected default mask length is ' + expected + ' but it was ' + actual); }); - + it("should by default include parentheses around a partial account number", function () { @@ -194,4 +194,12 @@ describe('finance.js', function () { assert.ok(transactionType); }); }); + + describe("currencyCode()", function () { + it("returns a random currency code with a format", function () { + var currencyCode = faker.finance.currencyCode(); + + assert.ok(currencyCode.match(/[A-Z]{3}/)); + }); + }) });
\ No newline at end of file |
