UNPKG

1.04 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var query = require("querystring");
4var MsgObject = /** @class */ (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 // debug
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}());
39exports.MsgObject = MsgObject;