aboutsummaryrefslogtreecommitdiff
path: root/lib/commerce.js
diff options
context:
space:
mode:
authorRonen Babayoff <[email protected]>2015-08-23 21:57:46 -0400
committerRonen Babayoff <[email protected]>2015-08-23 21:57:46 -0400
commit66996e280c9fbbbc2e7db376549f568be32ad5cd (patch)
treee93f412c4bceeb7ed0376e26113c9d31522af8b4 /lib/commerce.js
parentcf0bd70d5fca9c0169414f5d2c16ca32431a3fd9 (diff)
parentd8f8108ac5dbec7e2b7ea9a23dd19aa42255e3fb (diff)
downloadfaker-66996e280c9fbbbc2e7db376549f568be32ad5cd.tar.xz
faker-66996e280c9fbbbc2e7db376549f568be32ad5cd.zip
Merge v3.0.1 into practicalmeteor:faker package branch
Diffstat (limited to 'lib/commerce.js')
-rw-r--r--lib/commerce.js89
1 files changed, 89 insertions, 0 deletions
diff --git a/lib/commerce.js b/lib/commerce.js
new file mode 100644
index 00000000..ec91edb1
--- /dev/null
+++ b/lib/commerce.js
@@ -0,0 +1,89 @@
+var Commerce = function (faker) {
+ var self = this;
+
+ self.color = function() {
+ return faker.random.arrayElement(faker.definitions.commerce.color);
+ };
+
+ self.department = function(max, fixedAmount) {
+
+ return faker.random.arrayElement(faker.definitions.commerce.department);
+ /*
+ 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];
+ */
+ };
+
+ self.productName = function() {
+ return faker.commerce.productAdjective() + " " +
+ faker.commerce.productMaterial() + " " +
+ faker.commerce.product();
+ };
+
+ self.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);
+ };
+
+ /*
+ self.categories = function(num) {
+ var categories = [];
+
+ do {
+ var category = faker.random.arrayElement(faker.definitions.commerce.department);
+ if(categories.indexOf(category) === -1) {
+ categories.push(category);
+ }
+ } while(categories.length < num);
+
+ return categories;
+ };
+
+ */
+ /*
+ self.mergeCategories = function(categories) {
+ var separator = faker.definitions.separator || " &";
+ // TODO: find undefined here
+ categories = categories || faker.definitions.commerce.categories;
+ var commaSeparated = categories.slice(0, -1).join(', ');
+
+ return [commaSeparated, categories[categories.length - 1]].join(separator + " ");
+ };
+ */
+
+ self.productAdjective = function() {
+ return faker.random.arrayElement(faker.definitions.commerce.product_name.adjective);
+ };
+
+ self.productMaterial = function() {
+ return faker.random.arrayElement(faker.definitions.commerce.product_name.material);
+ };
+
+ self.product = function() {
+ return faker.random.arrayElement(faker.definitions.commerce.product_name.product);
+ }
+
+ return self;
+};
+
+module['exports'] = Commerce; \ No newline at end of file