This repository has been archived by the owner on Oct 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stringify.js
52 lines (49 loc) · 1.54 KB
/
stringify.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
// Generated by CoffeeScript 1.9.1
var isquery, stringify;
isquery = require('./isquery');
stringify = function(indent, query) {
var key, newindent, res, value;
if (query instanceof Array || typeof query !== 'object') {
return JSON.stringify(query, null, 2).split('\n').map(function(i) {
return "" + indent + i;
}).join('\n');
}
newindent = indent + " ";
res = [];
if (!isquery(query)) {
for (key in query) {
value = query[key];
res.push("" + indent + key + ":");
res.push(stringify(newindent, value));
}
} else {
res.push("" + indent + query.__q);
if ((query.__s != null) && !((query.__p != null) || (query.__l != null) || (query.__r != null))) {
res.push(stringify(indent, query.__s));
} else if ((query.__p != null) && (query.__s != null) && !((query.__l != null) || (query.__r != null))) {
res.push(stringify(newindent, query.__p));
res.push(stringify(indent, query.__s));
} else {
if (query.__p != null) {
res.push(indent + "p:");
res.push(stringify(newindent, query.__p));
}
if (query.__s != null) {
res.push(indent + "s:");
res.push(stringify(newindent, query.__s));
}
if (query.__l != null) {
res.push(indent + "l:");
res.push(stringify(newindent, query.__l));
}
if (query.__r != null) {
res.push(indent + "r:");
res.push(stringify(newindent, query.__r));
}
}
}
return res.join('\n');
};
module.exports = function(query) {
return stringify('', query);
};