39 | static decode(obj: any) { |
40 | if (obj && obj.$type === 'ObjectId') { |
41 | return new MongoDb.ObjectID(obj.$value); |
42 | } |
43 | if (obj && obj.$type === "Date") { |
44 | return new Date(obj.$value); |
45 | } |
46 | if (obj && obj.$type === "RegExp") { |
47 | return new RegExp(obj.$value.$pattern, obj.$value.$flags); |
48 | } |
49 | if (Array.isArray(obj)) { |
50 | return [...obj.map(JsonEncoder.decode)]; |
51 | } |
52 | if (obj && typeof obj === 'object') { |
53 | for (const [key, value] of Object.entries(obj)) { |
54 | obj[key] = JsonEncoder.decode(value); |
55 | } |
56 | } |
57 | |
58 | return obj; |
59 | } |