-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
67 lines (55 loc) · 1.63 KB
/
index.js
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
// Data mocking (auto lorem ipsum)
// ===========================
var Faker = require('Faker');
var _ = require('underscore');
module.exports = function(rawSON) {
var finalObject = {}; // Result array
var data = ""; // Final JSON
var object;
var buildingElement = {}; // JSON of unit data
var i, j; // temporary variables
// Data randomized population
createData = function(params) {
return Faker[params[0]][params[1]](params[2]);
};
// Create the necessary number of events
var findTheLeaves = function(list) {
var tmp = {};
var tmpArray = [];
_.each(list,
function(obj, index, list) {
if(obj.type === "array") {
// Create object/array
_(obj.cycles).times(function() {
tmpArray.push(findTheLeaves(list[index].items));
tmp[index] = tmpArray;
});
}
else if(obj.type === "object") {
if(!index) {
tmp = findTheLeaves(list[index].properties);
return tmp;
}
else {
tmp[index] = findTheLeaves(list[index].properties);
return tmp;
}
}
else {
if(list[index].fixture) {
var dataArgs = list[index].fixture.type.split('.');
dataArgs.push(list[index].fixture.params);
tmp[index] = createData(dataArgs).toString();
} else {
console.log("ERROR, there is a problem with the definition of your fixture");
}
return tmp;
}
}
);
buildingElement = tmp;
tmp = {};
return buildingElement;
};
return findTheLeaves(rawSON.properties);
};