在公司裡有時後會遇到api架構已經訂完了,但api卻尚未完成的情況
可能就需要自己去產生一些假資料
起初為了產生一堆假資料,搞得好麻煩,超級懶惰的我,每次處理需要假資料來測試時,就進度超慢的
後來我發現了這個網站!!!
[
'{{repeat(5, 7)}}',
{
_id: '{{objectId()}}',
index: '{{index()}}',
guid: '{{guid()}}',
isActive: '{{bool()}}',
balance: '{{floating(1000, 4000, 2, "$0,0.00")}}',
picture: 'http://placehold.it/32x32',
age: '{{integer(20, 40)}}',
eyeColor: '{{random("blue", "brown", "green")}}',
name: '{{firstName()}} {{surname()}}',
gender: '{{gender()}}',
company: '{{company().toUpperCase()}}',
email: '{{email()}}',
phone: '+1 {{phone()}}',
address: '{{integer(100, 999)}} {{street()}}, {{city()}}, {{state()}}, {{integer(100, 10000)}}',
about: '{{lorem(1, "paragraphs")}}',
registered: '{{date(new Date(2014, 0, 1), new Date(), "YYYY-MM-ddThh:mm:ss Z")}}',
latitude: '{{floating(-90.000001, 90)}}',
longitude: '{{floating(-180.000001, 180)}}',
tags: [
'{{repeat(7)}}',
'{{lorem(1, "words")}}'
],
friends: [
'{{repeat(3)}}',
{
id: '{{index()}}',
name: '{{firstName()}} {{surname()}}'
}
],
greeting: function (tags) {
return 'Hello, ' + this.name + '! You have ' + tags.integer(1, 10) + ' unread messages.';
},
favoriteFruit: function (tags) {
var fruits = ['apple', 'banana', 'strawberry'];
return fruits[tags.integer(0, fruits.length - 1)];
}
}
]
上面這段是網站裡的範例
以下兩段是我當初產生假資料的範例
//session
[
'{{repeat(150, 200)}}',
{
type: '{{random("0", "0", "1","2")}}',
sessionID: '{{index()}}',
name:function (tags) {
return 'seaaion ' + tags.integer(1, 100);
},
trackID:function (tags) {
var test = tags.integer(1, 3);
if (test == 1){
return '|' + tags.integer(0, 10) + '|';
}else if(test == 2){
return '|' + tags.integer(0, 5) + '|' + tags.integer(6, 10) + '|';
}
return '|' + tags.integer(0, 2) + '|' + tags.integer(3, 5) + '|'+ tags.integer(6, 10) + '|';
},
startDate:'{{random("2015-01-05", "2015-01-06", "2015-01-07","2015-01-08")}}',
endDate:'{{random("2015-01-05", "2015-01-06", "2015-01-07","2015-01-08")}}',
startTime:'{{date(new Date(2014, 0, 1), new Date(), "hh:mm:ss ")}}',
endTime:'{{date(new Date(2014, 0, 1), new Date(), "hh:mm:ss ")}}',
note:'備註',
roomID:function (tags) {
var test = tags.integer(1, 3);
if (test == 1){
return '|' + tags.integer(0, 50) + '|';
}else if(test == 2){
return '|' + tags.integer(0, 25) + '|' + tags.integer(25, 50) + '|';
}
return '|' + tags.integer(1, 10) + '|' + tags.integer(11, 30) + '|'+ tags.integer(31, 50) + '|';
},
chairman:['{{repeat(1, 3)}}',
{
name:'{{firstName()}} {{surname()}}',
email:'{{email()}}',
affiliation:'{{company().toUpperCase()}}'
}
]
}
]
//Room
[
'{{repeat(0, 50)}}',
{
roomID: '{{index()}}',
roomName:'{{random("E", "Q", "V","L","B","SG")}}'+'{{integer(0, 9)}}'+'{{integer(0, 9)}}'+'{{integer(0, 9)}}',
locationX:50,
locationY:50,
locationWidth:100,
locationHeight:100
}
]
把這記錄下來,以後如果我要產生假資料的時候就可以來這取用了!!
如果產生jason後可以再利用這個網站把空格換行給取代掉,在這網頁要閱讀裡面內容也會比較方便,我自己覺得啦XD
沒有留言:
張貼留言