aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorrob.scott <[email protected]>2015-03-10 13:57:02 +0000
committerrob.scott <[email protected]>2015-03-10 13:57:02 +0000
commit3418839d8b818485331ef7931dea1de26c751da2 (patch)
tree7dedc0b4a35e0d1d22b3b3c22210d10b31a5b7a8 /lib
parenta39082f6f49fb326111bc2a0d9014c9dc65fe1fa (diff)
downloadfaker-3418839d8b818485331ef7931dea1de26c751da2.tar.xz
faker-3418839d8b818485331ef7931dea1de26c751da2.zip
Add Commerce functions from https://github.com/stympy/faker into javascript
Diffstat (limited to 'lib')
-rw-r--r--lib/commerce.js81
-rw-r--r--lib/locales/en.js32
2 files changed, 110 insertions, 3 deletions
diff --git a/lib/commerce.js b/lib/commerce.js
new file mode 100644
index 00000000..20b736bc
--- /dev/null
+++ b/lib/commerce.js
@@ -0,0 +1,81 @@
+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);
+
+ console.log("NUMBER: " + 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/locales/en.js b/lib/locales/en.js
index d79cb828..a7d70e8f 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"
]
}
};