blob: c46516fcfba42407bda658616218bb89a2b657a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
<html>
<head>
<title>Faker.js - generate massive amounts of fake data in Node.js and the browser</title>
<script src = "js/jquery.js" type = "text/javascript"></script>
<script src = "js/prettyPrint.js" type = "text/javascript"></script>
<script src = "js/Faker.js" type = "text/javascript"></script>
<script>
if(typeof JSON == 'undefined'){
document.write('get a real browser that has JSON.stringify and JSON.parse built in <br/>');
// implement JSON.stringify serialization
var JSON = {};
JSON.stringify = function (obj) {
var t = typeof (obj);
if (t != "object" || obj === null) {
// simple data type
if (t == "string") obj = '"'+obj+'"';
return String(obj);
}
else {
// recurse array or object
var n, v, json = [], arr = (obj && obj.constructor == Array);
for (n in obj) {
v = obj[n]; t = typeof(v);
if (t == "string") v = '"'+v+'"';
else if (t == "object" && v !== null) v = JSON.stringify(v);
json.push((arr ? "" : '"' + n + '":') + String(v));
}
return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");
}
};
}
$(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++){
var card = Faker.Helpers.createCard();
cards.push(card);
}
$('#output').html('<textarea cols = "100" rows = "100">'+JSON.stringify(cards)+'</textarea>');
}, 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>
<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/>
<strong>protip</strong>: open your console on this page and run: <code>console.log(Faker); var randomName = Faker.Name.findName(); console.log(randomName);</code><hr/>
<div id = "output"></div>
</body>
</html>
|