PageSourceSearch

https://dev.rutoken.ru/includes/js/third-party/jquery.json-2.3.js

js rutoken.ru collected 2026-09-24 08:59:20 UTC 4,894 bytes, 195 lines download raw bytes

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