From 04288f8e1f24be8daafc5282bc8df35fcbc27b05 Mon Sep 17 00:00:00 2001 From: Matthew Bergman Date: Fri, 14 May 2010 22:38:13 -0400 Subject: added helper file --- helper.js | 38 ++++++++++++++++++++++++++++++++++++++ index.js | 27 +++------------------------ lib/address.js | 7 +++++++ lib/name.js | 2 +- 4 files changed, 49 insertions(+), 25 deletions(-) create mode 100644 helper.js 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 diff --git a/index.js b/index.js index 63cff62d..8c8c11c6 100644 --- a/index.js +++ b/index.js @@ -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 -- cgit v1.2.3