1/** 2 * jQuery JSON plugin v2.5.1 3 * https://github.com/Krinkle/jquery-json 4 * 5 * @author Brantley Harris, 2009-2011 6 * @author Timo Tijhof, 2011-2014 7 * @source This plugin is heavily influenced by MochiKit's serializeJSON, which is 8 * copyrighted 2005 by Bob Ippolito. 9 * @source Brantley Harris wrote this plugin. It is based somewhat on the JSON.org 10 * website's http://www.json.org/json2.js, which proclaims: 11 * "NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.", a sentiment that 12 * I uphold. 13 * @license MIT License <http://opensource.org/licenses/MIT> 14 */ 15(function ($) { 16 'use strict'; 17 18 var escape = /["\\\x00-\x1f\x7f-\x9f]/g, 19 meta = { 20 '\b': '\\b', 21 '\t': '\\t', 22 '\n': '\\n', 23 '\f': '\\f', 24 '\r': '\\r', 25 '"': '\\"', 26 '\\': '\\\\' 27 }, 28 hasOwn = Object.prototype.hasOwnProperty; 29 30 /** 31 * jQuery.toJSON 32 * Converts the given argument into a JSON representation. 33 * 34 * @param o {Mixed} The json-serializable *thing* to be converted 35 * 36 * If an object has a toJSON prototype, that will be used to get the representation. 37 * Non-integer/string keys are skipped in the object, as are keys that point to a 38 * function. 39 * 40 */ 41 $.toJSON = typeof JSON === 'object' && JSON.stringify ? JSON.stringify : function (o) { 42 if (o === null) { 43 return 'null'; 44 } 45 46 var pairs, k, name, val, 47 type = $.type(o); 48 49 if (type === 'undefined') { 50 return undefined; 51 } 52 53 // Also covers instantiated Number and Boolean objects, 54 // which are typeof 'object' but thanks to $.type, we 55 // catch them here. I don't know whether it is right 56 // or wrong that instantiated primitives are not 57 // exported to JSON as an {"object":..}. 58 // We choose this path because that's what the browsers did. 59 if (type === 'number' || type === 'boolean') { 60 return String(o); 61 } 62 if (type === 'string') { 63 return $.quoteString(o); 64 } 65 if (typeof o.toJSON === 'function') { 66 return $.toJSON(o.toJSON()); 67 } 68 if (type === 'date') { 69 var month = o.getUTCMonth() + 1, 70 day = o.getUTCDate(), 71 year = o.getUTCFullYear(), 72 hours = o.getUTCHours(), 73 minutes = o.getUTCMinutes(), 74 seconds = o.getUTCSeconds(), 75 milli = o.getUTCMilliseconds(); 76 77 if (month < 10) { 78 month = '0' + month; 79 } 80 if (day < 10) { 81 day = '0' + day; 82 } 83 if (hours < 10) { 84 hours = '0' + hours; 85 } 86 if (minutes < 10) { 87 minutes = '0' + minutes; 88 } 89 if (seconds < 10) { 90 seconds = '0' + seconds; 91 } 92 if (milli < 100) { 93 milli = '0' + milli; 94 } 95 if (milli < 10) { 96 milli = '0' + milli; 97 } 98 return '"' + year + '-' + month + '-' + day + 'T' + 99 hours + ':' + minutes + ':' + seconds + 100 '.' + milli + 'Z"'; 101 } 102 103 pairs = []; 104 105 if ($.isArray(o)) { 106 for (k = 0; k < o.length; k++) { 107 pairs.push($.toJSON(o[k]) || 'null'); 108 } 109 return '[' + pairs.join(',') + ']'; 110 } 111 112 // Any other object (plain object, RegExp, ..) 113 // Need to do typeof instead of $.type, because we also 114 // want to catch non-plain objects. 115 if (typeof o === 'object') { 116 for (k in o) { 117 // Only include own properties, 118 // Filter out inherited prototypes 119 if (hasOwn.call(o, k)) { 120 // Keys must be numerical or string. Skip others 121 type = typeof k; 122 if (type === 'number') { 123 name = '"' + k + '"'; 124 } else if (type === 'string') { 125 name = $.quoteString(k); 126 } else { 127 continue; 128 } 129 type = typeof o[k]; 130 131 // Invalid values like these return undefined 132 // from toJSON, however those object members 133 // shouldn't be included in the JSON string at all. 134 if (type !== 'function' && type !== 'undefined') { 135 val = $.toJSON(o[k]); 136 pairs.push(name + ':' + val); 137 } 138 } 139 } 140 return '{' + pairs.join(',') + '}'; 141 } 142 }; 143 144 /** 145 * jQuery.evalJSON 146 * Evaluates a given json string. 147 * 148 * @param str {String} 149 */ 150 $.evalJSON = typeof JSON === 'object' && JSON.parse ? JSON.parse : function (str) { 151 /*jshint evil: true */ 152 return eval('(' + str + ')'); 153 }; 154 155 /** 156 * jQuery.secureEvalJSON 157 * Evals JSON in a way that is *more* secure. 158 * 159 * @param str {String} 160 */ 161 $.secureEvalJSON = typeof JSON === 'object' && JSON.parse ? JSON.parse : function (str) { 162 var filtered = 163 str 164 .replace(/\\["\\\/bfnrtu]/g, '@') 165 .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']') 166 .replace(/(?:^|:|,)(?:\s*\[)+/g, ''); 167 168 if (/^[\],:{}\s]*$/.test(filtered)) { 169 /*jshint evil: true */ 170 return eval('(' + str + ')'); 171 }
172 throw new SyntaxError('Error parsing JSON, source is not valid.'); 173 }; 174 175 /** 176 * jQuery.quoteString 177 * Returns a string-repr of a string, escaping quotes intelligently. 178 * Mostly a support function for toJSON. 179 * Examples: 180 * >>> jQuery.quoteString('apple') 181 * "apple" 182 * 183 * >>> jQuery.quoteString('"Where are we going?", she asked.') 184 * "\"Where are we going?\", she asked." 185 */ 186 $.quoteString = function (str) { 187 if (str.match(escape)) { 188 return '"' + str.replace(escape, function (a) { 189 var c = meta[a]; 190 if (typeof c === 'string') { 191 return c; 192 } 193 c = a.charCodeAt(); 194 return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16); 195 }) + '"'; 196 } 197 return '"' + str + '"'; 198 }; 199 200}(jQuery));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.