Skip to content

Commit

Permalink
Merge pull request zuriby#1 from richardbutler/master
Browse files Browse the repository at this point in the history
Split male and female names to two groups; add random gender
  • Loading branch information
jayliu50 committed Nov 6, 2013
2 parents b17d651 + d40511a commit e7aaa93
Show file tree
Hide file tree
Showing 9 changed files with 11,052 additions and 11 deletions.
4,275 changes: 4,275 additions & 0 deletions data/female-names.txt

Large diffs are not rendered by default.

1,219 changes: 1,219 additions & 0 deletions data/male-names.txt

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion lib/definitions.js

Large diffs are not rendered by default.

4,277 changes: 4,277 additions & 0 deletions lib/female_names.js

Large diffs are not rendered by default.

1,221 changes: 1,221 additions & 0 deletions lib/male_names.js

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions lib/name.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
var Faker = require('../index');

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

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

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

return this.firstName() + " " + this.lastName();
return this.firstName( gender ) + " " + this.lastName();
},

gender: function() {
return Faker.random.gender();
}
};

Expand Down
19 changes: 17 additions & 2 deletions lib/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,23 @@ var random = {
return this.array_element(definitions.uk_country);
},

first_name: function () {
return this.array_element(definitions.first_name);
gender: function() {
return this.array_element([ "male", "female" ]);
},

first_name: function ( gender ) {
var def;

if ( typeof gender === "undefined" ) {
def = [].concat(
definitions.first_name.male,
definitions.first_name.female
);
} else {
def = definitions.first_name[ gender ];
}

return this.array_element( def || [] );
},

last_name: function () {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "Faker",
"description": "Generate massive amounts of fake contextual data",
"version": "0.5.11",
"version": "0.5.12",
"author": "Marak Squires <[email protected]>",
"repository": {
"type": "git",
"url": "http://github.com/Marak/Faker.js.git"
"url": "https://github.com/richardbutler/Faker.js.git"
},
"scripts": {
"test": "node_modules/.bin/mocha test/*.*.js"
Expand Down
23 changes: 23 additions & 0 deletions scripts/import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var fs = require( "fs" );

function importNames( inputFile, outputFile ) {
var input = fs.readFileSync( __dirname + "/" + inputFile ),
names = String( input ).split( "\n" ),
output;

names = names
.map( function( name ) {
name = name.trim();
name = name.charAt( 0 ).toUpperCase() + name.substr( 1 ).toLowerCase();
return name;
}).filter( function( name ) {
return name !== "";
});

output = "module.exports = [\n '" + names.join( "',\n '" ) + "'\n];\n";

fs.writeFileSync( __dirname + "/" + outputFile, output );
}

importNames( "../data/male-names.txt", "../lib/male_names.js" );
importNames( "../data/female-names.txt", "../lib/female_names.js" );

0 comments on commit e7aaa93

Please sign in to comment.