faker 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jshintignore +3 -0
- package/.jshintrc +87 -0
- package/.npmignore +16 -0
- package/.travis.yml +5 -0
- package/BUILD/BUILD.js +139 -0
- package/BUILD/Mustache.js +296 -0
- package/BUILD/docs.js +62 -0
- package/BUILD/main.js +60 -0
- package/MIT-LICENSE.txt +20 -0
- package/Makefile +26 -0
- package/Readme.md +46 -0
- package/examples/bigDataSet.json +1 -0
- package/examples/browser_test.html +40 -0
- package/examples/dataSet.json +1 -0
- package/examples/index.html +77 -0
- package/examples/js/faker.js +730 -0
- package/examples/js/jquery.js +154 -0
- package/examples/js/prettyPrint.js +712 -0
- package/examples/library_test.js +9 -0
- package/examples/node_generateSet.js +20 -0
- package/examples/node_min_test.js +9 -0
- package/faker.js +730 -0
- package/index.js +31 -0
- package/lib/address.js +100 -0
- package/lib/company.js +36 -0
- package/lib/date.js +42 -0
- package/lib/definitions.js +1398 -0
- package/lib/helpers.js +124 -0
- package/lib/image.js +58 -0
- package/lib/internet.js +53 -0
- package/lib/lorem.js +45 -0
- package/lib/name.js +34 -0
- package/lib/phone_number.js +16 -0
- package/lib/random.js +106 -0
- package/lib/tree.js +69 -0
- package/lib/version.js +0 -0
- package/logo.png +0 -0
- package/minfaker.js +35 -0
- package/package.json +25 -0
- package/test/address.unit.js +293 -0
- package/test/all.functional.js +47 -0
- package/test/browser.unit.html +28 -0
- package/test/company.unit.js +110 -0
- package/test/date.unit.js +65 -0
- package/test/helpers.unit.js +62 -0
- package/test/image.unit.js +108 -0
- package/test/internet.unit.js +92 -0
- package/test/lorem.unit.js +178 -0
- package/test/mocha.opts +5 -0
- package/test/name.unit.js +87 -0
- package/test/phone_number.unit.js +29 -0
- package/test/run.js +68 -0
- package/test/support/chai.js +3403 -0
- package/test/support/sinon-1.5.2.js +4153 -0
- package/test/support/walk_dir.js +43 -0
- package/test/tree.unit.js +108 -0
@@ -0,0 +1,712 @@
|
|
1
|
+
/*
|
2
|
+
AUTHOR James Padolsey (http://james.padolsey.com)
|
3
|
+
VERSION 1.01
|
4
|
+
UPDATED 06-06-2009
|
5
|
+
*/
|
6
|
+
|
7
|
+
var prettyPrint = (function(){
|
8
|
+
|
9
|
+
/* These "util" functions are not part of the core
|
10
|
+
functionality but are all necessary - mostly DOM helpers */
|
11
|
+
|
12
|
+
var util = {
|
13
|
+
|
14
|
+
el: function(type, attrs) {
|
15
|
+
|
16
|
+
/* Create new element */
|
17
|
+
var el = document.createElement(type), attr;
|
18
|
+
|
19
|
+
/*Copy to single object */
|
20
|
+
attrs = util.merge({}, attrs);
|
21
|
+
|
22
|
+
/* Add attributes to el */
|
23
|
+
if (attrs && attrs.style) {
|
24
|
+
var styles = attrs.style;
|
25
|
+
for (var prop in styles) {
|
26
|
+
if (styles.hasOwnProperty(prop)) {
|
27
|
+
try{
|
28
|
+
/* Yes, IE6 SUCKS! */
|
29
|
+
el.style[prop] = styles[prop];
|
30
|
+
}catch(e){}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
delete attrs.style;
|
34
|
+
}
|
35
|
+
for (attr in attrs) {
|
36
|
+
if (attrs.hasOwnProperty(attr)) {
|
37
|
+
el[attr] = attrs[attr];
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
return el;
|
42
|
+
|
43
|
+
},
|
44
|
+
|
45
|
+
txt: function(t) {
|
46
|
+
/* Create text node */
|
47
|
+
return document.createTextNode(t);
|
48
|
+
},
|
49
|
+
|
50
|
+
row: function(cells, type, cellType) {
|
51
|
+
|
52
|
+
/* Creates new <tr> */
|
53
|
+
cellType = cellType || 'td';
|
54
|
+
|
55
|
+
/* colSpan is calculated by length of null items in array */
|
56
|
+
var colSpan = util.count(cells, null) + 1,
|
57
|
+
tr = util.el('tr'), td,
|
58
|
+
attrs = {
|
59
|
+
style: util.getStyles(cellType, type),
|
60
|
+
colSpan: colSpan
|
61
|
+
};
|
62
|
+
|
63
|
+
util.forEach(cells, function(cell){
|
64
|
+
|
65
|
+
if (cell === null) { return; }
|
66
|
+
/* Default cell type is <td> */
|
67
|
+
td = util.el(cellType, attrs);
|
68
|
+
|
69
|
+
if (cell.nodeType) {
|
70
|
+
/* IsDomElement */
|
71
|
+
td.appendChild(cell);
|
72
|
+
} else {
|
73
|
+
/* IsString */
|
74
|
+
td.innerHTML = util.shorten(cell.toString());
|
75
|
+
}
|
76
|
+
|
77
|
+
tr.appendChild(td);
|
78
|
+
});
|
79
|
+
|
80
|
+
return tr;
|
81
|
+
},
|
82
|
+
|
83
|
+
hRow: function(cells, type){
|
84
|
+
/* Return new <th> */
|
85
|
+
return util.row(cells, type, 'th');
|
86
|
+
},
|
87
|
+
|
88
|
+
table: function(headings, type){
|
89
|
+
|
90
|
+
headings = headings || [];
|
91
|
+
|
92
|
+
/* Creates new table: */
|
93
|
+
var attrs = {
|
94
|
+
thead: {
|
95
|
+
style:util.getStyles('thead',type)
|
96
|
+
},
|
97
|
+
tbody: {
|
98
|
+
style:util.getStyles('tbody',type)
|
99
|
+
},
|
100
|
+
table: {
|
101
|
+
style:util.getStyles('table',type)
|
102
|
+
}
|
103
|
+
},
|
104
|
+
tbl = util.el('table', attrs.table),
|
105
|
+
thead = util.el('thead', attrs.thead),
|
106
|
+
tbody = util.el('tbody', attrs.tbody);
|
107
|
+
|
108
|
+
if (headings.length) {
|
109
|
+
tbl.appendChild(thead);
|
110
|
+
thead.appendChild( util.hRow(headings, type) );
|
111
|
+
}
|
112
|
+
tbl.appendChild(tbody);
|
113
|
+
|
114
|
+
return {
|
115
|
+
/* Facade for dealing with table/tbody
|
116
|
+
Actual table node is this.node: */
|
117
|
+
node: tbl,
|
118
|
+
tbody: tbody,
|
119
|
+
thead: thead,
|
120
|
+
appendChild: function(node) {
|
121
|
+
this.tbody.appendChild(node);
|
122
|
+
},
|
123
|
+
addRow: function(cells, _type, cellType){
|
124
|
+
this.appendChild(util.row.call(util, cells, (_type || type), cellType));
|
125
|
+
return this;
|
126
|
+
}
|
127
|
+
};
|
128
|
+
},
|
129
|
+
|
130
|
+
shorten: function(str) {
|
131
|
+
var max = 40;
|
132
|
+
str = str.replace(/^\s\s*|\s\s*$|\n/g,'');
|
133
|
+
return str.length > max ? (str.substring(0, max-1) + '...') : str;
|
134
|
+
},
|
135
|
+
|
136
|
+
htmlentities: function(str) {
|
137
|
+
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
138
|
+
},
|
139
|
+
|
140
|
+
merge: function(target, source) {
|
141
|
+
|
142
|
+
/* Merges two (or more) objects,
|
143
|
+
giving the last one precedence */
|
144
|
+
|
145
|
+
if ( typeof target !== 'object' ) {
|
146
|
+
target = {};
|
147
|
+
}
|
148
|
+
|
149
|
+
for (var property in source) {
|
150
|
+
|
151
|
+
if ( source.hasOwnProperty(property) ) {
|
152
|
+
|
153
|
+
var sourceProperty = source[ property ];
|
154
|
+
|
155
|
+
if ( typeof sourceProperty === 'object' ) {
|
156
|
+
target[ property ] = util.merge( target[ property ], sourceProperty );
|
157
|
+
continue;
|
158
|
+
}
|
159
|
+
|
160
|
+
target[ property ] = sourceProperty;
|
161
|
+
|
162
|
+
}
|
163
|
+
|
164
|
+
}
|
165
|
+
|
166
|
+
for (var a = 2, l = arguments.length; a < l; a++) {
|
167
|
+
util.merge(target, arguments[a]);
|
168
|
+
}
|
169
|
+
|
170
|
+
return target;
|
171
|
+
},
|
172
|
+
|
173
|
+
count: function(arr, item) {
|
174
|
+
var count = 0;
|
175
|
+
for (var i = 0, l = arr.length; i< l; i++) {
|
176
|
+
if (arr[i] === item) {
|
177
|
+
count++;
|
178
|
+
}
|
179
|
+
}
|
180
|
+
return count;
|
181
|
+
},
|
182
|
+
|
183
|
+
thead: function(tbl) {
|
184
|
+
return tbl.getElementsByTagName('thead')[0];
|
185
|
+
},
|
186
|
+
|
187
|
+
forEach: function(arr, fn) {
|
188
|
+
|
189
|
+
/* Helper: iteration */
|
190
|
+
var len = arr.length, index = -1;
|
191
|
+
|
192
|
+
while (len > ++index) {
|
193
|
+
if(fn( arr[index], index, arr ) === false) {
|
194
|
+
break;
|
195
|
+
}
|
196
|
+
}
|
197
|
+
|
198
|
+
return true;
|
199
|
+
},
|
200
|
+
|
201
|
+
type: function(v){
|
202
|
+
try {
|
203
|
+
/* Returns type, e.g. "string", "number", "array" etc.
|
204
|
+
Note, this is only used for precise typing. */
|
205
|
+
if (v === null) { return 'null'; }
|
206
|
+
if (v === undefined) { return 'undefined'; }
|
207
|
+
var oType = Object.prototype.toString.call(v).match(/\s(.+?)\]/)[1].toLowerCase();
|
208
|
+
if (v.nodeType) {
|
209
|
+
if (v.nodeType === 1) {
|
210
|
+
return 'domelement';
|
211
|
+
}
|
212
|
+
return 'domnode';
|
213
|
+
}
|
214
|
+
if (/^(string|number|array|regexp|function|date|boolean)$/.test(oType)) {
|
215
|
+
return oType;
|
216
|
+
}
|
217
|
+
if (typeof v === 'object') {
|
218
|
+
return 'object';
|
219
|
+
}
|
220
|
+
if (v === window || v === document) {
|
221
|
+
return 'object';
|
222
|
+
}
|
223
|
+
return 'default';
|
224
|
+
} catch(e) {
|
225
|
+
return 'default';
|
226
|
+
}
|
227
|
+
},
|
228
|
+
|
229
|
+
within: function(ref) {
|
230
|
+
/* Check existence of a val within an object
|
231
|
+
RETURNS KEY */
|
232
|
+
return {
|
233
|
+
is: function(o) {
|
234
|
+
for (var i in ref) {
|
235
|
+
if (ref[i] === o) {
|
236
|
+
return i;
|
237
|
+
}
|
238
|
+
}
|
239
|
+
return '';
|
240
|
+
}
|
241
|
+
};
|
242
|
+
},
|
243
|
+
|
244
|
+
common: {
|
245
|
+
circRef: function(obj, key, settings) {
|
246
|
+
return util.expander(
|
247
|
+
'[POINTS BACK TO <strong>' + (key) + '</strong>]',
|
248
|
+
'Click to show this item anyway',
|
249
|
+
function() {
|
250
|
+
this.parentNode.appendChild( prettyPrintThis(obj,{maxDepth:1}) );
|
251
|
+
}
|
252
|
+
);
|
253
|
+
},
|
254
|
+
depthReached: function(obj, settings) {
|
255
|
+
return util.expander(
|
256
|
+
'[DEPTH REACHED]',
|
257
|
+
'Click to show this item anyway',
|
258
|
+
function() {
|
259
|
+
try {
|
260
|
+
this.parentNode.appendChild( prettyPrintThis(obj,{maxDepth:1}) );
|
261
|
+
} catch(e) {
|
262
|
+
this.parentNode.appendChild(
|
263
|
+
util.table(['ERROR OCCURED DURING OBJECT RETRIEVAL'],'error').addRow([e.message]).node
|
264
|
+
);
|
265
|
+
}
|
266
|
+
}
|
267
|
+
);
|
268
|
+
}
|
269
|
+
},
|
270
|
+
|
271
|
+
getStyles: function(el, type) {
|
272
|
+
type = prettyPrintThis.settings.styles[type] || {};
|
273
|
+
return util.merge(
|
274
|
+
{}, prettyPrintThis.settings.styles['default'][el], type[el]
|
275
|
+
);
|
276
|
+
},
|
277
|
+
|
278
|
+
expander: function(text, title, clickFn) {
|
279
|
+
return util.el('a', {
|
280
|
+
innerHTML: util.shorten(text) + ' <b style="visibility:hidden;">[+]</b>',
|
281
|
+
title: title,
|
282
|
+
onmouseover: function() {
|
283
|
+
this.getElementsByTagName('b')[0].style.visibility = 'visible';
|
284
|
+
},
|
285
|
+
onmouseout: function() {
|
286
|
+
this.getElementsByTagName('b')[0].style.visibility = 'hidden';
|
287
|
+
},
|
288
|
+
onclick: function() {
|
289
|
+
this.style.display = 'none';
|
290
|
+
clickFn.call(this);
|
291
|
+
return false;
|
292
|
+
},
|
293
|
+
style: {
|
294
|
+
cursor: 'pointer'
|
295
|
+
}
|
296
|
+
});
|
297
|
+
},
|
298
|
+
|
299
|
+
stringify: function(obj) {
|
300
|
+
|
301
|
+
/* Bit of an ugly duckling!
|
302
|
+
- This fn returns an ATTEMPT at converting an object/array/anyType
|
303
|
+
into a string, kinda like a JSON-deParser
|
304
|
+
- This is used for when |settings.expanded === false| */
|
305
|
+
|
306
|
+
var type = util.type(obj),
|
307
|
+
str, first = true;
|
308
|
+
if ( type === 'array' ) {
|
309
|
+
str = '[';
|
310
|
+
util.forEach(obj, function(item,i){
|
311
|
+
str += (i===0?'':', ') + util.stringify(item);
|
312
|
+
});
|
313
|
+
return str + ']';
|
314
|
+
}
|
315
|
+
if (typeof obj === 'object') {
|
316
|
+
str = '{';
|
317
|
+
for (var i in obj){
|
318
|
+
if (obj.hasOwnProperty(i)) {
|
319
|
+
str += (first?'':', ') + i + ':' + util.stringify(obj[i]);
|
320
|
+
first = false;
|
321
|
+
}
|
322
|
+
}
|
323
|
+
return str + '}';
|
324
|
+
}
|
325
|
+
if (type === 'regexp') {
|
326
|
+
return '/' + obj.source + '/';
|
327
|
+
}
|
328
|
+
if (type === 'string') {
|
329
|
+
return '"' + obj.replace(/"/g,'\\"') + '"';
|
330
|
+
}
|
331
|
+
return obj.toString();
|
332
|
+
},
|
333
|
+
|
334
|
+
headerGradient: (function(){
|
335
|
+
|
336
|
+
var canvas = document.createElement('canvas');
|
337
|
+
if (!canvas.getContext) { return ''; }
|
338
|
+
var cx = canvas.getContext('2d');
|
339
|
+
canvas.height = 30;
|
340
|
+
canvas.width = 1;
|
341
|
+
|
342
|
+
var linearGrad = cx.createLinearGradient(0,0,0,30);
|
343
|
+
linearGrad.addColorStop(0,'rgba(0,0,0,0)');
|
344
|
+
linearGrad.addColorStop(1,'rgba(0,0,0,0.25)');
|
345
|
+
|
346
|
+
cx.fillStyle = linearGrad;
|
347
|
+
cx.fillRect(0,0,1,30);
|
348
|
+
|
349
|
+
var dataURL = canvas.toDataURL && canvas.toDataURL();
|
350
|
+
return 'url(' + (dataURL || '') + ')';
|
351
|
+
|
352
|
+
})()
|
353
|
+
|
354
|
+
};
|
355
|
+
|
356
|
+
// Main..
|
357
|
+
var prettyPrintThis = function(obj, options) {
|
358
|
+
|
359
|
+
/*
|
360
|
+
* obj :: Object to be printed
|
361
|
+
* options :: Options (merged with config)
|
362
|
+
*/
|
363
|
+
|
364
|
+
options = options || {};
|
365
|
+
|
366
|
+
var settings = util.merge( {}, prettyPrintThis.config, options ),
|
367
|
+
container = util.el('div'),
|
368
|
+
config = prettyPrintThis.config,
|
369
|
+
currentDepth = 0,
|
370
|
+
stack = {},
|
371
|
+
hasRunOnce = false;
|
372
|
+
|
373
|
+
/* Expose per-call settings.
|
374
|
+
Note: "config" is overwritten (where necessary) by options/"settings"
|
375
|
+
So, if you need to access/change *DEFAULT* settings then go via ".config" */
|
376
|
+
prettyPrintThis.settings = settings;
|
377
|
+
|
378
|
+
var typeDealer = {
|
379
|
+
string : function(item){
|
380
|
+
return util.txt('"' + util.shorten(item.replace(/"/g,'\\"')) + '"');
|
381
|
+
},
|
382
|
+
number : function(item) {
|
383
|
+
return util.txt(item);
|
384
|
+
},
|
385
|
+
regexp : function(item) {
|
386
|
+
|
387
|
+
var miniTable = util.table(['RegExp',null], 'regexp');
|
388
|
+
var flags = util.table();
|
389
|
+
var span = util.expander(
|
390
|
+
'/' + item.source + '/',
|
391
|
+
'Click to show more',
|
392
|
+
function() {
|
393
|
+
this.parentNode.appendChild(miniTable.node);
|
394
|
+
}
|
395
|
+
);
|
396
|
+
|
397
|
+
flags
|
398
|
+
.addRow(['g', item.global])
|
399
|
+
.addRow(['i', item.ignoreCase])
|
400
|
+
.addRow(['m', item.multiline]);
|
401
|
+
|
402
|
+
miniTable
|
403
|
+
.addRow(['source', '/' + item.source + '/'])
|
404
|
+
.addRow(['flags', flags.node])
|
405
|
+
.addRow(['lastIndex', item.lastIndex]);
|
406
|
+
|
407
|
+
return settings.expanded ? miniTable.node : span;
|
408
|
+
},
|
409
|
+
domelement : function(element, depth) {
|
410
|
+
|
411
|
+
var miniTable = util.table(['DOMElement',null], 'domelement'),
|
412
|
+
props = ['id', 'className', 'innerHTML'];
|
413
|
+
|
414
|
+
miniTable.addRow(['tag', '<' + element.nodeName.toLowerCase() + '>']);
|
415
|
+
|
416
|
+
util.forEach(props, function(prop){
|
417
|
+
if ( element[prop] ) {
|
418
|
+
miniTable.addRow([ prop, util.htmlentities(element[prop]) ]);
|
419
|
+
}
|
420
|
+
});
|
421
|
+
|
422
|
+
return settings.expanded ? miniTable.node : util.expander(
|
423
|
+
'DOMElement (' + element.nodeName.toLowerCase() + ')',
|
424
|
+
'Click to show more',
|
425
|
+
function() {
|
426
|
+
this.parentNode.appendChild(miniTable.node);
|
427
|
+
}
|
428
|
+
);
|
429
|
+
},
|
430
|
+
domnode : function(node){
|
431
|
+
|
432
|
+
/* Deals with all DOMNodes that aren't elements (nodeType !== 1) */
|
433
|
+
var miniTable = util.table(['DOMNode',null], 'domelement'),
|
434
|
+
data = util.htmlentities( (node.data || 'UNDEFINED').replace(/\n/g,'\\n') );
|
435
|
+
miniTable
|
436
|
+
.addRow(['nodeType', node.nodeType + ' (' + node.nodeName + ')'])
|
437
|
+
.addRow(['data', data]);
|
438
|
+
|
439
|
+
return settings.expanded ? miniTable.node : util.expander(
|
440
|
+
'DOMNode',
|
441
|
+
'Click to show more',
|
442
|
+
function() {
|
443
|
+
this.parentNode.appendChild(miniTable.node);
|
444
|
+
}
|
445
|
+
);
|
446
|
+
},
|
447
|
+
object : function(obj, depth, key) {
|
448
|
+
|
449
|
+
/* Checking depth + circular refs */
|
450
|
+
/* Note, check for circular refs before depth; just makes more sense */
|
451
|
+
var stackKey = util.within(stack).is(obj);
|
452
|
+
if ( stackKey ) {
|
453
|
+
return util.common.circRef(obj, stackKey, settings);
|
454
|
+
}
|
455
|
+
stack[key||'TOP'] = obj;
|
456
|
+
if (depth === settings.maxDepth) {
|
457
|
+
return util.common.depthReached(obj, settings);
|
458
|
+
}
|
459
|
+
|
460
|
+
var table = util.table(['Object', null],'object'),
|
461
|
+
isEmpty = true;
|
462
|
+
|
463
|
+
for (var i in obj) {
|
464
|
+
if (!obj.hasOwnProperty || obj.hasOwnProperty(i)) {
|
465
|
+
var item = obj[i],
|
466
|
+
type = util.type(item);
|
467
|
+
isEmpty = false;
|
468
|
+
try {
|
469
|
+
table.addRow([i, typeDealer[ type ](item, depth+1, i)], type);
|
470
|
+
} catch(e) {
|
471
|
+
/* Security errors are thrown on certain Window/DOM properties */
|
472
|
+
if (window.console && window.console.log) {
|
473
|
+
console.log(e.message);
|
474
|
+
}
|
475
|
+
}
|
476
|
+
}
|
477
|
+
}
|
478
|
+
|
479
|
+
if (isEmpty) {
|
480
|
+
table.addRow(['<small>[empty]</small>']);
|
481
|
+
} else {
|
482
|
+
table.thead.appendChild(
|
483
|
+
util.hRow(['key','value'], 'colHeader')
|
484
|
+
);
|
485
|
+
}
|
486
|
+
|
487
|
+
var ret = (settings.expanded || hasRunOnce) ? table.node : util.expander(
|
488
|
+
util.stringify(obj),
|
489
|
+
'Click to show more',
|
490
|
+
function() {
|
491
|
+
this.parentNode.appendChild(table.node);
|
492
|
+
}
|
493
|
+
);
|
494
|
+
|
495
|
+
hasRunOnce = true;
|
496
|
+
|
497
|
+
return ret;
|
498
|
+
|
499
|
+
},
|
500
|
+
array : function(arr, depth, key) {
|
501
|
+
|
502
|
+
/* Checking depth + circular refs */
|
503
|
+
/* Note, check for circular refs before depth; just makes more sense */
|
504
|
+
var stackKey = util.within(stack).is(arr);
|
505
|
+
if ( stackKey ) {
|
506
|
+
return util.common.circRef(arr, stackKey);
|
507
|
+
}
|
508
|
+
stack[key||'TOP'] = arr;
|
509
|
+
if (depth === settings.maxDepth) {
|
510
|
+
return util.common.depthReached(arr);
|
511
|
+
}
|
512
|
+
|
513
|
+
/* Accepts a table and modifies it */
|
514
|
+
var table = util.table(['Array(' + arr.length + ')', null], 'array'),
|
515
|
+
isEmpty = true;
|
516
|
+
|
517
|
+
util.forEach(arr, function(item,i){
|
518
|
+
isEmpty = false;
|
519
|
+
table.addRow([i, typeDealer[ util.type(item) ](item, depth+1, i)]);
|
520
|
+
});
|
521
|
+
|
522
|
+
if (isEmpty) {
|
523
|
+
table.addRow(['<small>[empty]</small>']);
|
524
|
+
} else {
|
525
|
+
table.thead.appendChild( util.hRow(['index','value'], 'colHeader') );
|
526
|
+
}
|
527
|
+
|
528
|
+
return settings.expanded ? table.node : util.expander(
|
529
|
+
util.stringify(arr),
|
530
|
+
'Click to show more',
|
531
|
+
function() {
|
532
|
+
this.parentNode.appendChild(table.node);
|
533
|
+
}
|
534
|
+
);
|
535
|
+
|
536
|
+
},
|
537
|
+
'function' : function(fn, depth, key) {
|
538
|
+
|
539
|
+
/* Checking JUST circular refs */
|
540
|
+
var stackKey = util.within(stack).is(fn);
|
541
|
+
if ( stackKey ) { return util.common.circRef(fn, stackKey); }
|
542
|
+
stack[key||'TOP'] = fn;
|
543
|
+
|
544
|
+
var miniTable = util.table(['Function',null], 'function'),
|
545
|
+
span = util.el('span', {
|
546
|
+
innerHTML: 'function(){...} <b style="visibility:hidden;">[+]</b>',
|
547
|
+
onmouseover: function() {
|
548
|
+
this.getElementsByTagName('b')[0].style.visibility = 'visible';
|
549
|
+
},
|
550
|
+
onmouseout: function() {
|
551
|
+
this.getElementsByTagName('b')[0].style.visibility = 'hidden';
|
552
|
+
},
|
553
|
+
onclick: function() {
|
554
|
+
this.style.display = 'none';
|
555
|
+
this.parentNode.appendChild(miniTable.node);
|
556
|
+
},
|
557
|
+
style: {
|
558
|
+
cursor: 'pointer'
|
559
|
+
}
|
560
|
+
}),
|
561
|
+
argsTable = util.table(['Arguments']),
|
562
|
+
args = fn.toString().match(/\((.+?)\)/),
|
563
|
+
body = fn.toString().match(/\(.*?\)\s+?\{?([\S\s]+)/)[1].replace(/\}?$/,'');
|
564
|
+
|
565
|
+
miniTable
|
566
|
+
.addRow(['arguments', args ? args[1].replace(/[^\w_,\s]/g,'') : '<small>[none/native]</small>'])
|
567
|
+
.addRow(['body', body]);
|
568
|
+
|
569
|
+
return settings.expanded ? miniTable.node : span;
|
570
|
+
},
|
571
|
+
'date' : function(date) {
|
572
|
+
|
573
|
+
var miniTable = util.table(['Date',null], 'date');
|
574
|
+
var span = util.el('span', {
|
575
|
+
innerHTML: (+date) + ' <b style="visibility:hidden;">[+]</b>',
|
576
|
+
onmouseover: function() {
|
577
|
+
this.getElementsByTagName('b')[0].style.visibility = 'visible';
|
578
|
+
},
|
579
|
+
onmouseout: function() {
|
580
|
+
this.getElementsByTagName('b')[0].style.visibility = 'hidden';
|
581
|
+
},
|
582
|
+
onclick: function() {
|
583
|
+
this.style.display = 'none';
|
584
|
+
this.parentNode.appendChild(miniTable.node);
|
585
|
+
},
|
586
|
+
style: {
|
587
|
+
cursor: 'pointer'
|
588
|
+
}
|
589
|
+
});
|
590
|
+
|
591
|
+
date = date.toString().split(/\s/);
|
592
|
+
|
593
|
+
/* TODO: Make cross-browser functional */
|
594
|
+
miniTable
|
595
|
+
.addRow(['Time', date[4]])
|
596
|
+
.addRow(['Date', date.slice(0,4).join('-')]);
|
597
|
+
|
598
|
+
return settings.expanded ? miniTable.node : span;
|
599
|
+
|
600
|
+
},
|
601
|
+
'boolean' : function(bool) {
|
602
|
+
return util.txt( bool.toString().toUpperCase() );
|
603
|
+
},
|
604
|
+
'undefined' : function() {
|
605
|
+
return util.txt('UNDEFINED');
|
606
|
+
},
|
607
|
+
'null' : function() {
|
608
|
+
return util.txt('NULL');
|
609
|
+
},
|
610
|
+
'default' : function() {
|
611
|
+
/* When a type cannot be found */
|
612
|
+
return util.txt('prettyPrint: TypeNotFound Error');
|
613
|
+
}
|
614
|
+
};
|
615
|
+
|
616
|
+
container.appendChild( typeDealer[ (settings.forceObject) ? 'object' : util.type(obj) ](obj, currentDepth) );
|
617
|
+
|
618
|
+
return container;
|
619
|
+
|
620
|
+
};
|
621
|
+
|
622
|
+
/* Configuration */
|
623
|
+
|
624
|
+
/* All items can be overwridden by passing an
|
625
|
+
"options" object when calling prettyPrint */
|
626
|
+
prettyPrintThis.config = {
|
627
|
+
|
628
|
+
/* Try setting this to false to save space */
|
629
|
+
expanded: true,
|
630
|
+
|
631
|
+
forceObject: false,
|
632
|
+
maxDepth: 3,
|
633
|
+
styles: {
|
634
|
+
array: {
|
635
|
+
th: {
|
636
|
+
backgroundColor: '#6DBD2A',
|
637
|
+
color: 'white'
|
638
|
+
}
|
639
|
+
},
|
640
|
+
'function': {
|
641
|
+
th: {
|
642
|
+
backgroundColor: '#D82525'
|
643
|
+
}
|
644
|
+
},
|
645
|
+
regexp: {
|
646
|
+
th: {
|
647
|
+
backgroundColor: '#E2F3FB',
|
648
|
+
color: '#000'
|
649
|
+
}
|
650
|
+
},
|
651
|
+
object: {
|
652
|
+
th: {
|
653
|
+
backgroundColor: '#1F96CF'
|
654
|
+
}
|
655
|
+
},
|
656
|
+
error: {
|
657
|
+
th: {
|
658
|
+
backgroundColor: 'red',
|
659
|
+
color: 'yellow'
|
660
|
+
}
|
661
|
+
},
|
662
|
+
domelement: {
|
663
|
+
th: {
|
664
|
+
backgroundColor: '#F3801E'
|
665
|
+
}
|
666
|
+
},
|
667
|
+
date: {
|
668
|
+
th: {
|
669
|
+
backgroundColor: '#A725D8'
|
670
|
+
}
|
671
|
+
},
|
672
|
+
colHeader: {
|
673
|
+
th: {
|
674
|
+
backgroundColor: '#EEE',
|
675
|
+
color: '#000',
|
676
|
+
textTransform: 'uppercase'
|
677
|
+
}
|
678
|
+
},
|
679
|
+
'default': {
|
680
|
+
table: {
|
681
|
+
borderCollapse: 'collapse',
|
682
|
+
width: '100%'
|
683
|
+
},
|
684
|
+
td: {
|
685
|
+
padding: '5px',
|
686
|
+
fontSize: '12px',
|
687
|
+
backgroundColor: '#FFF',
|
688
|
+
color: '#222',
|
689
|
+
border: '1px solid #000',
|
690
|
+
verticalAlign: 'top',
|
691
|
+
fontFamily: '"Consolas","Lucida Console",Courier,mono',
|
692
|
+
whiteSpace: 'nowrap'
|
693
|
+
},
|
694
|
+
th: {
|
695
|
+
padding: '5px',
|
696
|
+
fontSize: '12px',
|
697
|
+
backgroundColor: '#222',
|
698
|
+
color: '#EEE',
|
699
|
+
textAlign: 'left',
|
700
|
+
border: '1px solid #000',
|
701
|
+
verticalAlign: 'top',
|
702
|
+
fontFamily: '"Consolas","Lucida Console",Courier,mono',
|
703
|
+
backgroundImage: util.headerGradient,
|
704
|
+
backgroundRepeat: 'repeat-x'
|
705
|
+
}
|
706
|
+
}
|
707
|
+
}
|
708
|
+
};
|
709
|
+
|
710
|
+
return prettyPrintThis;
|
711
|
+
|
712
|
+
})();
|