diff options
| author | Matthew Bergman <[email protected]> | 2010-05-15 03:10:47 -0400 |
|---|---|---|
| committer | Matthew Bergman <[email protected]> | 2010-05-15 03:10:47 -0400 |
| commit | c6dbabb8689a50754d80693250845efb31c81f68 (patch) | |
| tree | 0d8efbcc2077b06bb6c214d80742379294875278 | |
| parent | 1b195d0e13836bcaf82530ccb6f2c89d2744e287 (diff) | |
| download | faker-c6dbabb8689a50754d80693250845efb31c81f68.tar.xz faker-c6dbabb8689a50754d80693250845efb31c81f68.zip | |
lorem partial working
| -rw-r--r-- | index.js | 5 | ||||
| -rw-r--r-- | lib/lorem.js | 45 |
2 files changed, 27 insertions, 23 deletions
@@ -9,6 +9,7 @@ Faker.Address = require('./lib/address'); Faker.PhoneNumber = require('./lib/phone_number'); Faker.Internet = require('./lib/internet'); Faker.Company = require('./lib/company'); +Faker.Lorem = require('./lib/lorem'); var Helper = require('helper');; @@ -30,6 +31,10 @@ sys.puts(JSON.stringify(Faker.Internet.domainName())); sys.puts(JSON.stringify(Faker.Company.companyName())); sys.puts(JSON.stringify(Faker.Company.catchPhrase())); sys.puts(JSON.stringify(Faker.Company.bs())); +sys.puts(JSON.stringify(Faker.Lorem.words())); +sys.puts(JSON.stringify(Faker.Lorem.sentence())); +sys.puts(JSON.stringify(Faker.Lorem.sentences())); + diff --git a/lib/lorem.js b/lib/lorem.js index f73f7e87..93f7b600 100644 --- a/lib/lorem.js +++ b/lib/lorem.js @@ -1,26 +1,26 @@ var Helper = require('../helper'); var definitions = require('../lib/definitions'); -function words(num){ - return Helper.shuffle(lorem); +exports.words = function(num){ + if( typeof num == 'undefined'){ var num = 3;} + return Helper.shuffle(definitions.lorem).slice(0, num); //Words.shuffle[0, num] -} +}; -function sentence(word_count){ - return 'sentences'; +exports.sentence = function(wordCount){ + if( typeof wordCount == 'undefined'){ var wordCount = 3;} + + return this.words(wordCount + Helper.randomNumber(7)).join(' ').capitalize(); //words(word_count + rand(6)).join(' ').capitalize + '.' -} - -function sentences(sentence_count){ - - return 'sentences'; - /* - returning([]) do |sentences| - 1.upto(sentence_count) do - sentences << sentence - end - */ - +}; + +exports.sentences = function(sentenceCount){ + if( typeof sentenceCount == 'undefined'){ var sentenceCount = 3;} + var sentences = ""; + for(sentenceCount; sentenceCount >= 0; sentenceCount--){ + sentences = sentences + this.sentence(); + } + return sentences; } function paragraph(sentence_count){ @@ -37,9 +37,8 @@ function paragraphs(paragraph_count){ */ } - -console.log(paragraph()); -console.log(paragraphs()); -console.log(sentence()); -console.log(sentences()); -console.log(words()); +String.prototype.capitalize = function(){ //v1.0 + return this.replace(/\w+/g, function(a){ + return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase(); + }); +}; |
