Skip to content

Commit

Permalink
namespacing with 'Faker'
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanDonovan committed Jan 7, 2013
1 parent 03701ad commit c7c3629
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 186 deletions.
28 changes: 14 additions & 14 deletions lib/address.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var helpers = require('./helpers');
var random = require('./random');
var Faker = require('../index');
var definitions = require('../lib/definitions');

exports.zipCode = function () {
Expand All @@ -11,24 +11,24 @@ exports.zipCodeFormat = function (format) {
};

exports.city = function () {
switch (random.number(3)) {
switch (Faker.random.number(3)) {
case 0:
return random.city_prefix() + " " + random.first_name() + random.city_suffix();
return Faker.random.city_prefix() + " " + Faker.random.first_name() + Faker.random.city_suffix();
case 1:
return random.city_prefix() + " " + random.first_name();
return Faker.random.city_prefix() + " " + Faker.random.first_name();
case 2:
return random.first_name() + random.city_suffix();
return Faker.random.first_name() + Faker.random.city_suffix();
case 3:
return random.last_name() + random.city_suffix();
return Faker.random.last_name() + Faker.random.city_suffix();
}
};

exports.streetName = function () {
switch (random.number(1)) {
switch (Faker.random.number(1)) {
case 0:
return random.last_name() + " " + random.street_suffix();
return Faker.random.last_name() + " " + Faker.random.street_suffix();
case 1:
return random.first_name() + " " + random.street_suffix();
return Faker.random.first_name() + " " + Faker.random.street_suffix();
}
};

Expand All @@ -38,7 +38,7 @@ exports.streetName = function () {
exports.streetAddress = function (useFullAddress) {
if (useFullAddress === undefined) { useFullAddress = false; }
var address = "";
switch (random.number(2)) {
switch (Faker.random.number(2)) {
case 0:
address = helpers.replaceSymbolWithNumber("#####") + " " + this.streetName();
break;
Expand All @@ -62,17 +62,17 @@ exports.secondaryAddress = function () {
};

exports.brState = function (useAbbr) {
return useAbbr ? random.br_state_abbr() : random.br_state();
return useAbbr ? Faker.random.br_state_abbr() : Faker.random.br_state();
};

exports.ukCounty = function () {
return random.uk_county();
return Faker.random.uk_county();
};

exports.ukCountry = function () {
return random.uk_country();
return Faker.random.uk_country();
};

exports.usState = function (useAbbr) {
return useAbbr ? random.us_state_abbr() : random.us_state();
return useAbbr ? Faker.random.us_state_abbr() : Faker.random.us_state();
};
25 changes: 12 additions & 13 deletions lib/company.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
var Name = require('./name');
var random = require('../lib/random');
var Faker = require('../index');

var company = {
suffixes: ["Inc", "and Sons", "LLC", "Group", "and Daughters"],

companyName: function (format) {
switch ((format ? format : random.number(3))) {
switch ((format ? format : Faker.random.number(3))) {
case 0:
return Name.lastName() + " " + this.companySuffix();
return Faker.Name.lastName() + " " + this.companySuffix();
case 1:
return Name.lastName() + "-" + Name.lastName();
return Faker.Name.lastName() + "-" + Faker.Name.lastName();
case 2:
return Name.lastName() + ", " + Name.lastName() + " and " + Name.lastName();
return Faker.Name.lastName() + ", " + Faker.Name.lastName() + " and " + Faker.Name.lastName();
}
},

companySuffix: function () {
return random.array_rand(this.suffixes);
return Faker.random.array_rand(this.suffixes);
},

catchPhrase: function () {
return random.catch_phrase_adjective() + " " +
random.catch_phrase_descriptor() + " " +
random.catch_phrase_noun();
return Faker.random.catch_phrase_adjective() + " " +
Faker.random.catch_phrase_descriptor() + " " +
Faker.random.catch_phrase_noun();
},

bs: function () {
return random.bs_adjective() + " " +
random.bs_buzz() + " " +
random.bs_noun();
return Faker.random.bs_adjective() + " " +
Faker.random.bs_buzz() + " " +
Faker.random.bs_noun();
}
};

Expand Down
7 changes: 3 additions & 4 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
var Faker = require('../Faker');
var random = require('./random');
var Faker = require('../index');

// temporary backword-compatibility
exports.randomNumber = function (range) {
return random.number(range);
return Faker.random.number(range);
};

// temporary backword-compatibility
exports.randomize = function (array) {
return random.array_rand(array);
return Faker.random.array_rand(array);
};

// parses string for a symbol and replace it with a random number from 1-10
Expand Down
12 changes: 6 additions & 6 deletions lib/name.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
var random = require('./random');
var Faker = require('../index');

var _name = {
firstName: function () {
return random.first_name();
return Faker.random.first_name();
},

lastName: function () {
return random.last_name();
return Faker.random.last_name();
},

findName: function () {
var r = random.number(8);
var r = Faker.random.number(8);
switch (r) {
case 0:
return random.name_prefix() + " " + _name.firstName() + " " + _name.lastName();
return Faker.random.name_prefix() + " " + _name.firstName() + " " + _name.lastName();
case 1:
return _name.firstName() + " " + _name.lastName() + " " + random.name_suffix();
return _name.firstName() + " " + _name.lastName() + " " + Faker.random.name_suffix();
}

return _name.firstName() + " " + _name.lastName();
Expand Down
Loading

0 comments on commit c7c3629

Please sign in to comment.