forked from mainegreen/pdf.js.forms
-
Notifications
You must be signed in to change notification settings - Fork 4
/
explore_dict.js
77 lines (71 loc) · 2.1 KB
/
explore_dict.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
68
69
70
71
72
73
74
75
76
77
function document(item, depth, prefix, showFunctions) {
if (depth==0)
return;
if (typeof(showFunctions)=='undefined')
showFunctions=true;
var iterations = 0;
if (typeof(item)=='object') {
var key;
for(key in item) {
iterations ++;
if (iterations>30)
return;
if (typeof(item[key])=='object') {
data[prefix+'.'+key] = '{object}';
if (key!='xref') {
document(item[key],depth-1,prefix+'_'+key,showFunctions);
}
}
else {
if (typeof(item[key])=='function') {
if (showFunctions)
data[prefix+'.'+key] = ' {function}';
}
else {
try {
data[prefix+'.'+key] =String(item[key]);
if (isDict(item)) {
data[prefix+'.'+key+(dv)] =String(item.get(key));
}
}
catch(e) {
data[prefix+'.'+key] = ' ** '+typeof(item[key])+' : '+e.message;
}
}
}
}
}
}
function dictExplorer(dict, depth) { // because get() can lead to results I don't want
if (depth==0)
return {'exceededDepth':true};
var returnObj = {}
var iterations = 0;
if (typeof(dict)=='object') {
var key;
for(key in dict) {
iterations ++;
if (iterations>30)
return {'exceededLimit':true};
if (typeof(dict[key])=='object') {
if (key!='xref') {
returnObj[key] = dictExplorer(dict[key],depth-1);
}
}
else {
try {
if (typeof(dict[key])!='function') {
returnObj[key] =String(dict[key]);
//if (isDict(dict)) {
// returnObj[key+'(dv)'] =String(dict.get(key));
//}
}
}
catch(e) {
returnObj[key] = ' ** '+typeof(dict[key])+' : '+e.message;
}
}
}
}
return returnObj;
}