Skip to content

Commit

Permalink
[refactor] [major] Renamed variable names for consistency Closes #5
Browse files Browse the repository at this point in the history
[refactor [major] Moved all errant methods from random.js to individual modules. Methods in random.js were causing unnecessary code complication.
  • Loading branch information
Marak committed Sep 14, 2014
1 parent 0048b9f commit 38f9e3a
Show file tree
Hide file tree
Showing 28 changed files with 514 additions and 531 deletions.
12 changes: 6 additions & 6 deletions build/src/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

<script src = "faker.js" type = "text/javascript"></script>
<script>
var randomName = faker.Name.findName(); // Caitlyn Kerluke
var randomEmail = faker.Internet.email(); // [email protected]
var randomCard = faker.Helpers.createCard(); // random contact card containing many properties
var randomName = faker.name.findName(); // Caitlyn Kerluke
var randomEmail = faker.internet.email(); // [email protected]
var randomCard = faker.helpers.createCard(); // random contact card containing many properties
</script>

### node.js -
Expand All @@ -18,9 +18,9 @@

var faker = require('./faker');

var randomName = faker.Name.findName(); // Rowan Nikolaus
var randomEmail = faker.Internet.email(); // [email protected]
var randomCard = faker.Helpers.createCard(); // random contact card containing many properties
var randomName = faker.name.findName(); // Rowan Nikolaus
var randomEmail = faker.internet.email(); // [email protected]
var randomCard = faker.helpers.createCard(); // random contact card containing many properties


## API
Expand Down
2 changes: 1 addition & 1 deletion examples/browser_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<head>
<script src = "../faker.js" type = "text/javascript"></script>
<script>
var card = faker.Helpers.createCard();
var card = faker.helpers.createCard();
if(typeof JSON == 'undefined'){
document.write('get a real browser that has JSON.stringify and JSON.parse built in <br/>');
// implement JSON.stringify serialization
Expand Down
8 changes: 4 additions & 4 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@

$(document).ready(function(e){

var card = faker.Helpers.createCard();
var card = faker.helpers.createCard();
$('#output').html(prettyPrint(card));

$('#generate').click(function(){
var card = faker.Helpers.createCard();
var card = faker.helpers.createCard();
$('#output').html(prettyPrint(card));
});

Expand All @@ -48,7 +48,7 @@
setTimeout(function(){
var cards = [];
for(var i = 0; i < $('#cardCount').val(); i++){
var card = faker.Helpers.createCard();
var card = faker.helpers.createCard();
cards.push(card);
}
$('#output').html('<textarea cols = "100" rows = "100">'+JSON.stringify(cards)+'</textarea>');
Expand All @@ -66,7 +66,7 @@ <h1>faker.js - generate massive amounts of fake data in Node.js and the browser<
<input id = "generate" type = "button" value = "generate one random card as HTML" />
<input id = "generateSet" type = "button" value = "generate an assosative array of random cards as JSON" />
card count : <input id = "cardCount" type = "text" size = "3" value = "5" /><br/><br/>
<strong>protip</strong>: open your console on this page and run: <code>console.log(faker); var randomName = faker.Name.findName(); console.log(randomName);</code><hr/>
<strong>protip</strong>: open your console on this page and run: <code>console.log(faker); var randomName = faker.name.findName(); console.log(randomName);</code><hr/>
<div id = "output"></div>
</body>
</html>
Expand Down
2 changes: 1 addition & 1 deletion examples/library_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ var definitions = require('../lib/definitions');

var faker = require('../index');

var card = faker.Helpers.createCard();
var card = faker.helpers.createCard();

util.puts(JSON.stringify(card));
4 changes: 2 additions & 2 deletions examples/node_generateSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ var faker= require('../index');


// generate dataSet as example
fs.writeFile('../examples/dataSet.json', JSON.stringify(faker.Helpers.userCard()), function() {
fs.writeFile('../examples/dataSet.json', JSON.stringify(faker.helpers.userCard()), function() {
sys.puts("dataSet generated successfully!");
});
// generate bigDataSet as example
var bigSet = [];

for(i = 20; i >= 0; i--){
bigSet.push(faker.Helpers.userCard());
bigSet.push(faker.helpers.userCard());
};

fs.writeFile('../examples/bigDataSet.json', JSON.stringify(bigSet), function() {
Expand Down
6 changes: 4 additions & 2 deletions examples/node_min_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var util = require('util');

var faker = require('../index');

var card = faker.Helpers.createCard();
var card = faker.helpers.createCard();

util.puts(JSON.stringify(card));
//util.puts(JSON.stringify(card));

console.log(card);
26 changes: 13 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@
you can include the faker library into your existing node.js application by requiring the entire /faker directory
var faker = require(./faker);
var randomName = faker.Name.findName();
var randomName = faker.name.findName();
you can also simply include the "faker.js" file which is the auto-generated bundled version of the faker library
var faker = require(./customAppPath/faker);
var randomName = faker.Name.findName();
var randomName = faker.name.findName();
if you plan on modifying the faker library you should be performing your changes in the /lib/ directory
*/

exports.Name = require('./lib/name');
exports.Address = require('./lib/address');
exports.PhoneNumber = require('./lib/phone_number');
exports.Internet = require('./lib/internet');
exports.Company = require('./lib/company');
exports.Image = require('./lib/image');
exports.Lorem = require('./lib/lorem');
exports.Helpers = require('./lib/helpers');
exports.Tree = require('./lib/tree');
exports.Date = require('./lib/date');
exports.name = require('./lib/name');
exports.address = require('./lib/address');
exports.phoneNumber = require('./lib/phone_number');
exports.internet = require('./lib/internet');
exports.company = require('./lib/company');
exports.image = require('./lib/image');
exports.lorem = require('./lib/lorem');
exports.helpers = require('./lib/helpers');
exports.tree = require('./lib/tree');
exports.date = require('./lib/date');
exports.random = require('./lib/random');
exports.definitions = require('./lib/definitions');
exports.Finance = require('./lib/finance');
exports.finance = require('./lib/finance');

exports.locales = require('./lib/locales');
49 changes: 35 additions & 14 deletions lib/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,37 @@ var address = {
var result;
switch (faker.random.number(3)) {
case 0:
result = faker.random.city_prefix() + " " + faker.random.first_name() + faker.random.city_suffix();
result = faker.address.cityPrefix() + " " + faker.name.firstName() + faker.address.citySuffix();
break;
case 1:
result = faker.random.city_prefix() + " " + faker.random.first_name();
result = faker.address.cityPrefix() + " " + faker.name.firstName();
break;
case 2:
result = faker.random.first_name() + faker.random.city_suffix();
result = faker.name.firstName() + faker.address.citySuffix();
break;
case 3:
result = faker.random.last_name() + faker.random.city_suffix();
result = faker.name.lastName() + faker.address.citySuffix();
break;
}
return result;
},

cityPrefix: function () {
return faker.random.array_element(definitions.city_prefix);
},

citySuffix: function () {
return faker.random.array_element(definitions.city_suffix);
},

streetName: function () {
var result;
switch (faker.random.number(1)) {
case 0:
result = faker.random.last_name() + " " + faker.random.street_suffix();
result = faker.name.lastName() + " " + faker.address.streetSuffix();
break;
case 1:
result = faker.random.first_name() + " " + faker.random.street_suffix();
result = faker.name.firstName() + " " + faker.address.streetSuffix();
break;
}
return result;
Expand All @@ -51,16 +59,20 @@ var address = {
var address = "";
switch (faker.random.number(2)) {
case 0:
address = Helpers.replaceSymbolWithNumber("#####") + " " + faker.Address.streetName();
address = Helpers.replaceSymbolWithNumber("#####") + " " + faker.address.streetName();
break;
case 1:
address = Helpers.replaceSymbolWithNumber("####") + " " + faker.Address.streetName();
address = Helpers.replaceSymbolWithNumber("####") + " " + faker.address.streetName();
break;
case 2:
address = Helpers.replaceSymbolWithNumber("###") + " " + faker.Address.streetName();
address = Helpers.replaceSymbolWithNumber("###") + " " + faker.address.streetName();
break;
}
return useFullAddress ? (address + " " + faker.Address.secondaryAddress()) : address;
return useFullAddress ? (address + " " + faker.address.secondaryAddress()) : address;
},

streetSuffix: function () {
return faker.random.array_element(definitions.street_suffix);
},

secondaryAddress: function () {
Expand All @@ -73,21 +85,30 @@ var address = {
},

brState: function (useAbbr) {
return useAbbr ? faker.random.br_state_abbr() : faker.random.br_state();
return useAbbr ? faker.address.brStateAbbr() : faker.random.array_element(definitions.br_state);
},

brStateAbbr: function () {
return faker.random.array_element(definitions.br_state_abbr);
},

ukCounty: function () {
return faker.random.uk_county();
return faker.random.array_element(definitions.uk_county);
},

ukCountry: function () {
return faker.random.uk_country();
return faker.random.array_element(definitions.uk_country);
},

usState: function (useAbbr) {
return useAbbr ? faker.random.us_state_abbr() : faker.random.us_state();
return useAbbr ? faker.address.usStateAbbr() : faker.random.array_element(definitions.us_state);
},

usStateAbbr: function () {
return faker.random.array_element(definitions.us_state_abbr);
},


latitude: function () {
return (faker.random.number(180 * 10000) / 10000.0 - 90.0).toFixed(4);
},
Expand Down
46 changes: 36 additions & 10 deletions lib/company.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,62 @@
var faker = require('../index');

var company = {

suffixes: function () {
return ["Inc", "and Sons", "LLC", "Group", "and Daughters"];
},

companyName: function (format) {
switch ((format ? format : faker.random.number(2))) {
case 0:
return faker.Name.lastName() + " " + faker.Company.companySuffix();
return faker.name.lastName() + " " + faker.company.companySuffix();
case 1:
return faker.Name.lastName() + "-" + faker.Name.lastName();
return faker.name.lastName() + "-" + faker.name.lastName();
case 2:
return faker.Name.lastName() + ", " + faker.Name.lastName() + " and " + faker.Name.lastName();
return faker.name.lastName() + ", " + faker.name.lastName() + " and " + faker.name.lastName();
}
},

companySuffix: function () {
return faker.random.array_element(faker.Company.suffixes());
return faker.random.array_element(faker.company.suffixes());
},

catchPhrase: function () {
return faker.random.catch_phrase_adjective() + " " +
faker.random.catch_phrase_descriptor() + " " +
faker.random.catch_phrase_noun();
return faker.company.catchPhraseAdjective() + " " +
faker.company.catchPhraseDescriptor() + " " +
faker.company.catchPhraseNoun();
},

bs: function () {
return faker.random.bs_adjective() + " " +
faker.random.bs_buzz() + " " +
faker.random.bs_noun();
return faker.company.bsAdjective() + " " +
faker.company.bsBuzz() + " " +
faker.company.bsNoun();
},

catchPhraseAdjective: function () {
return faker.random.array_element(faker.definitions.catch_phrase_adjective);
},

catchPhraseDescriptor: function () {
return faker.random.array_element(faker.definitions.catch_phrase_descriptor);
},

catchPhraseNoun: function () {
return faker.random.array_element(faker.definitions.catch_phrase_noun);
},

bsAdjective: function () {
return faker.random.array_element(faker.definitions.bs_adjective);
},

bsBuzz: function () {
return faker.random.array_element(faker.definitions.bs_buzz);
},

bsNoun: function () {
return faker.random.array_element(faker.definitions.bs_noun);
}

};

module.exports = company;
Loading

0 comments on commit 38f9e3a

Please sign in to comment.