a11199a2774158e23671bc6c5b49a5d01647687f
[aai/esr-gui.git] /
1 try {
2   exports.BSONPure = require('./bson');
3   exports.BSONNative = require('./bson');
4 } catch(err) {
5 }
6
7 [ 'binary'
8   , 'code'
9   , 'map'
10   , 'db_ref'
11   , 'double'
12   , 'int_32'
13   , 'max_key'
14   , 'min_key'
15   , 'objectid'
16   , 'regexp'
17   , 'symbol'
18   , 'decimal128'
19   , 'timestamp'
20   , 'long'
21   , 'bson'].forEach(function (path) {
22         var module = require('./' + path);
23         for (var i in module) {
24                 exports[i] = module[i];
25     }
26 });
27
28 // Exports all the classes for the PURE JS BSON Parser
29 exports.pure = function() {
30   var classes = {};
31   // Map all the classes
32   [ 'binary'
33     , 'code'
34     , 'map'
35     , 'db_ref'
36     , 'double'
37     , 'int_32'
38     , 'max_key'
39     , 'min_key'
40     , 'objectid'
41     , 'regexp'
42     , 'symbol'
43     , 'decimal128'
44     , 'timestamp'
45     , 'long'
46     , 'bson'].forEach(function (path) {
47         var module = require('./' + path);
48         for (var i in module) {
49                 classes[i] = module[i];
50       }
51   });
52   // Return classes list
53   return classes;
54 }
55
56 // Exports all the classes for the NATIVE JS BSON Parser
57 exports.native = function() {
58   var classes = {};
59   // Map all the classes
60   [ 'binary'
61     , 'code'
62     , 'map'
63     , 'db_ref'
64     , 'double'
65     , 'int_32'
66     , 'max_key'
67     , 'min_key'
68     , 'objectid'
69     , 'regexp'
70     , 'symbol'
71     , 'decimal128'
72     , 'timestamp'
73     , 'long'
74     , 'bson'].forEach(function (path) {
75       var module = require('./' + path);
76       for (var i in module) {
77         classes[i] = module[i];
78       }
79   });
80
81   // Catch error and return no classes found
82   try {
83     classes['BSON'] = require('./bson');
84   } catch(err) {
85     return exports.pure();
86   }
87
88   // Return classes list
89   return classes;
90 }