diff options
| author | Marak <[email protected]> | 2015-07-06 09:16:55 -0700 |
|---|---|---|
| committer | Marak <[email protected]> | 2015-07-06 09:16:55 -0700 |
| commit | e1866cf2b1cd72b9e267e1258e197798642c73a8 (patch) | |
| tree | b60c75fe73bc63f5b06bb6ec7b4563bff77de29e /lib | |
| parent | 760a2c5e92011cc60286e55447e6cc168c1b86c6 (diff) | |
| parent | 4f5cb5cddad356abad010b746dede809263b95c7 (diff) | |
| download | faker-e1866cf2b1cd72b9e267e1258e197798642c73a8.tar.xz faker-e1866cf2b1cd72b9e267e1258e197798642c73a8.zip | |
[merge] Commerce implementation
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/commerce.js | 79 | ||||
| -rw-r--r-- | lib/internet.js | 2 | ||||
| -rw-r--r-- | lib/locales/en.js | 32 |
3 files changed, 109 insertions, 4 deletions
diff --git a/lib/commerce.js b/lib/commerce.js new file mode 100644 index 00000000..76ec4beb --- /dev/null +++ b/lib/commerce.js @@ -0,0 +1,79 @@ +var faker = require('../index'); + +var commerce = { + + color: function() { + return faker.random.array_element(faker.definitions.commerce.color); + }, + + department: function(max, fixedAmount) { + max = max || 3; + + var num = Math.floor((Math.random() * max) + 1); + if(fixedAmount) { + num = max; + } + + var categories = faker.commerce.categories(num); + + if(num > 1) { + return faker.commerce.mergeCategories(categories); + } + + return categories[0]; + }, + + productName: function() { + return faker.commerce.productAdjective() + " " + + faker.commerce.productMaterial() + " " + + faker.commerce.product(); + }, + + price: function(min, max, dec, symbol) { + min = min || 0; + max = max || 1000; + dec = dec || 2; + symbol = symbol || ''; + + if(min < 0 || max < 0) { + return symbol + 0.00; + } + + return symbol + (Math.round((Math.random() * (max - min) + min) * Math.pow(10, dec)) / Math.pow(10, dec)).toFixed(dec); + }, + + categories: function(num) { + var categories = []; + + do { + var category = faker.random.array_element(faker.definitions.commerce.department); + if(categories.indexOf(category) === -1) { + categories.push(category); + } + } while(categories.length < num); + + return categories; + }, + + mergeCategories: function(categories) { + var separator = faker.definitions.separator; + var commaSeparated = categories.slice(0, -1).join(', '); + + return [commaSeparated, categories[categories.length - 1]].join(separator); + }, + + productAdjective: function() { + return faker.random.array_element(faker.definitions.commerce.product_name.adjective); + }, + + productMaterial: function() { + return faker.random.array_element(faker.definitions.commerce.product_name.material); + }, + + product: function() { + return faker.random.array_element(faker.definitions.commerce.product_name.product); + } + +}; + +module.exports = commerce;
\ No newline at end of file diff --git a/lib/internet.js b/lib/internet.js index 89be21f4..d70088d4 100644 --- a/lib/internet.js +++ b/lib/internet.js @@ -51,7 +51,7 @@ var internet = { }, domainWord: function () { - return faker.name.firstName().replace(/([^A-Z0-9._%+-])/ig, '').toLowerCase(); + return faker.name.firstName().replace(/([\\~#&*{}/:<>?|\"])/ig, '').toLowerCase(); }, ip: function () { diff --git a/lib/locales/en.js b/lib/locales/en.js index d79cb828..ef0123a1 100644 --- a/lib/locales/en.js +++ b/lib/locales/en.js @@ -7723,7 +7723,14 @@ en.commerce = { "Fantastic", "Practical", "Sleek", - "Awesome" + "Awesome", + "Generic", + "Handcrafted", + "Handmade", + "Licensed", + "Refined", + "Unbranded", + "Tasty" ], "material": [ "Steel", @@ -7732,18 +7739,37 @@ en.commerce = { "Plastic", "Cotton", "Granite", - "Rubber" + "Rubber", + "Metal", + "Soft", + "Fresh", + "Frozen" ], "product": [ "Chair", "Car", "Computer", + "Keyboard", + "Mouse", + "Bike", + "Ball", "Gloves", "Pants", "Shirt", "Table", "Shoes", - "Hat" + "Hat", + "Towels", + "Soap", + "Tuna", + "Chicken", + "Fish", + "Cheese", + "Bacon", + "Pizza", + "Salad", + "Sausages", + "Chips" ] } }; |
