diff options
| author | Alexey Osipenko <[email protected]> | 2011-12-28 11:38:03 +0200 |
|---|---|---|
| committer | Alexey Osipenko <[email protected]> | 2011-12-28 11:38:03 +0200 |
| commit | 84ab59342f333bc33a992ec5ca37d8716295a536 (patch) | |
| tree | 9930ead4be40d782d766cac6b1409aa0d1a09668 /examples | |
| parent | 308683c3c29c8e72148d6ce88f1c50880864b57f (diff) | |
| download | faker-84ab59342f333bc33a992ec5ca37d8716295a536.tar.xz faker-84ab59342f333bc33a992ec5ca37d8716295a536.zip | |
Trailing spaces
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/index.html | 12 | ||||
| -rw-r--r-- | examples/js/Faker.js | 30 | ||||
| -rw-r--r-- | examples/js/prettyPrint.js | 216 |
3 files changed, 129 insertions, 129 deletions
diff --git a/examples/index.html b/examples/index.html index cd622a4f..c46516fc 100644 --- a/examples/index.html +++ b/examples/index.html @@ -34,17 +34,17 @@ } $(document).ready(function(e){ - + var card = Faker.Helpers.createCard(); $('#output').html(prettyPrint(card)); - + $('#generate').click(function(){ var card = Faker.Helpers.createCard(); $('#output').html(prettyPrint(card)); }); - + $('#generateSet').click(function(){ - + setTimeout(function(){ var cards = []; for(var i = 0; i < $('#cardCount').val(); i++){ @@ -55,14 +55,14 @@ }, 10); }); - + }); </script> </head> <body> <h1>Faker.js - generate massive amounts of fake data in Node.js and the browser</h1> - <a href="http://github.com/marak/Faker.js/"><img style="position:absolute; z-index:10; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png" alt="Fork me on GitHub" /></a> + <a href="http://github.com/marak/Faker.js/"><img style="position:absolute; z-index:10; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png" alt="Fork me on GitHub" /></a> <input id = "generate" type = "button" value = "generate one random card as HTML" /> <input id = "generateSet" type = "button" value = "generate an assosative array of random cards as JSON" /> card count : <input id = "cardCount" type = "text" size = "3" value = "5" /><br/><br/> diff --git a/examples/js/Faker.js b/examples/js/Faker.js index ea202e55..a2e2c7b8 100644 --- a/examples/js/Faker.js +++ b/examples/js/Faker.js @@ -19,20 +19,20 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************** AUTOGENERATED @ 1289092784548 *************** WARNING: THIS FILE WAS AUTOGENERATED BY THE FAKER BUILD SCRIPT - MODIFYING THIS FILE IS FINE, BUT YOU REALLY SHOULD BE MODIFYING + MODIFYING THIS FILE IS FINE, BUT YOU REALLY SHOULD BE MODIFYING THE LIBRARY DIRECTLY AND REGENERATING THIS FILE USING BUILD.js!!!! Faker.js - Written by Matthew Bergman and Marak Squires - + ## USAGE - - ### browser - + + ### browser - <script src = "Faker.js" type = "text/javascript"></script> <script> var randomName = Faker.Name.findName(); // Caitlyn Kerluke var randomEmail = Faker.Internet.email(); // [email protected] var randomCard = Faker.Helpers.createCard(); // random contact card containing many properties </script> - ### node.js - + ### node.js - var Faker = require('./Faker'); var randomName = Faker.Name.findName(); // Rowan Nikolaus var randomEmail = Faker.Internet.email(); // [email protected] @@ -151,9 +151,9 @@ Faker.Address.usState = function ( abbr ) { Faker.PhoneNumber = {}; Faker.PhoneNumber.phoneNumber = function (){ - + return Helpers.replaceSymbolWithNumber(Helpers.randomize(definitions.phone_formats())); - + }; Faker.PhoneNumber.phoneNumberFormat = function ( format ){ @@ -162,7 +162,7 @@ Faker.PhoneNumber.phoneNumberFormat = function ( format ){ Faker.Internet = {}; Faker.Internet.email = function () { - return this.userName() + "@" + this.domainName(); + return this.userName() + "@" + this.domainName(); }; Faker.Internet.userName = function () { @@ -264,12 +264,12 @@ Faker.Helpers.randomize = function (array) { }; Faker.Helpers.replaceSymbolWithNumber = function (string, symbol){ - - // default symbol is '#' + + // default symbol is '#' if(typeof symbol == 'undefined'){ var symbol = '#'; } - + var str = ''; for(var i = 0; i < string.length; i++){ if(string[i] == symbol){ @@ -282,13 +282,13 @@ Faker.Helpers.replaceSymbolWithNumber = function (string, symbol){ return str; }; -Faker.Helpers.shuffle = function (o){ +Faker.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; }; Faker.Helpers.generateDataSet = function (size){ - + }; Faker.Helpers.createCard = function (){ @@ -484,6 +484,6 @@ Faker.definitions.phone_formats = function (){return [ '1-###-###-#### x#####', '###.###.#### x#####' ];}; -var definitions = Faker.definitions; -var Helpers = Faker.Helpers; +var definitions = Faker.definitions; +var Helpers = Faker.Helpers; if(typeof exports != "undefined"){for(var prop in Faker){exports[prop] = Faker[prop];}}
\ No newline at end of file diff --git a/examples/js/prettyPrint.js b/examples/js/prettyPrint.js index 14235787..13f3ee45 100644 --- a/examples/js/prettyPrint.js +++ b/examples/js/prettyPrint.js @@ -5,20 +5,20 @@ */ var prettyPrint = (function(){ - + /* These "util" functions are not part of the core functionality but are all necessary - mostly DOM helpers */ - + var util = { - + el: function(type, attrs) { - + /* Create new element */ var el = document.createElement(type), attr; - + /*Copy to single object */ attrs = util.merge({}, attrs); - + /* Add attributes to el */ if (attrs && attrs.style) { var styles = attrs.style; @@ -37,21 +37,21 @@ var prettyPrint = (function(){ el[attr] = attrs[attr]; } } - + return el; - + }, - + txt: function(t) { /* Create text node */ return document.createTextNode(t); }, - + row: function(cells, type, cellType) { - + /* Creates new <tr> */ cellType = cellType || 'td'; - + /* colSpan is calculated by length of null items in array */ var colSpan = util.count(cells, null) + 1, tr = util.el('tr'), td, @@ -59,13 +59,13 @@ var prettyPrint = (function(){ style: util.getStyles(cellType, type), colSpan: colSpan }; - + util.forEach(cells, function(cell){ - + if (cell === null) { return; } /* Default cell type is <td> */ td = util.el(cellType, attrs); - + if (cell.nodeType) { /* IsDomElement */ td.appendChild(cell); @@ -73,22 +73,22 @@ var prettyPrint = (function(){ /* IsString */ td.innerHTML = util.shorten(cell.toString()); } - + tr.appendChild(td); }); - + return tr; }, - + hRow: function(cells, type){ /* Return new <th> */ return util.row(cells, type, 'th'); }, - + table: function(headings, type){ - + headings = headings || []; - + /* Creates new table: */ var attrs = { thead: { @@ -104,13 +104,13 @@ var prettyPrint = (function(){ tbl = util.el('table', attrs.table), thead = util.el('thead', attrs.thead), tbody = util.el('tbody', attrs.tbody); - + if (headings.length) { tbl.appendChild(thead); thead.appendChild( util.hRow(headings, type) ); } tbl.appendChild(tbody); - + return { /* Facade for dealing with table/tbody Actual table node is this.node: */ @@ -126,50 +126,50 @@ var prettyPrint = (function(){ } }; }, - + shorten: function(str) { var max = 40; str = str.replace(/^\s\s*|\s\s*$|\n/g,''); return str.length > max ? (str.substring(0, max-1) + '...') : str; }, - + htmlentities: function(str) { return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); }, - + merge: function(target, source) { - + /* Merges two (or more) objects, giving the last one precedence */ - + if ( typeof target !== 'object' ) { target = {}; } - + for (var property in source) { - + if ( source.hasOwnProperty(property) ) { - + var sourceProperty = source[ property ]; - + if ( typeof sourceProperty === 'object' ) { target[ property ] = util.merge( target[ property ], sourceProperty ); continue; } - + target[ property ] = sourceProperty; - + } - + } - + for (var a = 2, l = arguments.length; a < l; a++) { util.merge(target, arguments[a]); } - + return target; }, - + count: function(arr, item) { var count = 0; for (var i = 0, l = arr.length; i< l; i++) { @@ -179,25 +179,25 @@ var prettyPrint = (function(){ } return count; }, - + thead: function(tbl) { return tbl.getElementsByTagName('thead')[0]; }, - + forEach: function(arr, fn) { - + /* Helper: iteration */ var len = arr.length, index = -1; - + while (len > ++index) { if(fn( arr[index], index, arr ) === false) { break; } } - + return true; }, - + type: function(v){ try { /* Returns type, e.g. "string", "number", "array" etc. @@ -225,7 +225,7 @@ var prettyPrint = (function(){ return 'default'; } }, - + within: function(ref) { /* Check existence of a val within an object RETURNS KEY */ @@ -240,7 +240,7 @@ var prettyPrint = (function(){ } }; }, - + common: { circRef: function(obj, key, settings) { return util.expander( @@ -260,21 +260,21 @@ var prettyPrint = (function(){ this.parentNode.appendChild( prettyPrintThis(obj,{maxDepth:1}) ); } catch(e) { this.parentNode.appendChild( - util.table(['ERROR OCCURED DURING OBJECT RETRIEVAL'],'error').addRow([e.message]).node + util.table(['ERROR OCCURED DURING OBJECT RETRIEVAL'],'error').addRow([e.message]).node ); } } ); } }, - + getStyles: function(el, type) { type = prettyPrintThis.settings.styles[type] || {}; return util.merge( {}, prettyPrintThis.settings.styles['default'][el], type[el] ); }, - + expander: function(text, title, clickFn) { return util.el('a', { innerHTML: util.shorten(text) + ' <b style="visibility:hidden;">[+]</b>', @@ -295,14 +295,14 @@ var prettyPrint = (function(){ } }); }, - + stringify: function(obj) { - + /* Bit of an ugly duckling! - This fn returns an ATTEMPT at converting an object/array/anyType into a string, kinda like a JSON-deParser - This is used for when |settings.expanded === false| */ - + var type = util.type(obj), str, first = true; if ( type === 'array' ) { @@ -330,51 +330,51 @@ var prettyPrint = (function(){ } return obj.toString(); }, - + headerGradient: (function(){ - + var canvas = document.createElement('canvas'); if (!canvas.getContext) { return ''; } var cx = canvas.getContext('2d'); canvas.height = 30; canvas.width = 1; - + var linearGrad = cx.createLinearGradient(0,0,0,30); linearGrad.addColorStop(0,'rgba(0,0,0,0)'); linearGrad.addColorStop(1,'rgba(0,0,0,0.25)'); - + cx.fillStyle = linearGrad; cx.fillRect(0,0,1,30); - + var dataURL = canvas.toDataURL && canvas.toDataURL(); return 'url(' + (dataURL || '') + ')'; - + })() - + }; - + // Main.. var prettyPrintThis = function(obj, options) { - + /* - * obj :: Object to be printed + * obj :: Object to be printed * options :: Options (merged with config) */ - + options = options || {}; - + var settings = util.merge( {}, prettyPrintThis.config, options ), container = util.el('div'), config = prettyPrintThis.config, currentDepth = 0, stack = {}, hasRunOnce = false; - + /* Expose per-call settings. Note: "config" is overwritten (where necessary) by options/"settings" So, if you need to access/change *DEFAULT* settings then go via ".config" */ prettyPrintThis.settings = settings; - + var typeDealer = { string : function(item){ return util.txt('"' + util.shorten(item.replace(/"/g,'\\"')) + '"'); @@ -383,7 +383,7 @@ var prettyPrint = (function(){ return util.txt(item); }, regexp : function(item) { - + var miniTable = util.table(['RegExp',null], 'regexp'); var flags = util.table(); var span = util.expander( @@ -393,32 +393,32 @@ var prettyPrint = (function(){ this.parentNode.appendChild(miniTable.node); } ); - + flags .addRow(['g', item.global]) .addRow(['i', item.ignoreCase]) .addRow(['m', item.multiline]); - + miniTable .addRow(['source', '/' + item.source + '/']) .addRow(['flags', flags.node]) .addRow(['lastIndex', item.lastIndex]); - + return settings.expanded ? miniTable.node : span; }, domelement : function(element, depth) { - + var miniTable = util.table(['DOMElement',null], 'domelement'), props = ['id', 'className', 'innerHTML']; - + miniTable.addRow(['tag', '<' + element.nodeName.toLowerCase() + '>']); - + util.forEach(props, function(prop){ if ( element[prop] ) { miniTable.addRow([ prop, util.htmlentities(element[prop]) ]); } }); - + return settings.expanded ? miniTable.node : util.expander( 'DOMElement (' + element.nodeName.toLowerCase() + ')', 'Click to show more', @@ -428,14 +428,14 @@ var prettyPrint = (function(){ ); }, domnode : function(node){ - + /* Deals with all DOMNodes that aren't elements (nodeType !== 1) */ var miniTable = util.table(['DOMNode',null], 'domelement'), data = util.htmlentities( (node.data || 'UNDEFINED').replace(/\n/g,'\\n') ); miniTable .addRow(['nodeType', node.nodeType + ' (' + node.nodeName + ')']) .addRow(['data', data]); - + return settings.expanded ? miniTable.node : util.expander( 'DOMNode', 'Click to show more', @@ -445,7 +445,7 @@ var prettyPrint = (function(){ ); }, object : function(obj, depth, key) { - + /* Checking depth + circular refs */ /* Note, check for circular refs before depth; just makes more sense */ var stackKey = util.within(stack).is(obj); @@ -456,10 +456,10 @@ var prettyPrint = (function(){ if (depth === settings.maxDepth) { return util.common.depthReached(obj, settings); } - + var table = util.table(['Object', null],'object'), isEmpty = true; - + for (var i in obj) { if (!obj.hasOwnProperty || obj.hasOwnProperty(i)) { var item = obj[i], @@ -475,7 +475,7 @@ var prettyPrint = (function(){ } } } - + if (isEmpty) { table.addRow(['<small>[empty]</small>']); } else { @@ -483,7 +483,7 @@ var prettyPrint = (function(){ util.hRow(['key','value'], 'colHeader') ); } - + var ret = (settings.expanded || hasRunOnce) ? table.node : util.expander( util.stringify(obj), 'Click to show more', @@ -491,14 +491,14 @@ var prettyPrint = (function(){ this.parentNode.appendChild(table.node); } ); - + hasRunOnce = true; - + return ret; - + }, array : function(arr, depth, key) { - + /* Checking depth + circular refs */ /* Note, check for circular refs before depth; just makes more sense */ var stackKey = util.within(stack).is(arr); @@ -509,22 +509,22 @@ var prettyPrint = (function(){ if (depth === settings.maxDepth) { return util.common.depthReached(arr); } - + /* Accepts a table and modifies it */ var table = util.table(['Array(' + arr.length + ')', null], 'array'), isEmpty = true; - + util.forEach(arr, function(item,i){ isEmpty = false; table.addRow([i, typeDealer[ util.type(item) ](item, depth+1, i)]); }); - + if (isEmpty) { table.addRow(['<small>[empty]</small>']); } else { table.thead.appendChild( util.hRow(['index','value'], 'colHeader') ); } - + return settings.expanded ? table.node : util.expander( util.stringify(arr), 'Click to show more', @@ -532,15 +532,15 @@ var prettyPrint = (function(){ this.parentNode.appendChild(table.node); } ); - + }, 'function' : function(fn, depth, key) { - + /* Checking JUST circular refs */ var stackKey = util.within(stack).is(fn); if ( stackKey ) { return util.common.circRef(fn, stackKey); } stack[key||'TOP'] = fn; - + var miniTable = util.table(['Function',null], 'function'), span = util.el('span', { innerHTML: 'function(){...} <b style="visibility:hidden;">[+]</b>', @@ -561,15 +561,15 @@ var prettyPrint = (function(){ argsTable = util.table(['Arguments']), args = fn.toString().match(/\((.+?)\)/), body = fn.toString().match(/\(.*?\)\s+?\{?([\S\s]+)/)[1].replace(/\}?$/,''); - + miniTable .addRow(['arguments', args ? args[1].replace(/[^\w_,\s]/g,'') : '<small>[none/native]</small>']) .addRow(['body', body]); - + return settings.expanded ? miniTable.node : span; }, 'date' : function(date) { - + var miniTable = util.table(['Date',null], 'date'); var span = util.el('span', { innerHTML: (+date) + ' <b style="visibility:hidden;">[+]</b>', @@ -587,16 +587,16 @@ var prettyPrint = (function(){ cursor: 'pointer' } }); - + date = date.toString().split(/\s/); - + /* TODO: Make cross-browser functional */ miniTable .addRow(['Time', date[4]]) .addRow(['Date', date.slice(0,4).join('-')]); - + return settings.expanded ? miniTable.node : span; - + }, 'boolean' : function(bool) { return util.txt( bool.toString().toUpperCase() ); @@ -612,22 +612,22 @@ var prettyPrint = (function(){ return util.txt('prettyPrint: TypeNotFound Error'); } }; - + container.appendChild( typeDealer[ (settings.forceObject) ? 'object' : util.type(obj) ](obj, currentDepth) ); - + return container; - + }; - + /* Configuration */ - + /* All items can be overwridden by passing an "options" object when calling prettyPrint */ prettyPrintThis.config = { - + /* Try setting this to false to save space */ expanded: true, - + forceObject: false, maxDepth: 3, styles: { @@ -706,7 +706,7 @@ var prettyPrint = (function(){ } } }; - + return prettyPrintThis; - + })();
\ No newline at end of file |
