summaryrefslogtreecommitdiffstats
path: root/js/yui3/json-stringify/json-stringify-min.js
blob: 82c3a7c60b14b876aa33078b667d1db202349784 (plain)
1
2
3
4
5
6
7
/*
YUI 3.7.3 (build 5687)
Copyright 2012 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
YUI.add("json-stringify",function(e,t){function n(t){var n=typeof global=="object"?global:undefined;return(e.UA.nodejs&&n?n:e.config.win||{})[t]}function B(e){var t=typeof e;return y[t]||y[a.call(e)]||(t===h?e?h:p:c)}function j(e){return D[e]||(D[e]="\\u"+("0000"+(+e.charCodeAt(0)).toString(16)).slice(-4),P[e]=0),++P[e]===H&&(M.push([new RegExp(e,"g"),D[e]]),_=M.length),D[e]}function F(e){var t,n;for(t=0;t<_;t++)n=M[t],e=e.replace(n[0],n[1]);return A+e.replace(O,j)+A}function I(e,t){return e.replace(/^/gm,t)}function q(t,n,r){function M(e,t){var a=e[t],f=B(a),y=[],A=r?L:k,O,_,D,P,H;o(a)&&s(a.toJSON)?a=a.toJSON(t):f===g&&(a=l(a)),s(i)&&(a=i.call(e,t,a)),a!==e[t]&&(f=B(a));switch(f){case g:case h:break;case d:return F(a);case v:return isFinite(a)?a+b:p;case m:return a+b;case p:return p;default:return undefined}for(_=c.length-1;_>=0;--_)if(c[_]===a)throw new Error("JSON.stringify. Cyclical reference");O=u(a),c.push(a);if(O)for(_=a.length-1;_>=0;--_)y[_]=M(a,_)||p;else{D=n||a,_=0;for(P in D)D.hasOwnProperty(P)&&(H=M(a,P),H&&(y[_++]=F(P)+A+H))}return c.pop(),r&&y.length?O?S+C+I(y.join(N),r)+C+x:w+C+I(y.join(N),r)+C+E:O?S+y.join(T)+x:w+y.join(T)+E}if(t===undefined)return undefined;var i=s(n)?n:null,f=a.call(r).match(/String|Number/)||[],l=e.JSON.dateToString,c=[],y,A,O;P={},H=e.JSON.charCacheThreshold;if(i||!u(n))n=undefined;if(n){y={};for(A=0,O=n.length;A<O;++A)y[n[A]]=!0;n=y}return r=f[0]==="Number"?(new Array(Math.min(Math.max(0,r),10)+1)).join(" "):(r||b).slice(0,10),M({"":t},"")}var r=n("JSON"),i=e.Lang,s=i.isFunction,o=i.isObject,u=i.isArray,a=Object.prototype.toString,f=a.call(r)==="[object JSON]"&&r,l=!!f,c="undefined",h="object",p="null",d="string",v="number",m="boolean",g="date",y={"undefined":c,string:d,"[object String]":d,number:v,"[object Number]":v,"boolean":m,"[object Boolean]":m,"[object Date]":g,"[object RegExp]":h},b="",w="{",E="}",S="[",x="]",T=",",N=",\n",C="\n",k=":",L=": ",A='"',O=/[\x00-\x07\x0b\x0e-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,M=[[/\\/g,"\\\\"],[/\"/g,'\\"'],[/\x08/g,"\\b"],[/\x09/g,"\\t"],[/\x0a/g,"\\n"],[/\x0c/g,"\\f"],[/\x0d/g,"\\r"]],_=M.length,D={},P,H;if(f)try{l="0"===f.stringify(0)}catch(R){l=!1}e.mix(e.namespace("JSON"),{useNativeStringify:l,dateToString:function(e){function t(e){return e<10?"0"+e:e}return e.getUTCFullYear()+"-"+t(e.getUTCMonth()+1)+"-"+t(e.getUTCDate())+"T"+t(e.getUTCHours())+k+t(e.getUTCMinutes())+k+t(e.getUTCSeconds())+"Z"},stringify:function(t,n,r){return f&&e.JSON.useNativeStringify?f.stringify(t,n,r):q(t,n,r)},charCacheThreshold:100})},"3.7.3",{requires:["yui-base"]});