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