diff options
| author | Matthew Bergman <[email protected]> | 2010-05-14 22:38:13 -0400 |
|---|---|---|
| committer | Matthew Bergman <[email protected]> | 2010-05-14 22:38:13 -0400 |
| commit | 04288f8e1f24be8daafc5282bc8df35fcbc27b05 (patch) | |
| tree | 97142b8ad9e8127aa554c7953e23e5706aa129bb | |
| parent | 7176a0b8b39f1a635eee1dd7786980ec96707494 (diff) | |
| download | faker-04288f8e1f24be8daafc5282bc8df35fcbc27b05.tar.xz faker-04288f8e1f24be8daafc5282bc8df35fcbc27b05.zip | |
added helper file
| -rw-r--r-- | helper.js | 38 | ||||
| -rw-r--r-- | index.js | 27 | ||||
| -rw-r--r-- | lib/address.js | 7 | ||||
| -rw-r--r-- | lib/name.js | 2 |
4 files changed, 49 insertions, 25 deletions
diff --git a/helper.js b/helper.js new file mode 100644 index 00000000..6127e090 --- /dev/null +++ b/helper.js @@ -0,0 +1,38 @@ +(function (Helper) { + +Helper.randomize = function(array) { + r = Math.floor(Math.random()*array.length); + return array[r]; +}; + +Helper.numerify = function(number_string){ + var str = ''; + for(var i = 0; i < number_string.length; i++){ + if(number_string[i] == "#"){ + str += Math.floor(Math.random()*10); + } + else{ + str += number_string[i]; + } + } + return str; +}; + +Helper.letterify = function(letter_string){ + //return letter_string.gsub(/\?/) { ('a'..'z').to_a.rand } + return 'zzz'; +}; +Helper.bothify = function(string){ + // self.letterify(self.numerify(string)) + //letterify + return 'zz11zz'; +}; + +})( + // 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 = {} +);
\ No newline at end of file @@ -5,30 +5,9 @@ var definitions = require('./lib/definitions'); var Faker = {}; Faker.Name = require('./lib/name'); +Faker.Address = require('./lib/address'); - -Faker.numerify = function(number_string){ - var str = ''; - for(var i = 0; i < number_string.length; i++){ - if(number_string[i] == "#"){ - str += Math.floor(Math.random()*10); - } - else{ - str += number_string[i] - } - } - return str; -}; - -Faker.letterify = function(letter_string){ - //return letter_string.gsub(/\?/) { ('a'..'z').to_a.rand } - return 'zzz'; -}; -Faker.bothify = function(string){ - // self.letterify(self.numerify(string)) - //letterify - return 'zz11zz'; -}; - +var Helper = require('helper');; sys.puts(JSON.stringify(Faker.Name.first_name())); +sys.puts(JSON.stringify(Faker.Address.zip_code())); diff --git a/lib/address.js b/lib/address.js index e69de29b..690e74ba 100644 --- a/lib/address.js +++ b/lib/address.js @@ -0,0 +1,7 @@ +var Faker = {}; + +var Helper = require('../helper'); + +var company = exports.zip_code = function() { + return Helper.numerify(Helper.randomize(["#####", '#####-####'])); +}; diff --git a/lib/name.js b/lib/name.js index 22ff0bd2..dd564cd0 100644 --- a/lib/name.js +++ b/lib/name.js @@ -5,4 +5,4 @@ var name = exports.first_name = function(){ return definitions.first_name[0]; //Math.floor(Math.random()*10); -}; +};
\ No newline at end of file |
