Skip to content

Commit 40664c6

Browse files
committed
Initial commit
0 parents  commit 40664c6

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
JSON schema data processor with FakerJS

index.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Data mocking (auto lorem ipsum)
2+
// ===========================
3+
4+
var Faker = require('Faker');
5+
var _ = require('underscore');
6+
7+
module.exports = function(rawSON) {
8+
var finalObject = {}; // Result array
9+
var data = ""; // Final JSON
10+
var object;
11+
var buildingElement = {}; // JSON of unit data
12+
var i, j; // temporary variables
13+
14+
// Data randomized population
15+
createData = function(params) {
16+
return Faker[params[0]][params[1]](params[2]);
17+
};
18+
19+
// Create the necessary number of events
20+
var findTheLeaves = function(list) {
21+
22+
var tmp = {};
23+
var tmpArray = [];
24+
25+
_.each(list,
26+
27+
function(obj, index, list) {
28+
29+
if(obj.type === "array") {
30+
// Create object/array
31+
_(obj.cycles).times(function() {
32+
tmpArray.push(findTheLeaves(list[index].items));
33+
tmp[index] = tmpArray;
34+
});
35+
}
36+
else if(obj.type === "object") {
37+
if(!index) {
38+
tmp = findTheLeaves(list[index].properties);
39+
return tmp;
40+
}
41+
else {
42+
tmp[index] = findTheLeaves(list[index].properties);
43+
return tmp;
44+
}
45+
}
46+
else {
47+
if(list[index].fixture) {
48+
var dataArgs = list[index].fixture.type.split('.');
49+
dataArgs.push(list[index].fixture.params);
50+
tmp[index] = createData(dataArgs);
51+
} else {
52+
console.log("ERROR, there is a problem with the definition of your fixture");
53+
}
54+
55+
return tmp;
56+
}
57+
}
58+
);
59+
60+
buildingElement = tmp;
61+
tmp = {};
62+
63+
return buildingElement;
64+
};
65+
66+
return findTheLeaves(rawSON.properties);
67+
};

package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "json-schema-processor",
3+
"description": "Mocking for the Limbo POC",
4+
"version": "0.0.5",
5+
"repository": {
6+
"type": "git",
7+
"url": "git://github.com/jaredhanson/locomotive.git"
8+
},
9+
"keywords": [
10+
"json-schema",
11+
"data-processor",
12+
"faker"
13+
],
14+
"dependencies": {
15+
"Faker": "~0.5.11",
16+
"underscore": "~1.5.1"
17+
},
18+
"main": "index",
19+
"scripts": {
20+
"prepublish": "npm prune"
21+
}
22+
}

0 commit comments

Comments
 (0)