From e9d866ca2c92dcbc1129c83970cf73a0ab401831 Mon Sep 17 00:00:00 2001 From: Jay Liu Date: Tue, 5 Nov 2013 17:06:36 -0700 Subject: Update build with (working) Tree module --- Faker.js | 85 +++++++++++++++++++++++++++++----------------------- MinFaker.js | 30 +++++++++---------- Readme.md | 2 +- examples/js/Faker.js | 85 +++++++++++++++++++++++++++++----------------------- 4 files changed, 112 insertions(+), 90 deletions(-) diff --git a/Faker.js b/Faker.js index 0691990a..1df2b6a8 100644 --- a/Faker.js +++ b/Faker.js @@ -17,7 +17,7 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************** AUTOGENERATED @ 1383662792637 *************** +/*************** AUTOGENERATED @ 1383696373283 *************** WARNING: THIS FILE WAS AUTOGENERATED BY THE FAKER BUILD SCRIPT MODIFYING THIS FILE IS FINE, BUT YOU REALLY SHOULD BE MODIFYING THE LIBRARY DIRECTLY AND REGENERATING THIS FILE USING BUILD.js!!!! @@ -392,51 +392,62 @@ Faker.Helpers.userCard = function () { }; Faker.Tree = {}; -Faker.Tree.createTree = function (depth, width, obj) { +Faker.Tree.clone = function clone(obj) { + if (obj == null || typeof(obj) != 'object') + return obj; - if (!obj) { - throw { - name: "ObjectError", - message: "there needs to be an object passed in", - toString: function () { - return this.name + ": " + this.message - } - }; - } + var temp = obj.constructor(); // changed - if (width <= 0) { - throw { - name: "TreeParamError", - message: "width must be greater than zero", - toString: function () { - return this.name + ": " + this.message - } - }; - } + for (var key in obj) { + temp[key] = this.clone(obj[key]); + } + return temp; + }; - var newObj = clone(obj); +Faker.Tree.createTree = function (depth, width, obj) { + if (!obj) { + throw { + name: "ObjectError", + message: "there needs to be an object passed in", + toString: function () { + return this.name + ": " + this.message + } + }; + } - for (var prop in newObj) { - if (newObj.hasOwnProperty(prop)) { - var value = null; - if (newObj[prop] !== "__RECURSE__") { - value = eval(newObj[prop]); - } - else { - if (depth !== 0) { - value = []; - for (var i = 0; i < width; i++) { - value.push(createTree(depth - 1, width, obj)); + if (width <= 0) { + throw { + name: "TreeParamError", + message: "width must be greater than zero", + toString: function () { + return this.name + ": " + this.message + } + }; + } + + var newObj = this.clone(obj); + + for (var prop in newObj) { + if (newObj.hasOwnProperty(prop)) { + var value = null; + if (newObj[prop] !== "__RECURSE__") { + value = eval(newObj[prop]); + } + else { + if (depth !== 0) { + value = []; + for (var i = 0; i < width; i++) { + value.push(this.createTree(depth - 1, width, obj)); + } } } - } - newObj[prop] = value; + newObj[prop] = value; + } } - } - return newObj; -}; + return newObj; + }; Faker.random = {}; Faker.random.number = function (range) { diff --git a/MinFaker.js b/MinFaker.js index 57e65cd9..10c1f571 100644 --- a/MinFaker.js +++ b/MinFaker.js @@ -1,20 +1,20 @@ !function(){var a={version:"0.5.5",Name:{}};a.Name.firstName=function(){return a.random.first_name()};a.Name.lastName=function(){return a.random.last_name()};a.Name.findName=function(){switch(a.random.number(8)){case 0:return a.random.name_prefix()+" "+this.firstName()+" "+this.lastName();case 1:return this.firstName()+" "+this.lastName()+" "+a.random.name_suffix()}return this.firstName()+" "+this.lastName()};a.Address={};a.Address.zipCode=function(){return f.replaceSymbolWithNumber(a.random.array_element(["#####", -"#####-####"]))};a.Address.zipCodeFormat=function(a){return f.replaceSymbolWithNumber(["#####","#####-####"][a])};a.Address.city=function(){var b;switch(a.random.number(4)){case 0:b=a.random.city_prefix()+" "+a.random.first_name()+a.random.city_suffix();break;case 1:b=a.random.city_prefix()+" "+a.random.first_name();break;case 2:b=a.random.first_name()+a.random.city_suffix();break;case 3:b=a.random.last_name()+a.random.city_suffix()}return b};a.Address.streetName=function(){var b;switch(a.random.number(2)){case 0:b= -a.random.last_name()+" "+a.random.street_suffix();break;case 1:b=a.random.first_name()+" "+a.random.street_suffix()}return b};a.Address.streetAddress=function(b){void 0===b&&(b=!1);var d="";switch(a.random.number(3)){case 0:d=f.replaceSymbolWithNumber("#####")+" "+this.streetName();break;case 1:d=f.replaceSymbolWithNumber("####")+" "+this.streetName();break;case 2:d=f.replaceSymbolWithNumber("###")+" "+this.streetName()}return b?d+" "+this.secondaryAddress():d};a.Address.secondaryAddress=function(){return f.replaceSymbolWithNumber(a.random.array_element(["Apt. ###", -"Suite ###"]))};a.Address.brState=function(b){return b?a.random.br_state_abbr():a.random.br_state()};a.Address.ukCounty=function(){return a.random.uk_county()};a.Address.ukCountry=function(){return a.random.uk_country()};a.Address.usState=function(b){return b?a.random.us_state_abbr():a.random.us_state()};a.Address.latitude=function(){return(a.random.number(18E5)/1E4-90).toFixed(4)};a.Address.longitude=function(){return(a.random.number(36E5)/1E4-180).toFixed(4)};a.PhoneNumber={};a.PhoneNumber.phoneNumber= -function(){return f.replaceSymbolWithNumber(a.random.phone_formats())};a.PhoneNumber.phoneNumberFormat=function(a){return f.replaceSymbolWithNumber(c.phone_formats[a])};a.Internet={};a.Internet.email=function(){return a.Helpers.slugify(this.userName())+"@"+a.Helpers.slugify(this.domainName())};a.Internet.userName=function(){var b;switch(a.random.number(2)){case 0:b=a.random.first_name();break;case 1:b=a.random.first_name()+a.random.array_element([".","_"])+a.random.last_name()}return b};a.Internet.domainName= -function(){return this.domainWord()+"."+a.random.domain_suffix()};a.Internet.domainWord=function(){return a.random.first_name().toLowerCase()};a.Internet.ip=function(){for(var a=[],d=0;4>d;d++)a[d]=(254*Math.random()+1).toFixed(0);return a.join(".")};a.Internet.color=function(b,d,c){d=Math.floor((a.random.number(256)+b)/2);c=Math.floor((a.random.number(256)+b)/2);b=Math.floor((a.random.number(256)+b)/2);return"#"+d.toString(16)+c.toString(16)+b.toString(16)};a.Company={};a.Company.suffixes=function(){return["Inc", -"and Sons","LLC","Group","and Daughters"]};a.Company.companyName=function(b){switch(b?b:a.random.number(3)){case 0:return a.Name.lastName()+" "+this.companySuffix();case 1:return a.Name.lastName()+"-"+a.Name.lastName();case 2:return a.Name.lastName()+", "+a.Name.lastName()+" and "+a.Name.lastName()}};a.Company.companySuffix=function(){return a.random.array_element(this.suffixes())};a.Company.catchPhrase=function(){return a.random.catch_phrase_adjective()+" "+a.random.catch_phrase_descriptor()+" "+ -a.random.catch_phrase_noun()};a.Company.bs=function(){return a.random.bs_adjective()+" "+a.random.bs_buzz()+" "+a.random.bs_noun()};a.Lorem={};a.Lorem.words=function(a){"undefined"==typeof a&&(a=3);return f.shuffle(c.lorem).slice(0,a)};a.Lorem.sentence=function(b,d){"undefined"==typeof b&&(b=3);return this.words(b+a.random.number(7)).join(" ")};a.Lorem.sentences=function(a){"undefined"==typeof a&&(a=3);var d=[];for(a;0d;d++)a[d]=(254*Math.random()+1).toFixed(0);return a.join(".")};a.Internet.color=function(c,d,b){d=Math.floor((a.random.number(256)+c)/2);b=Math.floor((a.random.number(256)+c)/2);c=Math.floor((a.random.number(256)+c)/2);return"#"+d.toString(16)+b.toString(16)+c.toString(16)};a.Company={};a.Company.suffixes=function(){return["Inc", +"and Sons","LLC","Group","and Daughters"]};a.Company.companyName=function(c){switch(c?c:a.random.number(3)){case 0:return a.Name.lastName()+" "+this.companySuffix();case 1:return a.Name.lastName()+"-"+a.Name.lastName();case 2:return a.Name.lastName()+", "+a.Name.lastName()+" and "+a.Name.lastName()}};a.Company.companySuffix=function(){return a.random.array_element(this.suffixes())};a.Company.catchPhrase=function(){return a.random.catch_phrase_adjective()+" "+a.random.catch_phrase_descriptor()+" "+ +a.random.catch_phrase_noun()};a.Company.bs=function(){return a.random.bs_adjective()+" "+a.random.bs_buzz()+" "+a.random.bs_noun()};a.Lorem={};a.Lorem.words=function(a){"undefined"==typeof a&&(a=3);return f.shuffle(b.lorem).slice(0,a)};a.Lorem.sentence=function(c,d){"undefined"==typeof c&&(c=3);return this.words(c+a.random.number(7)).join(" ")};a.Lorem.sentences=function(a){"undefined"==typeof a&&(a=3);var d=[];for(a;0=c)throw{name:"TreeParamError",message:"width must be greater than zero",toString:function(){return this.name+": "+this.message}};var e=clone(f),g;for(g in e)if(e.hasOwnProperty(g)){var h=null;if("__RECURSE__"!==e[g])h=eval(e[g]);else if(0!==a)for(var h=[],k= -0;k=b)throw{name:"TreeParamError",message:"width must be greater than zero",toString:function(){return this.name+": "+this.message}}; +var e=this.clone(f),g;for(g in e)if(e.hasOwnProperty(g)){var h=null;if("__RECURSE__"!==e[g])h=eval(e[g]);else if(0!==a)for(var h=[],k=0;k
  • Name
    • firstName
    • lastName
    • findName
  • Address
    • zipCode
    • zipCodeFormat
    • city
    • streetName
    • streetAddress
    • secondaryAddress
    • brState
    • ukCounty
    • ukCountry
    • usState
    • latitude
    • longitude
  • PhoneNumber
    • phoneNumber
    • phoneNumberFormat
  • Internet
    • email
    • userName
    • domainName
    • domainWord
    • ip
    • color
  • Company
    • suffixes
    • companyName
    • companySuffix
    • catchPhrase
    • bs
  • Lorem
    • words
    • sentence
    • sentences
    • paragraph
    • paragraphs
  • Helpers
    • randomNumber
    • randomize
    • slugify
    • replaceSymbolWithNumber
    • shuffle
    • createCard
    • userCard
  • Tree
    • createTree
  • random
    • number
    • array_element
    • city_prefix
    • city_suffix
    • street_suffix
    • br_state
    • br_state_abbr
    • us_state
    • us_state_abbr
    • uk_county
    • uk_country
    • first_name
    • last_name
    • name_prefix
    • name_suffix
    • catch_phrase_adjective
    • catch_phrase_descriptor
    • catch_phrase_noun
    • bs_adjective
    • bs_buzz
    • bs_noun
    • phone_formats
    • domain_suffix
  • definitions
    • first_name
    • last_name
    • name_prefix
    • name_suffix
    • br_state
    • br_state_abbr
    • us_state
    • us_state_abbr
    • city_prefix
    • city_suffix
    • street_suffix
    • uk_county
    • uk_country
    • catch_phrase_adjective
    • catch_phrase_descriptor
    • catch_phrase_noun
    • bs_adjective
    • bs_buzz
    • bs_noun
    • domain_suffix
    • lorem
    • phone_formats
  • +
    • Name
      • firstName
      • lastName
      • findName
    • Address
      • zipCode
      • zipCodeFormat
      • city
      • streetName
      • streetAddress
      • secondaryAddress
      • brState
      • ukCounty
      • ukCountry
      • usState
      • latitude
      • longitude
    • PhoneNumber
      • phoneNumber
      • phoneNumberFormat
    • Internet
      • email
      • userName
      • domainName
      • domainWord
      • ip
      • color
    • Company
      • suffixes
      • companyName
      • companySuffix
      • catchPhrase
      • bs
    • Lorem
      • words
      • sentence
      • sentences
      • paragraph
      • paragraphs
    • Helpers
      • randomNumber
      • randomize
      • slugify
      • replaceSymbolWithNumber
      • shuffle
      • createCard
      • userCard
    • Tree
      • clone
      • createTree
    • random
      • number
      • array_element
      • city_prefix
      • city_suffix
      • street_suffix
      • br_state
      • br_state_abbr
      • us_state
      • us_state_abbr
      • uk_county
      • uk_country
      • first_name
      • last_name
      • name_prefix
      • name_suffix
      • catch_phrase_adjective
      • catch_phrase_descriptor
      • catch_phrase_noun
      • bs_adjective
      • bs_buzz
      • bs_noun
      • phone_formats
      • domain_suffix
    • definitions
      • first_name
      • last_name
      • name_prefix
      • name_suffix
      • br_state
      • br_state_abbr
      • us_state
      • us_state_abbr
      • city_prefix
      • city_suffix
      • street_suffix
      • uk_county
      • uk_country
      • catch_phrase_adjective
      • catch_phrase_descriptor
      • catch_phrase_noun
      • bs_adjective
      • bs_buzz
      • bs_noun
      • domain_suffix
      • lorem
      • phone_formats
    ## Tests npm install . make test diff --git a/examples/js/Faker.js b/examples/js/Faker.js index 0691990a..1df2b6a8 100644 --- a/examples/js/Faker.js +++ b/examples/js/Faker.js @@ -17,7 +17,7 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************** AUTOGENERATED @ 1383662792637 *************** +/*************** AUTOGENERATED @ 1383696373283 *************** WARNING: THIS FILE WAS AUTOGENERATED BY THE FAKER BUILD SCRIPT MODIFYING THIS FILE IS FINE, BUT YOU REALLY SHOULD BE MODIFYING THE LIBRARY DIRECTLY AND REGENERATING THIS FILE USING BUILD.js!!!! @@ -392,51 +392,62 @@ Faker.Helpers.userCard = function () { }; Faker.Tree = {}; -Faker.Tree.createTree = function (depth, width, obj) { +Faker.Tree.clone = function clone(obj) { + if (obj == null || typeof(obj) != 'object') + return obj; - if (!obj) { - throw { - name: "ObjectError", - message: "there needs to be an object passed in", - toString: function () { - return this.name + ": " + this.message - } - }; - } + var temp = obj.constructor(); // changed - if (width <= 0) { - throw { - name: "TreeParamError", - message: "width must be greater than zero", - toString: function () { - return this.name + ": " + this.message - } - }; - } + for (var key in obj) { + temp[key] = this.clone(obj[key]); + } + return temp; + }; - var newObj = clone(obj); +Faker.Tree.createTree = function (depth, width, obj) { + if (!obj) { + throw { + name: "ObjectError", + message: "there needs to be an object passed in", + toString: function () { + return this.name + ": " + this.message + } + }; + } - for (var prop in newObj) { - if (newObj.hasOwnProperty(prop)) { - var value = null; - if (newObj[prop] !== "__RECURSE__") { - value = eval(newObj[prop]); - } - else { - if (depth !== 0) { - value = []; - for (var i = 0; i < width; i++) { - value.push(createTree(depth - 1, width, obj)); + if (width <= 0) { + throw { + name: "TreeParamError", + message: "width must be greater than zero", + toString: function () { + return this.name + ": " + this.message + } + }; + } + + var newObj = this.clone(obj); + + for (var prop in newObj) { + if (newObj.hasOwnProperty(prop)) { + var value = null; + if (newObj[prop] !== "__RECURSE__") { + value = eval(newObj[prop]); + } + else { + if (depth !== 0) { + value = []; + for (var i = 0; i < width; i++) { + value.push(this.createTree(depth - 1, width, obj)); + } } } - } - newObj[prop] = value; + newObj[prop] = value; + } } - } - return newObj; -}; + return newObj; + }; Faker.random = {}; Faker.random.number = function (range) { -- cgit v1.2.3