Skip to content

Commit

Permalink
bundled version of Faker.js should now be working
Browse files Browse the repository at this point in the history
  • Loading branch information
Marak committed May 15, 2010
1 parent 10383fe commit 529dc73
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 87 deletions.
3 changes: 3 additions & 0 deletions BUILD/BUILD.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ for(var module in Faker){
}
docs.API += '</ul>';

// definitions hack
code += 'var definitions = Faker.definitions; \n';
code += 'var Helpers = Faker.Helpers; \n';

// generate some samples sets (move this code to another section)
fs.writeFile('../Faker.js', code, function() {
Expand Down
170 changes: 86 additions & 84 deletions Faker.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## generate massive amounts of fake data in Node.js and the browser
<img src = "http://imgur.com/KiinQ.png" border = "0">
## API
<ul><li>definitions<ul><li>first_name</li><li>last_name</li><li>name_prefix</li><li>name_suffix</li><li>us_state</li><li>us_state_abbr</li><li>city_prefix</li><li>city_suffix</li><li>street_suffix</li><li>uk_county</li><li>uk_country</li><li>catch_phrase_adjective</li><li>catch_phrase_descriptor</li><li>catch_phrase_noun</li><li>bs_adjective</li><li>bs_buzz</li><li>bs_noun</li><li>domain_suffix</li><li>lorem</li><li>phone_formats</li></ul></li><li>Name<ul><li>findName</li></ul></li><li>Address<ul><li>zipCode</li><li>city</li><li>streetName</li><li>streetAddress</li><li>secondaryAddress</li><li>ukCounty</li><li>ukCountry</li></ul></li><li>PhoneNumber<ul><li>phoneNumber</li></ul></li><li>Internet<ul><li>email</li><li>userName</li><li>domainName</li><li>domainWord</li></ul></li><li>Company<ul><li>companyName</li><li>companySuffix</li><li>catchPhrase</li><li>bs</li></ul></li><li>Lorem<ul><li>words</li><li>sentence</li><li>sentences</li><li>paragraph</li></ul></li><li>Helpers<ul><li>randomNumber</li><li>randomize</li><li>replaceSymbolWithNumber</li><li>shuffle</li></ul></li></ul>
<ul><li>Name<ul><li>findName</li></ul></li><li>Address<ul><li>zipCode</li><li>city</li><li>streetName</li><li>streetAddress</li><li>secondaryAddress</li><li>ukCounty</li><li>ukCountry</li></ul></li><li>PhoneNumber<ul><li>phoneNumber</li></ul></li><li>Internet<ul><li>email</li><li>userName</li><li>domainName</li><li>domainWord</li></ul></li><li>Company<ul><li>companyName</li><li>companySuffix</li><li>catchPhrase</li><li>bs</li></ul></li><li>Lorem<ul><li>words</li><li>sentence</li><li>sentences</li><li>paragraph</li></ul></li><li>Helpers<ul><li>randomNumber</li><li>randomize</li><li>replaceSymbolWithNumber</li><li>shuffle</li></ul></li><li>definitions<ul><li>first_name</li><li>last_name</li><li>name_prefix</li><li>name_suffix</li><li>us_state</li><li>us_state_abbr</li><li>city_prefix</li><li>city_suffix</li><li>street_suffix</li><li>uk_county</li><li>uk_country</li><li>catch_phrase_adjective</li><li>catch_phrase_descriptor</li><li>catch_phrase_noun</li><li>bs_adjective</li><li>bs_buzz</li><li>bs_noun</li><li>domain_suffix</li><li>lorem</li><li>phone_formats</li></ul></li></ul>
## Authors
####Matthew Bergman & Marak Squires
Heavily inspired by Benjamin Curtis's Ruby Gem [Faker](http://faker.rubyforge.org/) and Perl's [Data::Faker](http://search.cpan.org/~jasonk/Data-Faker-0.07/lib/Data/Faker.pm)
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
exports.definitions = require('./lib/definitions');
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.Lorem = require('./lib/lorem');
exports.Helpers = require('./lib/helpers');

exports.definitions = require('./lib/definitions');
48 changes: 48 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
(function (Helpers) {

// returns a single random number based on a range
Helpers.randomNumber = function(range) {
r = Math.floor(Math.random()*range);
return r;
};

// takes an array and returns the array randomly sorted
Helpers.randomize = function(array) {
r = Math.floor(Math.random()*array.length);
return array[r];
};

// parses string for a symbol and replace it with a random number from 1-10
Helpers.replaceSymbolWithNumber = function(string, symbol){

// default symbol is '#'
if(typeof symbol == 'undefined'){
var symbol = '#';
}

var str = '';
for(var i = 0; i < string.length; i++){
if(string[i] == symbol){
str += Math.floor(Math.random()*10);
}
else{
str += string[i];
}
}
return str;
};

// takes an array and returns it randomized
Helpers.shuffle = function(o){
for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
return o;
};

})(
// exports will be set in any commonjs platform; use it if it's available
typeof exports !== "undefined" ?
exports :
// otherwise construct a name space. outside the anonymous function,
// "this" will always be "window" in a browser, even in strict mode.
this.window = {}
);

0 comments on commit 529dc73

Please sign in to comment.