PageRenderTime 103ms CodeModel.GetById 61ms app.highlight 8ms RepoModel.GetById 32ms app.codeStats 0ms

/js/lib/Socket.IO-node/example/json.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 18 lines | 18 code | 0 blank | 0 comment | 4 complexity | 99d445dc21a6c32f6bec655c93dae2f5 MD5 | raw file
 1if(!this.JSON){JSON=function(){function f(n){return n<10?'0'+n:n;}
 2Date.prototype.toJSON=function(){return this.getUTCFullYear()+'-'+
 3f(this.getUTCMonth()+1)+'-'+
 4f(this.getUTCDate())+'T'+
 5f(this.getUTCHours())+':'+
 6f(this.getUTCMinutes())+':'+
 7f(this.getUTCSeconds())+'Z';};var m={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};function stringify(value,whitelist){var a,i,k,l,r=/["\\\x00-\x1f\x7f-\x9f]/g,v;switch(typeof value){case'string':return r.test(value)?'"'+value.replace(r,function(a){var c=m[a];if(c){return c;}
 8c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+
 9(c%16).toString(16);})+'"':'"'+value+'"';case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';}
10if(typeof value.toJSON==='function'){return stringify(value.toJSON());}
11a=[];if(typeof value.length==='number'&&!(value.propertyIsEnumerable('length'))){l=value.length;for(i=0;i<l;i+=1){a.push(stringify(value[i],whitelist)||'null');}
12return'['+a.join(',')+']';}
13if(whitelist){l=whitelist.length;for(i=0;i<l;i+=1){k=whitelist[i];if(typeof k==='string'){v=stringify(value[k],whitelist);if(v){a.push(stringify(k)+':'+v);}}}}else{for(k in value){if(typeof k==='string'){v=stringify(value[k],whitelist);if(v){a.push(stringify(k)+':'+v);}}}}
14return'{'+a.join(',')+'}';}}
15return{stringify:stringify,parse:function(text,filter){var j;function walk(k,v){var i,n;if(v&&typeof v==='object'){for(i in v){if(Object.prototype.hasOwnProperty.apply(v,[i])){n=walk(i,v[i]);if(n!==undefined){v[i]=n;}}}}
16return filter(k,v);}
17if(/^[\],:{}\s]*$/.test(text.replace(/\\./g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof filter==='function'?walk('',j):j;}
18throw new SyntaxError('parseJSON');}};}();}