No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

1 línea
44 KiB

  1. {"ast":null,"code":"/*! JSON v3.3.2 | http://bestiejs.github.io/json3 | Copyright 2012-2014, Kit Cambridge | http://kit.mit-license.org */\n;\n(function () {\n // Detect the `define` function exposed by asynchronous module loaders. The\n // strict `define` check is necessary for compatibility with `r.js`.\n var isLoader = typeof define === \"function\" && define.amd; // A set of types used to distinguish objects from primitives.\n\n var objectTypes = {\n \"function\": true,\n \"object\": true\n }; // Detect the `exports` object exposed by CommonJS implementations.\n\n var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports; // Use the `global` object exposed by Node (including Browserify via\n // `insert-module-globals`), Narwhal, and Ringo as the default context,\n // and the `window` object in browsers. Rhino exports a `global` function\n // instead.\n\n var root = objectTypes[typeof window] && window || this,\n freeGlobal = freeExports && objectTypes[typeof module] && module && !module.nodeType && typeof global == \"object\" && global;\n\n if (freeGlobal && (freeGlobal[\"global\"] === freeGlobal || freeGlobal[\"window\"] === freeGlobal || freeGlobal[\"self\"] === freeGlobal)) {\n root = freeGlobal;\n } // Public: Initializes JSON 3 using the given `context` object, attaching the\n // `stringify` and `parse` functions to the specified `exports` object.\n\n\n function runInContext(context, exports) {\n context || (context = root[\"Object\"]());\n exports || (exports = root[\"Object\"]()); // Native constructor aliases.\n\n var Number = context[\"Number\"] || root[\"Number\"],\n String = context[\"String\"] || root[\"String\"],\n Object = context[\"Object\"] || root[\"Object\"],\n Date = context[\"Date\"] || root[\"Date\"],\n SyntaxError = context[\"SyntaxError\"] || root[\"SyntaxError\"],\n TypeError = context[\"TypeError\"] || root[\"TypeError\"],\n Math = context[\"Math\"] || root[\"Math\"],\n nativeJSON = context[\"JSON\"] || root[\"JSON\"]; // Delegate to the native `stringify` and `parse` implementations.\n\n if (typeof nativeJSON == \"object\" && nativeJSON) {\n exports.stringify = nativeJSON.stringify;\n exports.parse = nativeJSON.parse;\n } // Convenience aliases.\n\n\n var objectProto = Object.prototype,\n getClass = objectProto.toString,\n _isProperty,\n _forEach,\n undef; // Test the `Date#getUTC*` methods. Based on work by @Yaffle.\n\n\n var isExtended = new Date(-3509827334573292);\n\n try {\n // The `getUTCFullYear`, `Month`, and `Date` methods return nonsensical\n // results for certain dates in Opera >= 10.53.\n isExtended = isExtended.getUTCFullYear() == -109252 && isExtended.getUTCMonth() === 0 && isExtended.getUTCDate() === 1 && // Safari < 2.0.2 stores the internal millisecond time value correctly,\n // but clips the values returned by the date methods to the range of\n // signed 32-bit integers ([-2 ** 31, 2 ** 31 - 1]).\n isExtended.getUTCHours() == 10 && isExtended.getUTCMinutes() == 37 && isExtended.getUTCSeconds() == 6 && isExtended.getUTCMilliseconds() == 708;\n } catch (exception) {} // Internal: Determines whether the native `JSON.stringify` and `parse`\n // implementations are spec-compliant. Based on work by Ken Snyder.\n\n\n function has(name) {\n if (has[name] !== undef) {\n // Return cached feature test result.\n return has[name];\n }\n\n var isSupported;\n\n if (name == \"bug-string-char-index\") {\n // IE <= 7 doesn't support accessing string characters using square\n // bracket notation. IE 8 only supports this for primitives.\n isSupported = \"a\"[0] != \"a\";\n } else if (name == \"json\") {\n // Indicates whether both `JSON.stringify` and `JSON.parse` are\n // supported.\n isSupported = has(\"json-stringify\") && has(\"json-parse\");\n } else {\n var value,\n serialized = \"{\\\"a\\\":[1,true,false,null,\\\"\\\\u0000\\\\b\\\\n\\\\f\\\\r\\\\t\\\"]}\"; // Test `JSON.stringify`.\n\n if (name == \"json-stringify\") {\n var stringify = exports.stringify,\n stringifySupported = typeof stringify == \"function\" && isExtended;\n\n if (stringifySupported) {\n // A test function object with a custom `toJSON` method.\n (value = function value() {\n return 1;\n }).toJSON = value;\n\n try {\n stringifySupported = // Firefox 3.1b1 and b2 serialize string, number, and boolean\n // primitives as object literals.\n stringify(0) === \"0\" && // FF 3.1b1, b2, and JSON 2 serialize wrapped primitives as object\n // literals.\n stringify(new Number()) === \"0\" && stringify(new String()) == '\"\"' && // FF 3.1b1, 2 throw an error if the value is `null`, `undefined`, or\n // does not define a canonical JSON representation (this applies to\n // objects with `toJSON` properties as well, *unless* they are nested\n // within an object or array).\n stringify(getClass) === undef && // IE 8 serializes `undefined` as `\"undefined\"`. Safari <= 5.1.7 and\n // FF 3.1b3 pass this test.\n stringify(undef) === undef && // Safari <= 5.1.7 and FF 3.1b3 throw `Error`s and `TypeError`s,\n // respectively, if the value is omitted entirely.\n stringify() === undef && // FF 3.1b1, 2 throw an error if the given value is not a number,\n // string, array, object, Boolean, or `null` literal. This applies to\n // objects with custom `toJSON` methods as well, unless they are nested\n // inside object or array literals. YUI 3.0.0b1 ignores custom `toJSON`\n // methods entirely.\n stringify(value) === \"1\" && stringify([value]) == \"[1]\" && // Prototype <= 1.6.1 serializes `[undefined]` as `\"[]\"` instead of\n // `\"[null]\"`.\n stringify([undef]) == \"[null]\" && // YUI 3.0.0b1 fails to serialize `null` literals.\n stringify(null) == \"null\" && // FF 3.1b1, 2 halts serialization if an array contains a function:\n // `[1, true, getClass, 1]` serializes as \"[1,true,],\". FF 3.1b3\n // elides non-JSON values from objects and arrays, unless they\n // define custom `toJSON` methods.\n stringify([undef, getClass, null]) == \"[null,null,null]\" && // Simple serialization test. FF 3.1b1 uses Unicode escape sequences\n // where character escape codes are expected (e.g., `\\b` => `\\u0008`).\n stringify({\n \"a\": [value, true, false, null, \"\\x00\\b\\n\\f\\r\\t\"]\n }) == serialized && // FF 3.1b1 and b2 ignore the `filter` and `width` arguments.\n stringify(null, value) === \"1\" && stringify([1, 2], null, 1) == \"[\\n 1,\\n 2\\n]\" && // JSON 2, Prototype <= 1.7, and older WebKit builds incorrectly\n // serialize extended years.\n stringify(new Date(-8.64e15)) == '\"-271821-04-20T00:00:00.000Z\"' && // The milliseconds are optional in ES 5, but required in 5.1.\n stringify(new Date(8.64e15)) == '\"+275760-09-13T00:00:00.000Z\"' && // Firefox <= 11.0 incorrectly serializes years prior to 0 as negative\n // four-digit years instead of six-digit years. Credits: @Yaffle.\n stringify(new Date(-621987552e5)) == '\"-000001-01-01T00:00:00.000Z\"' && // Safari <= 5.1.5 and Opera >= 10.53 incorrectly serialize millisecond\n // values less than 1000. Credits: @Yaffle.\n stringify(new Date(-1)) == '\"1969-12-31T23:59:59.999Z\"';\n } catch (exception) {\n stringifySupported = false;\n }\n }\n\n isSupported = stringifySupported;\n } // Test `JSON.parse`.\n\n\n if (name == \"json-parse\") {\n var parse = exports.parse;\n\n if (typeof parse == \"function\") {\n try {\n // FF 3.1b1, b2 will throw an exception if a bare literal is provided.\n // Conforming implementations should also coerce the initial argument to\n // a string prior to parsing.\n if (parse(\"0\") === 0 && !parse(false)) {\n // Simple parsing test.\n value = parse(serialized);\n var parseSupported = value[\"a\"].length == 5 && value[\"a\"][0] === 1;\n\n if (parseSupported) {\n try {\n // Safari <= 5.1.2 and FF 3.1b1 allow unescaped tabs in strings.\n parseSupported = !parse('\"\\t\"');\n } catch (exception) {}\n\n if (parseSupported) {\n try {\n // FF 4.0 and 4.0.1 allow leading `+` signs and leading\n // decimal points. FF 4.0, 4.0.1, and IE 9-10 also allow\n // certain octal literals.\n parseSupported = parse(\"01\") !== 1;\n } catch (exception) {}\n }\n\n if (parseSupported) {\n try {\n // FF 4.0, 4.0.1, and Rhino 1.7R3-R4 allow trailing decimal\n // points. These environments, along with FF 3.1b1 and 2,\n // also allow trailing commas in JSON objects and arrays.\n parseSupported = parse(\"1.\") !== 1;\n } catch (exception) {}\n }\n }\n }\n } catch (exception) {\n parseSupported = false;\n }\n }\n\n isSupported = parseSupported;\n }\n }\n\n return has[name] = !!isSupported;\n }\n\n if (!has(\"json\")) {\n // Common `[[Class]]` name aliases.\n var functionClass = \"[object Function]\",\n dateClass = \"[object Date]\",\n numberClass = \"[object Number]\",\n stringClass = \"[object String]\",\n arrayClass = \"[object Array]\",\n booleanClass = \"[object Boolean]\"; // Detect incomplete support for accessing string characters by index.\n\n var charIndexBuggy = has(\"bug-string-char-index\"); // Define additional utility methods if the `Date` methods are buggy.\n\n if (!isExtended) {\n var floor = Math.floor; // A mapping between the months of the year and the number of days between\n // January 1st and the first of the respective month.\n\n var Months = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]; // Internal: Calculates the number of days between the Unix epoch and the\n // first day of the given month.\n\n var getDay = function getDay(year, month) {\n return Months[month] + 365 * (year - 1970) + floor((year - 1969 + (month = +(month > 1))) / 4) - floor((year - 1901 + month) / 100) + floor((year - 1601 + month) / 400);\n };\n } // Internal: Determines if a property is a direct property of the given\n // object. Delegates to the native `Object#hasOwnProperty` method.\n\n\n if (!(_isProperty = objectProto.hasOwnProperty)) {\n _isProperty = function isProperty(property) {\n var members = {},\n constructor;\n\n if ((members.__proto__ = null, members.__proto__ = {\n // The *proto* property cannot be set multiple times in recent\n // versions of Firefox and SeaMonkey.\n \"toString\": 1\n }, members).toString != getClass) {\n // Safari <= 2.0.3 doesn't implement `Object#hasOwnProperty`, but\n // supports the mutable *proto* property.\n _isProperty = function isProperty(property) {\n // Capture and break the object's prototype chain (see section 8.6.2\n // of the ES 5.1 spec). The parenthesized expression prevents an\n // unsafe transformation by the Closure Compiler.\n var original = this.__proto__,\n result = (property in (this.__proto__ = null, this)); // Restore the original prototype chain.\n\n this.__proto__ = original;\n return result;\n };\n } else {\n // Capture a reference to the top-level `Object` constructor.\n constructor = members.constructor; // Use the `constructor` property to simulate `Object#hasOwnProperty` in\n // other environments.\n\n _isProperty = function isProperty(property) {\n var parent = (this.constructor || constructor).prototype;\n return property in this && !(property in parent && this[property] === parent[property]);\n };\n }\n\n members = null;\n return _isProperty.call(this, property);\n };\n } // Internal: Normalizes the `for...in` iteration algorithm across\n // environments. Each enumerated key is yielded to a `callback` function.\n\n\n _forEach = function forEach(object, callback) {\n var size = 0,\n Properties,\n members,\n property; // Tests for bugs in the current environment's `for...in` algorithm. The\n // `valueOf` property inherits the non-enumerable flag from\n // `Object.prototype` in older versions of IE, Netscape, and Mozilla.\n\n (Properties = function Properties() {\n this.valueOf = 0;\n }).prototype.valueOf = 0; // Iterate over a new instance of the `Properties` class.\n\n members = new Properties();\n\n for (property in members) {\n // Ignore all properties inherited from `Object.prototype`.\n if (_isProperty.call(members, property)) {\n size++;\n }\n }\n\n Properties = members = null; // Normalize the iteration algorithm.\n\n if (!size) {\n // A list of non-enumerable properties inherited from `Object.prototype`.\n members = [\"valueOf\", \"toString\", \"toLocaleString\", \"propertyIsEnumerable\", \"isPrototypeOf\", \"hasOwnProperty\", \"constructor\"]; // IE <= 8, Mozilla 1.0, and Netscape 6.2 ignore shadowed non-enumerable\n // properties.\n\n _forEach = function forEach(object, callback) {\n var isFunction = getClass.call(object) == functionClass,\n property,\n length;\n var hasProperty = !isFunction && typeof object.constructor != \"function\" && objectTypes[typeof object.hasOwnProperty] && object.hasOwnProperty || _isProperty;\n\n for (property in object) {\n // Gecko <= 1.0 enumerates the `prototype` property of functions under\n // certain conditions; IE does not.\n if (!(isFunction && property == \"prototype\") && hasProperty.call(object, property)) {\n callback(property);\n }\n } // Manually invoke the callback for each non-enumerable property.\n\n\n for (length = members.length; property = members[--length]; hasProperty.call(object, property) && callback(property)) {\n ;\n }\n };\n } else if (size == 2) {\n // Safari <= 2.0.4 enumerates shadowed properties twice.\n _forEach = function forEach(object, callback) {\n // Create a set of iterated properties.\n var members = {},\n isFunction = getClass.call(object) == functionClass,\n property;\n\n for (property in object) {\n // Store each property name to prevent double enumeration. The\n // `prototype` property of functions is not enumerated due to cross-\n // environment inconsistencies.\n if (!(isFunction && property == \"prototype\") && !_isProperty.call(members, property) && (members[property] = 1) && _isProperty.call(object, property)) {\n callback(property);\n }\n }\n };\n } else {\n // No bugs detected; use the standard `for...in` algorithm.\n _forEach = function forEach(object, callback) {\n var isFunction = getClass.call(object) == functionClass,\n property,\n isConstructor;\n\n for (property in object) {\n if (!(isFunction && property == \"prototype\") && _isProperty.call(object, property) && !(isConstructor = property === \"constructor\")) {\n callback(property);\n }\n } // Manually invoke the callback for the `constructor` property due to\n // cross-environment inconsistencies.\n\n\n if (isConstructor || _isProperty.call(object, property = \"constructor\")) {\n callback(property);\n }\n };\n }\n\n return _forEach(object, callback);\n }; // Public: Serializes a JavaScript `value` as a JSON string. The optional\n // `filter` argument may specify either a function that alters how object and\n // array members are serialized, or an array of strings and numbers that\n // indicates which properties should be serialized. The optional `width`\n // argument may be either a string or number that specifies the indentation\n // level of the output.\n\n\n if (!has(\"json-stringify\")) {\n // Internal: A map of control characters and their escaped equivalents.\n var Escapes = {\n 92: \"\\\\\\\\\",\n 34: '\\\\\"',\n 8: \"\\\\b\",\n 12: \"\\\\f\",\n 10: \"\\\\n\",\n 13: \"\\\\r\",\n 9: \"\\\\t\"\n }; // Internal: Converts `value` into a zero-padded string such that its\n // length is at least equal to `width`. The `width` must be <= 6.\n\n var leadingZeroes = \"000000\";\n\n var toPaddedString = function toPaddedString(width, value) {\n // The `|| 0` expression is necessary to work around a bug in\n // Opera <= 7.54u2 where `0 == -0`, but `String(-0) !== \"0\"`.\n return (leadingZeroes + (value || 0)).slice(-width);\n }; // Internal: Double-quotes a string `value`, replacing all ASCII control\n // characters (characters with code unit values between 0 and 31) with\n // their escaped equivalents. This is an implementation of the\n // `Quote(value)` operation defined in ES 5.1 section 15.12.3.\n\n\n var unicodePrefix = \"\\\\u00\";\n\n var quote = function quote(value) {\n var result = '\"',\n index = 0,\n length = value.length,\n useCharIndex = !charIndexBuggy || length > 10;\n var symbols = useCharIndex && (charIndexBuggy ? value.split(\"\") : value);\n\n for (; index < length; index++) {\n var charCode = value.charCodeAt(index); // If the character is a control character, append its Unicode or\n // shorthand escape sequence; otherwise, append the character as-is.\n\n switch (charCode) {\n case 8:\n case 9:\n case 10:\n case 12:\n case 13:\n case 34:\n case 92:\n result += Escapes[charCode];\n break;\n\n default:\n if (charCode < 32) {\n result += unicodePrefix + toPaddedString(2, charCode.toString(16));\n break;\n }\n\n result += useCharIndex ? symbols[index] : value.charAt(index);\n }\n }\n\n return result + '\"';\n }; // Internal: Recursively serializes an object. Implements the\n // `Str(key, holder)`, `JO(value)`, and `JA(value)` operations.\n\n\n var serialize = function serialize(property, object, callback, properties, whitespace, indentation, stack) {\n var value, className, year, month, date, time, hours, minutes, seconds, milliseconds, results, element, index, length, prefix, result;\n\n try {\n // Necessary for host object support.\n value = object[property];\n } catch (exception) {}\n\n if (typeof value == \"object\" && value) {\n className = getClass.call(value);\n\n if (className == dateClass && !_isProperty.call(value, \"toJSON\")) {\n if (value > -1 / 0 && value < 1 / 0) {\n // Dates are serialized according to the `Date#toJSON` method\n // specified in ES 5.1 section 15.9.5.44. See section 15.9.1.15\n // for the ISO 8601 date time string format.\n if (getDay) {\n // Manually compute the year, month, date, hours, minutes,\n // seconds, and milliseconds if the `getUTC*` methods are\n // buggy. Adapted from @Yaffle's `date-shim` project.\n date = floor(value / 864e5);\n\n for (year = floor(date / 365.2425) + 1970 - 1; getDay(year + 1, 0) <= date; year++) {\n ;\n }\n\n for (month = floor((date - getDay(year, 0)) / 30.42); getDay(year, month + 1) <= date; month++) {\n ;\n }\n\n date = 1 + date - getDay(year, month); // The `time` value specifies the time within the day (see ES\n // 5.1 section 15.9.1.2). The formula `(A % B + B) % B` is used\n // to compute `A modulo B`, as the `%` operator does not\n // correspond to the `modulo` operation for negative numbers.\n\n time = (value % 864e5 + 864e5) % 864e5; // The hours, minutes, seconds, and milliseconds are obtained by\n // decomposing the time within the day. See section 15.9.1.10.\n\n hours = floor(time / 36e5) % 24;\n minutes = floor(time / 6e4) % 60;\n seconds = floor(time / 1e3) % 60;\n milliseconds = time % 1e3;\n } else {\n year = value.getUTCFullYear();\n month = value.getUTCMonth();\n date = value.getUTCDate();\n hours = value.getUTCHours();\n minutes = value.getUTCMinutes();\n seconds = value.getUTCSeconds();\n milliseconds = value.getUTCMilliseconds();\n } // Serialize extended years correctly.\n\n\n value = (year <= 0 || year >= 1e4 ? (year < 0 ? \"-\" : \"+\") + toPaddedString(6, year < 0 ? -year : year) : toPaddedString(4, year)) + \"-\" + toPaddedString(2, month + 1) + \"-\" + toPaddedString(2, date) + // Months, dates, hours, minutes, and seconds should have two\n // digits; milliseconds should have three.\n \"T\" + toPaddedString(2, hours) + \":\" + toPaddedString(2, minutes) + \":\" + toPaddedString(2, seconds) + // Milliseconds are optional in ES 5.0, but required in 5.1.\n \".\" + toPaddedString(3, milliseconds) + \"Z\";\n } else {\n value = null;\n }\n } else if (typeof value.toJSON == \"function\" && (className != numberClass && className != stringClass && className != arrayClass || _isProperty.call(value, \"toJSON\"))) {\n // Prototype <= 1.6.1 adds non-standard `toJSON` methods to the\n // `Number`, `String`, `Date`, and `Array` prototypes. JSON 3\n // ignores all `toJSON` methods on these objects unless they are\n // defined directly on an instance.\n value = value.toJSON(property);\n }\n }\n\n if (callback) {\n // If a replacement function was provided, call it to obtain the value\n // for serialization.\n value = callback.call(object, property, value);\n }\n\n if (value === null) {\n return \"null\";\n }\n\n className = getClass.call(value);\n\n if (className == booleanClass) {\n // Booleans are represented literally.\n return \"\" + value;\n } else if (className == numberClass) {\n // JSON numbers must be finite. `Infinity` and `NaN` are serialized as\n // `\"null\"`.\n return value > -1 / 0 && value < 1 / 0 ? \"\" + value : \"null\";\n } else if (className == stringClass) {\n // Strings are double-quoted and escaped.\n return quote(\"\" + value);\n } // Recursively serialize objects and arrays.\n\n\n if (typeof value == \"object\") {\n // Check for cyclic structures. This is a linear search; performance\n // is inversely proportional to the number of unique nested objects.\n for (length = stack.length; length--;) {\n if (stack[length] === value) {\n // Cyclic structures cannot be serialized by `JSON.stringify`.\n throw TypeError();\n }\n } // Add the object to the stack of traversed objects.\n\n\n stack.push(value);\n results = []; // Save the current indentation level and indent one additional level.\n\n prefix = indentation;\n indentation += whitespace;\n\n if (className == arrayClass) {\n // Recursively serialize array elements.\n for (index = 0, length = value.length; index < length; index++) {\n element = serialize(index, value, callback, properties, whitespace, indentation, stack);\n results.push(element === undef ? \"null\" : element);\n }\n\n result = results.length ? whitespace ? \"[\\n\" + indentation + results.join(\",\\n\" + indentation) + \"\\n\" + prefix + \"]\" : \"[\" + results.join(\",\") + \"]\" : \"[]\";\n } else {\n // Recursively serialize object members. Members are selected from\n // either a user-specified list of property names, or the object\n // itself.\n _forEach(properties || value, function (property) {\n var element = serialize(property, value, callback, properties, whitespace, indentation, stack);\n\n if (element !== undef) {\n // According to ES 5.1 section 15.12.3: \"If `gap` {whitespace}\n // is not the empty string, let `member` {quote(property) + \":\"}\n // be the concatenation of `member` and the `space` character.\"\n // The \"`space` character\" refers to the literal space\n // character, not the `space` {width} argument provided to\n // `JSON.stringify`.\n results.push(quote(property) + \":\" + (whitespace ? \" \" : \"\") + element);\n }\n });\n\n result = results.length ? whitespace ? \"{\\n\" + indentation + results.join(\",\\n\" + indentation) + \"\\n\" + prefix + \"}\" : \"{\" + results.join(\",\") + \"}\" : \"{}\";\n } // Remove the object from the traversed object stack.\n\n\n stack.pop();\n return result;\n }\n }; // Public: `JSON.stringify`. See ES 5.1 section 15.12.3.\n\n\n exports.stringify = function (source, filter, width) {\n var whitespace, callback, properties, className;\n\n if (objectTypes[typeof filter] && filter) {\n if ((className = getClass.call(filter)) == functionClass) {\n callback = filter;\n } else if (className == arrayClass) {\n // Convert the property names array into a makeshift set.\n properties = {};\n\n for (var index = 0, length = filter.length, value; index < length; value = filter[index++], (className = getClass.call(value), className == stringClass || className == numberClass) && (properties[value] = 1)) {\n ;\n }\n }\n }\n\n if (width) {\n if ((className = getClass.call(width)) == numberClass) {\n // Convert the `width` to an integer and create a string containing\n // `width` number of space characters.\n if ((width -= width % 1) > 0) {\n for (whitespace = \"\", width > 10 && (width = 10); whitespace.length < width; whitespace += \" \") {\n ;\n }\n }\n } else if (className == stringClass) {\n whitespace = width.length <= 10 ? width : width.slice(0, 10);\n }\n } // Opera <= 7.54u2 discards the values associated with empty string keys\n // (`\"\"`) only if they are used directly within an object member list\n // (e.g., `!(\"\" in { \"\": 1})`).\n\n\n return serialize(\"\", (value = {}, value[\"\"] = source, value), callback, properties, whitespace, \"\", []);\n };\n } // Public: Parses a JSON source string.\n\n\n if (!has(\"json-parse\")) {\n var fromCharCode = String.fromCharCode; // Internal: A map of escaped control characters and their unescaped\n // equivalents.\n\n var Unescapes = {\n 92: \"\\\\\",\n 34: '\"',\n 47: \"/\",\n 98: \"\\b\",\n 116: \"\\t\",\n 110: \"\\n\",\n 102: \"\\f\",\n 114: \"\\r\"\n }; // Internal: Stores the parser state.\n\n var Index, Source; // Internal: Resets the parser state and throws a `SyntaxError`.\n\n var abort = function abort() {\n Index = Source = null;\n throw SyntaxError();\n }; // Internal: Returns the next token, or `\"$\"` if the parser has reached\n // the end of the source string. A token may be a string, number, `null`\n // literal, or Boolean literal.\n\n\n var lex = function lex() {\n var source = Source,\n length = source.length,\n value,\n begin,\n position,\n isSigned,\n charCode;\n\n while (Index < length) {\n charCode = source.charCodeAt(Index);\n\n switch (charCode) {\n case 9:\n case 10:\n case 13:\n case 32:\n // Skip whitespace tokens, including tabs, carriage returns, line\n // feeds, and space characters.\n Index++;\n break;\n\n case 123:\n case 125:\n case 91:\n case 93:\n case 58:\n case 44:\n // Parse a punctuator token (`{`, `}`, `[`, `]`, `:`, or `,`) at\n // the current position.\n value = charIndexBuggy ? source.charAt(Index) : source[Index];\n Index++;\n return value;\n\n case 34:\n // `\"` delimits a JSON string; advance to the next character and\n // begin parsing the string. String tokens are prefixed with the\n // sentinel `@` character to distinguish them from punctuators and\n // end-of-string tokens.\n for (value = \"@\", Index++; Index < length;) {\n charCode = source.charCodeAt(Index);\n\n if (charCode < 32) {\n // Unescaped ASCII control characters (those with a code unit\n // less than the space character) are not permitted.\n abort();\n } else if (charCode == 92) {\n // A reverse solidus (`\\`) marks the beginning of an escaped\n // control character (including `\"`, `\\`, and `/`) or Unicode\n // escape sequence.\n charCode = source.charCodeAt(++Index);\n\n switch (charCode) {\n case 92:\n case 34:\n case 47:\n case 98:\n case 116:\n case 110:\n case 102:\n case 114:\n // Revive escaped control characters.\n value += Unescapes[charCode];\n Index++;\n break;\n\n case 117:\n // `\\u` marks the beginning of a Unicode escape sequence.\n // Advance to the first character and validate the\n // four-digit code point.\n begin = ++Index;\n\n for (position = Index + 4; Index < position; Index++) {\n charCode = source.charCodeAt(Index); // A valid sequence comprises four hexdigits (case-\n // insensitive) that form a single hexadecimal value.\n\n if (!(charCode >= 48 && charCode <= 57 || charCode >= 97 && charCode <= 102 || charCode >= 65 && charCode <= 70)) {\n // Invalid Unicode escape sequence.\n abort();\n }\n } // Revive the escaped character.\n\n\n value += fromCharCode(\"0x\" + source.slice(begin, Index));\n break;\n\n default:\n // Invalid escape sequence.\n abort();\n }\n } else {\n if (charCode == 34) {\n // An unescaped double-quote character marks the end of the\n // string.\n break;\n }\n\n charCode = source.charCodeAt(Index);\n begin = Index; // Optimize for the common case where a string is valid.\n\n while (charCode >= 32 && charCode != 92 && charCode != 34) {\n charCode = source.charCodeAt(++Index);\n } // Append the string as-is.\n\n\n value += source.slice(begin, Index);\n }\n }\n\n if (source.charCodeAt(Index) == 34) {\n // Advance to the next character and return the revived string.\n Index++;\n return value;\n } // Unterminated string.\n\n\n abort();\n\n default:\n // Parse numbers and literals.\n begin = Index; // Advance past the negative sign, if one is specified.\n\n if (charCode == 45) {\n isSigned = true;\n charCode = source.charCodeAt(++Index);\n } // Parse an integer or floating-point value.\n\n\n if (charCode >= 48 && charCode <= 57) {\n // Leading zeroes are interpreted as octal literals.\n if (charCode == 48 && (charCode = source.charCodeAt(Index + 1), charCode >= 48 && charCode <= 57)) {\n // Illegal octal literal.\n abort();\n }\n\n isSigned = false; // Parse the integer component.\n\n for (; Index < length && (charCode = source.charCodeAt(Index), charCode >= 48 && charCode <= 57); Index++) {\n ;\n } // Floats cannot contain a leading decimal point; however, this\n // case is already accounted for by the parser.\n\n\n if (source.charCodeAt(Index) == 46) {\n position = ++Index; // Parse the decimal component.\n\n for (; position < length && (charCode = source.charCodeAt(position), charCode >= 48 && charCode <= 57); position++) {\n ;\n }\n\n if (position == Index) {\n // Illegal trailing decimal.\n abort();\n }\n\n Index = position;\n } // Parse exponents. The `e` denoting the exponent is\n // case-insensitive.\n\n\n charCode = source.charCodeAt(Index);\n\n if (charCode == 101 || charCode == 69) {\n charCode = source.charCodeAt(++Index); // Skip past the sign following the exponent, if one is\n // specified.\n\n if (charCode == 43 || charCode == 45) {\n Index++;\n } // Parse the exponential component.\n\n\n for (position = Index; position < length && (charCode = source.charCodeAt(position), charCode >= 48 && charCode <= 57); position++) {\n ;\n }\n\n if (position == Index) {\n // Illegal empty exponent.\n abort();\n }\n\n Index = position;\n } // Coerce the parsed value to a JavaScript number.\n\n\n return +source.slice(begin, Index);\n } // A negative sign may only precede numbers.\n\n\n if (isSigned) {\n abort();\n } // `true`, `false`, and `null` literals.\n\n\n if (source.slice(Index, Index + 4) == \"true\") {\n Index += 4;\n return true;\n } else if (source.slice(Index, Index + 5) == \"false\") {\n Index += 5;\n return false;\n } else if (source.slice(Index, Index + 4) == \"null\") {\n Index += 4;\n return null;\n } // Unrecognized token.\n\n\n abort();\n }\n } // Return the sentinel `$` character if the parser has reached the end\n // of the source string.\n\n\n return \"$\";\n }; // Internal: Parses a JSON `value` token.\n\n\n var get = function get(value) {\n var results, hasMembers;\n\n if (value == \"$\") {\n // Unexpected end of input.\n abort();\n }\n\n if (typeof value == \"string\") {\n if ((charIndexBuggy ? value.charAt(0) : value[0]) == \"@\") {\n // Remove the sentinel `@` character.\n return value.slice(1);\n } // Parse object and array literals.\n\n\n if (value == \"[\") {\n // Parses a JSON array, returning a new JavaScript array.\n results = [];\n\n for (;; hasMembers || (hasMembers = true)) {\n value = lex(); // A closing square bracket marks the end of the array literal.\n\n if (value == \"]\") {\n break;\n } // If the array literal contains elements, the current token\n // should be a comma separating the previous element from the\n // next.\n\n\n if (hasMembers) {\n if (value == \",\") {\n value = lex();\n\n if (value == \"]\") {\n // Unexpected trailing `,` in array literal.\n abort();\n }\n } else {\n // A `,` must separate each array element.\n abort();\n }\n } // Elisions and leading commas are not permitted.\n\n\n if (value == \",\") {\n abort();\n }\n\n results.push(get(value));\n }\n\n return results;\n } else if (value == \"{\") {\n // Parses a JSON object, returning a new JavaScript object.\n results = {};\n\n for (;; hasMembers || (hasMembers = true)) {\n value = lex(); // A closing curly brace marks the end of the object literal.\n\n if (value == \"}\") {\n break;\n } // If the object literal contains members, the current token\n // should be a comma separator.\n\n\n if (hasMembers) {\n if (value == \",\") {\n value = lex();\n\n if (value == \"}\") {\n // Unexpected trailing `,` in object literal.\n abort();\n }\n } else {\n // A `,` must separate each object member.\n abort();\n }\n } // Leading commas are not permitted, object property names must be\n // double-quoted strings, and a `:` must separate each property\n // name and value.\n\n\n if (value == \",\" || typeof value != \"string\" || (charIndexBuggy ? value.charAt(0) : value[0]) != \"@\" || lex() != \":\") {\n abort();\n }\n\n results[value.slice(1)] = get(lex());\n }\n\n return results;\n } // Unexpected token encountered.\n\n\n abort();\n }\n\n return value;\n }; // Internal: Updates a traversed object member.\n\n\n var update = function update(source, property, callback) {\n var element = walk(source, property, callback);\n\n if (element === undef) {\n delete source[property];\n } else {\n source[property] = element;\n }\n }; // Internal: Recursively traverses a parsed JSON object, invoking the\n // `callback` function for each value. This is an implementation of the\n // `Walk(holder, name)` operation defined in ES 5.1 section 15.12.2.\n\n\n var walk = function walk(source, property, callback) {\n var value = source[property],\n length;\n\n if (typeof value == \"object\" && value) {\n // `forEach` can't be used to traverse an array in Opera <= 8.54\n // because its `Object#hasOwnProperty` implementation returns `false`\n // for array indices (e.g., `![1, 2, 3].hasOwnProperty(\"0\")`).\n if (getClass.call(value) == arrayClass) {\n for (length = value.length; length--;) {\n update(value, length, callback);\n }\n } else {\n _forEach(value, function (property) {\n update(value, property, callback);\n });\n }\n }\n\n return callback.call(source, property, value);\n }; // Public: `JSON.parse`. See ES 5.1 section 15.12.2.\n\n\n exports.parse = function (source, callback) {\n var result, value;\n Index = 0;\n Source = \"\" + source;\n result = get(lex()); // If a JSON string contains multiple tokens, it is invalid.\n\n if (lex() != \"$\") {\n abort();\n } // Reset the parser state.\n\n\n Index = Source = null;\n return callback && getClass.call(callback) == functionClass ? walk((value = {}, value[\"\"] = result, value), \"\", callback) : result;\n };\n }\n }\n\n exports[\"runInContext\"] = runInContext;\n return exports;\n }\n\n if (freeExports && !isLoader) {\n // Export for CommonJS environments.\n runInContext(root, freeExports);\n } else {\n // Export for web browsers and JavaScript engines.\n var nativeJSON = root.JSON,\n previousJSON = root[\"JSON3\"],\n isRestored = false;\n var JSON3 = runInContext(root, root[\"JSON3\"] = {\n // Public: Restores the original value of the global `JSON` object and\n // returns a reference to the `JSON3` object.\n \"noConflict\": function noConflict() {\n if (!isRestored) {\n isRestored = true;\n root.JSON = nativeJSON;\n root[\"JSON3\"] = previousJSON;\n nativeJSON = previousJSON = null;\n }\n\n return JSON3;\n }\n });\n root.JSON = {\n \"parse\": JSON3.parse,\n \"stringify\": JSON3.stringify\n };\n } // Export for asynchronous module loaders.\n\n\n if (isLoader) {\n define(function () {\n return JSON3;\n });\n }\n}).call(this);","map":null,"metadata":{},"sourceType":"script"}