PageSourceSearch

https://www.archeologiasacra.net/pcas-web/resources/js/labs_json.js

js archeologiasacra.net collected 2026-09-24 20:39:37 UTC 6,163 bytes, 207 lines download raw bytes

1/**
2 * labs_json Script by Giraldo Rosales.
3 * Version 1.0
4 * Visit www.liquidgear.net for documentation and updates.
5 *
6 *
7 * Copyright (c) 2009 Nitrogen Design, Inc. All rights reserved.
8 * 
9 * Permission is hereby granted, free of charge, to any person
10 * obtaining a copy of this software and associated documentation
11 * files (the "Software"), to deal in the Software without
12 * restriction, including without limitation the rights to use,
13 * copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following
16 * conditions:
17 * 
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 * 
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
29 **/
30 
31/**
32 * HOW TO USE
33 * ==========
34 * Encode:
35 * var obj = {};
36 * obj.name	= "Test JSON";
37 * obj.type	= "test";
38 * $.json.encode(obj); //output: {"name":"Test JSON", "type":"test"}
39 * 
40 * Decode:
41 * $.json.decode({"name":"Test JSON", "type":"test"}); //output: object
42 * 
43 */
44
45jQuery.json = {
46    encode:function(value, replacer, space) {
47		var i;
48		gap = '';
49		var indent = '';
50		
51		if (typeof space === 'number') {
52			for (i = 0; i < space; i += 1) {
53				indent += ' ';
54			}
55			
56		} else if (typeof space === 'string') {
57			indent = space;
58		}
59		
60		rep = replacer;
61		if (replacer && typeof replacer !== 'function' &&
62				(typeof replacer !== 'object' ||
63				 typeof replacer.length !== 'number')) {
64			throw new Error('JSON.encode');
65		}
66		
67		return this.str('', {'': value});
68    },
69    
70    decode:function(text, reviver) {
71		var j;
72		var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
73		
74		function walk(holder, key) {
75			var k, v, value = holder[key];
76			
77			if (value && typeof value === 'object') {
78				for (k in value) {
79					if (Object.hasOwnProperty.call(value, k)) {
80						v = walk(value, k);
81						if (v !== undefined) {
82							value[k] = v;
83						} else {
84							delete value[k];
85						}
86					}
87				}
88			}
89			return reviver.call(holder, key, value);
90		}
91		
92		cx.lastIndex = 0;
93		
94		if (cx.test(text)) {
95			text = text.replace(cx, function (a) {
96				return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
97			});
98		}
99		
100		if (/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
101			j = eval('(' + text + ')');
102			return typeof reviver === 'function' ? walk({'': j}, '') : j;
103		}
104		
105		throw new SyntaxError('JSON.parse');
106	},
107	
108    f:function(n) {
109        return n < 10 ? '0' + n : n;
110    },
111	
112	DateToJSON:function(key) {
113		return this.getUTCFullYear() + '-' + this.f(this.getUTCMonth() + 1) + '-' + this.f(this.getUTCDate())      + 'T' + this.f(this.getUTCHours())     + ':' + this.f(this.getUTCMinutes())   + ':' + this.f(this.getUTCSeconds())   + 'Z';
114	},
115	
116	StringToJSON:function(key) {
117		return this.valueOf();
118    },
119    
120    quote:function(string) {
121        var meta = {'\b': '\\b','\t': '\\t','\n': '\\n','\f': '\\f','\r': '\\r','"' : '\\"','\\': '\\\\'};
122        var escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
123        
124        escapable.lastIndex = 0;
125        return escapable.test(string) ?
126            '"' + string.replace(escapable, function (a) {
127                var c = meta[a];
128                return typeof c === 'string' ? c :
129                    '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
130            }) + '"' :
131            '"' + string + '"';
132    },
133    
134    str:function(key, holder) {
135        var indent='', gap = '', i, k, v, length, mind = gap, partial, value = holder[key];
136        
137        if (value && typeof value === 'object') {
138            switch((typeof value)) {
139            	case 'date':
140            		this.DateToJSON(key);
141            		break;
142            	default:
143            		this.StringToJSON(key);
144            		break;
145            }
146        }
147        
148        if (typeof rep === 'function') {
149            value = rep.call(holder, key, value);
150        }
151        switch (typeof value) {
152        	case 'string':
153        	    return this.quote(value);
154			case 'number':
155	            return isFinite(value) ? String(value) : 'null';
156			case 'boolean':
157			case 'null':
158	            return String(value);
159	        case 'object':
160				if (!value) {
161					return 'null';
162				}
163				gap += indent;
164				partial = [];
165				
166				if (Object.prototype.toString.apply(value) === '[object Array]') {
167					length = value.length;
168					
169					for (i = 0; i < length; i += 1) {
170						partial[i] = this.str(i, value) || 'null';
171					}
172	
173					v = partial.length === 0 ? '[]' : gap ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : '[' + partial.join(',') + ']';
174					gap = mind;
175					return v;
176				}
177					
178				if (rep && typeof rep === 'object') {
179					length = rep.length;
180					for (i = 0; i < length; i += 1) {
181						k = rep[i];
182						if (typeof k === 'string') {
183							v = this.str(k, value);
184							if (v) {
185								partial.push(this.quote(k) + (gap ? ': ' : ':') + v);
186							}
187						}
188					}
189				} else {
190					for (k in value) {
191						if (Object.hasOwnProperty.call(value, k)) {
192							v = this.str(k, value);
193							if (v) {
194								partial.push(this.quote(k) + (gap ? ': ' : ':') + v);
195							}
196						}
197					}
198				}
199
200				v = partial.length === 0 ? '{}' :
201					gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
202							mind + '}' : '{' + partial.join(',') + '}';
203				gap = mind;
204				return v;
205		}
206	}
207};

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.