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