-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerator.js
More file actions
89 lines (75 loc) · 2.03 KB
/
generator.js
File metadata and controls
89 lines (75 loc) · 2.03 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
/*jslint node:true*/
/**
* Generate single file exports from the database (using a static manifest)
*/
const fs = require('fs'),
walk = require('fs-walk'),
links = {
5: 0x001,
6: 0x002,
7: 0x004,
4: 0x008,
5: 0x020,
0: 0x040,
1: 0x080,
2: 0x100,
}
function mapDef(card) {
if (typeof card.def === 'string' && card.links) {
return card.links.map(function(link) {
return links[link]
}).reduce(function(a, b) { return a + b });
} else {
return card.def || 0;
}
}
function splitJSON() {
var full = require('./manifest_0-en-OCGTCG.json');
full.forEach(function(card) {
var data = JSON.stringify(card, null, 4),
id = './json/' + card.id.toString() + '.json';
fs.writeFileSync(id, data);
});
}
function mysql_real_escape_string(str) {
'use strict';
return str.replace(/[\0\x08\x09\x1a"\\\%]/g, function(char) {
switch (char) {
case "\0":
return "\\0";
case "\x08":
return "\\b";
case "\x09":
return "\\t";
case "\x1a":
return "\\z";
case "\n":
return "\\n";
case "\r":
return "\\r";
case "\"":
return '""';
case "\\":
case "%":
return "\\" + char; // prepends a backslash to backslash, percent,
// and double/single quotes
}
});
}
function getDB(response, callback) {
var db = [];
walk.filesSync('./http/json/', function(basedir, filename, stat, next) {
var data = fs.readFileSync(basedir + filename);
try {
db.push(JSON.parse(data));
} catch (error) {
response.write('Can not Parsed! ' + basedir + filename);
console.log('ERROR!', basedir + filename)
}
});
callback(null, db);
}
module.exports = {
getDB: getDB,
splitJSON: splitJSON
};