1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var query = require("querystring");
|
4 | var MsgObject = (function () {
|
5 | function MsgObject() {
|
6 | }
|
7 | MsgObject.parse = function (body) {
|
8 | var isObject = function (obj) {
|
9 | return obj.constructor === Object;
|
10 | };
|
11 | var regExp = new RegExp(/<xml>[\s\S]*?<\/xml>/g);
|
12 | if (regExp.test(body)) {
|
13 | return body;
|
14 | }
|
15 | try {
|
16 |
|
17 | if (isObject(body)) {
|
18 | return body;
|
19 | }
|
20 | else {
|
21 | var json = JSON.parse(body);
|
22 | if (Object.keys(json).length > 0) {
|
23 | return json;
|
24 | }
|
25 | return body;
|
26 | }
|
27 | }
|
28 | catch (ex) {
|
29 | var obj = query.parse(body);
|
30 | if (Object.keys(obj).length > 0) {
|
31 | return obj;
|
32 | }
|
33 | return body;
|
34 | }
|
35 | };
|
36 | ;
|
37 | return MsgObject;
|
38 | }());
|
39 | exports.MsgObject = MsgObject;
|