aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMarak <[email protected]>2014-09-21 08:39:08 +0200
committerMarak <[email protected]>2014-09-21 10:28:41 +0200
commit970be2ef22f1b5895f3880c5f54251b93fdf368a (patch)
tree312f2da0b0336b39c22c7ace01332324d1741596 /lib
parent7fb1370ddcedd9fd1aa77209aa96be99de5d5b87 (diff)
downloadfaker-970be2ef22f1b5895f3880c5f54251b93fdf368a.tar.xz
faker-970be2ef22f1b5895f3880c5f54251b93fdf368a.zip
[api] Added hacker module. Added default values for all methods. Cleaned up errant methods. Added mustache helper.
Diffstat (limited to 'lib')
-rw-r--r--lib/address.js4
-rw-r--r--lib/hacker.js52
-rw-r--r--lib/helpers.js16
-rw-r--r--lib/internet.js3
-rw-r--r--lib/name.js9
-rw-r--r--lib/phone_number.js1
-rw-r--r--lib/random.js1
-rw-r--r--lib/tree.js4
8 files changed, 76 insertions, 14 deletions
diff --git a/lib/address.js b/lib/address.js
index e367aa28..38b2ce5e 100644
--- a/lib/address.js
+++ b/lib/address.js
@@ -6,10 +6,6 @@ var address = {
return Helpers.replaceSymbolWithNumber(faker.random.array_element(["#####", '#####-####']));
},
- zipCodeFormat: function (format) {
- return Helpers.replaceSymbolWithNumber(["#####", '#####-####'][format]);
- },
-
city: function () {
var result;
switch (faker.random.number(3)) {
diff --git a/lib/hacker.js b/lib/hacker.js
new file mode 100644
index 00000000..ca6bfb2d
--- /dev/null
+++ b/lib/hacker.js
@@ -0,0 +1,52 @@
+var faker = require('../index');
+
+var hacker = {
+
+ abbreviation : function () {
+ return faker.random.array_element(faker.definitions.hacker.abbreviation);
+ },
+
+ adjective : function () {
+ return faker.random.array_element(faker.definitions.hacker.adjective);
+ },
+
+ noun : function () {
+ return faker.random.array_element(faker.definitions.hacker.noun);
+ },
+
+ verb : function () {
+ return faker.random.array_element(faker.definitions.hacker.verb);
+ },
+
+ ingverb : function () {
+ return faker.random.array_element(faker.definitions.hacker.ingverb);
+ },
+
+ phrase : function () {
+
+ var data = {
+ abbreviation: hacker.abbreviation(),
+ adjective: hacker.adjective(),
+ ingverb: hacker.ingverb(),
+ noun: hacker.noun(),
+ verb: hacker.verb()
+ };
+
+ var phrase = faker.random.array_element([ "If we {{verb}} the {{noun}}, we can get to the {{abbreviation}} {{noun}} through the {{adjective}} {{abbreviation}} {{noun}}!",
+ "We need to {{verb}} the {{adjective}} {{abbreviation}} {{noun}}!",
+ "Try to {{verb}} the {{abbreviation}} {{noun}}, maybe it will {{verb}} the {{adjective}} {{noun}}!",
+ "You can't {{verb}} the {{noun}} without {{ingverb}} the {{adjective}} {{abbreviation}} {{noun}}!",
+ "Use the {{adjective}} {{abbreviation}} {{noun}}, then you can {{verb}} the {{adjective}} {{noun}}!",
+ "The {{abbreviation}} {{noun}} is down, {{verb}} the {{adjective}} {{noun}} so we can {{verb}} the {{abbreviation}} {{noun}}!",
+ "{{ingverb}} the {{noun}} won't do anything, we need to {{verb}} the {{adjective}} {{abbreviation}} {{noun}}!",
+ "I'll {{verb}} the {{adjective}} {{abbreviation}} {{noun}}, that should {{noun}} the {{abbreviation}} {{noun}}!"
+ ]);
+
+ return faker.helpers.mustache(phrase, data);
+
+ },
+
+
+};
+
+module.exports = hacker;
diff --git a/lib/helpers.js b/lib/helpers.js
index 203ac9e4..91d73c86 100644
--- a/lib/helpers.js
+++ b/lib/helpers.js
@@ -7,16 +7,19 @@ exports.randomNumber = function (range) {
// backword-compatibility
exports.randomize = function (array) {
+ array = array || ["a", "b", "c"];
return faker.random.array_element(array);
};
// slugifies string
exports.slugify = function (string) {
+ string = string || "";
return string.replace(/ /g, '-').replace(/[^\w\.\-]+/g, '');
};
// parses string for a symbol and replace it with a random number from 1-10
exports.replaceSymbolWithNumber = function (string, symbol) {
+ string = string || "";
// default symbol is '#'
if (symbol === undefined) {
symbol = '#';
@@ -35,10 +38,19 @@ exports.replaceSymbolWithNumber = function (string, symbol) {
// takes an array and returns it randomized
exports.shuffle = function (o) {
+ o = o || ["a", "b", "c"];
for (var j, x, i = o.length; i; j = faker.random.number(i), x = o[--i], o[i] = o[j], o[j] = x);
return o;
};
+exports.mustache = function (str, data) {
+ for(var p in data) {
+ var re = new RegExp('{{' + p + '}}', 'g')
+ str = str.replace(re, data[p]);
+ }
+ return str;
+};
+
exports.createCard = function () {
return {
"name": faker.name.findName(),
@@ -95,7 +107,10 @@ exports.contextualCard = function () {
return {
"name": name,
"username": userName,
+ "avatar": faker.internet.avatarUri(),
"email": faker.internet.email(userName),
+ "dob": faker.date.past(50, new Date("Sat Sep 20 1992 21:35:02 GMT+0200 (CEST)")),
+ "phone": faker.phone.phoneNumber(),
"address": {
"street": faker.address.streetName(true),
"suite": faker.address.secondaryAddress(),
@@ -106,7 +121,6 @@ exports.contextualCard = function () {
"lng": faker.address.longitude()
}
},
- "phone": faker.phone.phoneNumber(),
"website": faker.internet.domainName(),
"company": {
"name": faker.company.companyName(),
diff --git a/lib/internet.js b/lib/internet.js
index 617c76a3..fdef75fb 100644
--- a/lib/internet.js
+++ b/lib/internet.js
@@ -58,6 +58,9 @@ var internet = {
},
color: function (baseRed255, baseGreen255, baseBlue255) {
+ baseRed255 = baseRed255 || 0;
+ baseGreen255 = baseGreen255 || 0;
+ baseBlue255 = baseBlue255 || 0;
// based on awesome response : http://stackoverflow.com/questions/43044/algorithm-to-randomly-generate-an-aesthetically-pleasing-color-palette
var red = Math.floor((faker.random.number(256) + baseRed255) / 2);
var green = Math.floor((faker.random.number(256) + baseRed255) / 2);
diff --git a/lib/name.js b/lib/name.js
index 483b8852..c697fe8d 100644
--- a/lib/name.js
+++ b/lib/name.js
@@ -5,15 +5,6 @@ var _name = {
return faker.random.array_element(faker.definitions.name.first_name)
},
- //Working as intended
- firstNameFemale: function () {
- return faker.name.firstName();
- },
- //Working as intended
- firstNameMale: function () {
- return faker.name.firstName();
- },
-
lastName: function () {
return faker.random.array_element(faker.definitions.name.last_name)
},
diff --git a/lib/phone_number.js b/lib/phone_number.js
index 624aba51..29d4f161 100644
--- a/lib/phone_number.js
+++ b/lib/phone_number.js
@@ -7,6 +7,7 @@ var phone = {
// FIXME: this is strange passing in an array index.
phoneNumberFormat: function (phoneFormatsArrayIndex) {
+ phoneFormatsArrayIndex = phoneFormatsArrayIndex || 0;
return faker.helpers.replaceSymbolWithNumber(faker.definitions.phone_number.formats[phoneFormatsArrayIndex]);
},
diff --git a/lib/random.js b/lib/random.js
index d4dcbc15..ada5ed86 100644
--- a/lib/random.js
+++ b/lib/random.js
@@ -37,6 +37,7 @@ var random = {
// takes an array and returns the array randomly sorted
array_element: function (array) {
+ array = array || ["a", "b", "c"];
var r = faker.random.number({ max: array.length - 1 });
return array[r];
},
diff --git a/lib/tree.js b/lib/tree.js
index 07a6242b..204d10f4 100644
--- a/lib/tree.js
+++ b/lib/tree.js
@@ -15,6 +15,10 @@ var tree = {
},
createTree: function (depth, width, obj) {
+ depth = depth || 0;
+ width = width || 0;
+ obj = obj || {};
+
if (!obj) {
throw {
name: "ObjectError",