var econda; (function (econda) { var util; (function (util) { /** * Provides cross browser JSON functions. * * @class econda.util.Json */ var Json = (function () { function Json() { } /** * Convert data structure to json string. Will use browser function if available. * @param {Object} obj * @returns {String} * @static */ Json.stringify = function (obj) { if ((typeof JSON != 'undefined') && JSON.stringify) { Json.stringify = JSON.stringify; } else { Json.stringify = Json._stringify; } return Json.stringify(obj); }; /** * Fallback function if browser supports no JSON * @private * @param {Object} obj * @returns {String} */ Json._stringify = function (obj) { var t = typeof (obj), v, json = [], arr = (obj && obj.constructor == Array); if (t != "object" || obj === null) { if (t == "string") obj = '"' + obj + '"'; return String(obj); } else { for (var n in obj) { v = obj[n]; t = typeof (v); if (t == "string") v = '"' + v + '"'; else if (t == "object" && v !== null) v = this.stringify(v); json.push((arr ? "" : '"' + n + '":') + String(v)); } return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}"); } }; /** * Parse json string and return content as data structure. * @param {String} json * @returns {Mixed} * @static */ Json.parse = function (json) { if ((typeof JSON != 'undefined') && JSON.parse) { Json.parse = JSON.parse; } else { Json.parse = Json._parse; } return Json.parse(json); }; /** * Fallback function to parse a json string based on json2 implementation * {@link https://github.com/douglascrockford/JSON-js/blob/master/json2.js} * * @param {String} json * @returns {Mixed} * @private * @static */ Json._parse = function (json) { var cx = Json.cx; var j; json = String(json); cx.lastIndex = 0; if (cx.test(json)) { json = json.replace(cx, function (a) { return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); }); } if (/^[\],:{}\s]*$/ .test(json.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@') .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']') .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { j = eval('(' + json + ')'); return j; } // If the text is not JSON parseable, then a SyntaxError is thrown. throw new SyntaxError('JSON.parse'); }; Json.cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; return Json; }()); util.Json = Json; })(util = econda.util || (econda.util = {})); })(econda || (econda = {}));