Make WordPress Core

Ticket #26913: json.patch

File json.patch, 10.4 KB (added by mgibbs189, 11 years ago)
  • json2.js

     
    11/*
    2     http://www.JSON.org/json2.js
    3     2011-02-23
     2    json2.js
     3    2013-05-26
    44
    55    Public Domain.
    66
     
    146146    redistribute.
    147147*/
    148148
    149 /*jslint evil: true, strict: false, regexp: false */
     149/*jslint evil: true, regexp: true */
    150150
    151151/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
    152152    call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
     
    159159// Create a JSON object only if one does not already exist. We create the
    160160// methods in a closure to avoid creating global variables.
    161161
    162 var JSON;
    163 if (!JSON) {
     162if (typeof JSON !== 'object') {
    164163    JSON = {};
    165164}
    166165
    167166(function () {
    168     "use strict";
     167    'use strict';
    169168
    170169    function f(n) {
    171170        // Format integers to have at least two digits.
     
    174173
    175174    if (typeof Date.prototype.toJSON !== 'function') {
    176175
    177         Date.prototype.toJSON = function (key) {
     176        Date.prototype.toJSON = function () {
    178177
    179             return isFinite(this.valueOf()) ?
    180                 this.getUTCFullYear()     + '-' +
    181                 f(this.getUTCMonth() + 1) + '-' +
    182                 f(this.getUTCDate())      + 'T' +
    183                 f(this.getUTCHours())     + ':' +
    184                 f(this.getUTCMinutes())   + ':' +
    185                 f(this.getUTCSeconds())   + 'Z' : null;
     178            return isFinite(this.valueOf())
     179                ? this.getUTCFullYear()     + '-' +
     180                    f(this.getUTCMonth() + 1) + '-' +
     181                    f(this.getUTCDate())      + 'T' +
     182                    f(this.getUTCHours())     + ':' +
     183                    f(this.getUTCMinutes())   + ':' +
     184                    f(this.getUTCSeconds())   + 'Z'
     185                : null;
    186186        };
    187187
    188188        String.prototype.toJSON      =
    189189            Number.prototype.toJSON  =
    190             Boolean.prototype.toJSON = function (key) {
     190            Boolean.prototype.toJSON = function () {
    191191                return this.valueOf();
    192192            };
    193193    }
     
    218218        escapable.lastIndex = 0;
    219219        return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
    220220            var c = meta[a];
    221             return typeof c === 'string' ? c :
    222                 '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
     221            return typeof c === 'string'
     222                ? c
     223                : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
    223224        }) + '"' : '"' + string + '"';
    224225    }
    225226
     
    303304// Join all of the elements together, separated with commas, and wrap them in
    304305// brackets.
    305306
    306                 v = partial.length === 0 ? '[]' : gap ?
    307                     '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
    308                     '[' + partial.join(',') + ']';
     307                v = partial.length === 0
     308                    ? '[]'
     309                    : gap
     310                    ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
     311                    : '[' + partial.join(',') + ']';
    309312                gap = mind;
    310313                return v;
    311314            }
     
    340343// Join all of the member texts together, separated with commas,
    341344// and wrap them in braces.
    342345
    343             v = partial.length === 0 ? '{}' : gap ?
    344                 '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
    345                 '{' + partial.join(',') + '}';
     346            v = partial.length === 0
     347                ? '{}'
     348                : gap
     349                ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
     350                : '{' + partial.join(',') + '}';
    346351            gap = mind;
    347352            return v;
    348353        }
     
    468473// In the optional fourth stage, we recursively walk the new structure, passing
    469474// each name/value pair to a reviver function for possible transformation.
    470475
    471                 return typeof reviver === 'function' ?
    472                     walk({'': j}, '') : j;
     476                return typeof reviver === 'function'
     477                    ? walk({'': j}, '')
     478                    : j;
    473479            }
    474480
    475481// If the text is not JSON parseable, then a SyntaxError is thrown.
     
    477483            throw new SyntaxError('JSON.parse');
    478484        };
    479485    }
    480 }());
     486}());
     487 No newline at end of file
  • json2.min.js

     
    1 var JSON;JSON||(JSON={}),function(){"use strict";function f(a){return 10>a?"0"+a:a}function quote(a){return escapable.lastIndex=0,escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return"string"==typeof b?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function str(a,b){var c,d,e,f,g,h=gap,i=b[a];switch(i&&"object"==typeof i&&"function"==typeof i.toJSON&&(i=i.toJSON(a)),"function"==typeof rep&&(i=rep.call(b,a,i)),typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";if(gap+=indent,g=[],"[object Array]"===Object.prototype.toString.apply(i)){for(f=i.length,c=0;f>c;c+=1)g[c]=str(c,i)||"null";return e=0===g.length?"[]":gap?"[\n"+gap+g.join(",\n"+gap)+"\n"+h+"]":"["+g.join(",")+"]",gap=h,e}if(rep&&"object"==typeof rep)for(f=rep.length,c=0;f>c;c+=1)"string"==typeof rep[c]&&(d=rep[c],e=str(d,i),e&&g.push(quote(d)+(gap?": ":":")+e));else for(d in i)Object.prototype.hasOwnProperty.call(i,d)&&(e=str(d,i),e&&g.push(quote(d)+(gap?": ":":")+e));return e=0===g.length?"{}":gap?"{\n"+gap+g.join(",\n"+gap)+"\n"+h+"}":"{"+g.join(",")+"}",gap=h,e}}"function"!=typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()});var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","  ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;"function"!=typeof JSON.stringify&&(JSON.stringify=function(a,b,c){var d;if(gap="",indent="","number"==typeof c)for(d=0;c>d;d+=1)indent+=" ";else"string"==typeof c&&(indent=c);if(rep=b,b&&"function"!=typeof b&&("object"!=typeof b||"number"!=typeof b.length))throw new Error("JSON.stringify");return str("",{"":a})}),"function"!=typeof JSON.parse&&(JSON.parse=function(text,reviver){function walk(a,b){var c,d,e=a[b];if(e&&"object"==typeof e)for(c in e)Object.prototype.hasOwnProperty.call(e,c)&&(d=walk(e,c),void 0!==d?e[c]=d:delete e[c]);return reviver.call(a,b,e)}var j;if(text=String(text),cx.lastIndex=0,cx.test(text)&&(text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})),/^[\],:{}\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,"")))return j=eval("("+text+")"),"function"==typeof reviver?walk({"":j},""):j;throw new SyntaxError("JSON.parse")})}();
    2  No newline at end of file
     1if(typeof JSON!=="object"){JSON={}}(function(){"use strict";function f(e){return e<10?"0"+e:e}function quote(e){escapable.lastIndex=0;return escapable.test(e)?'"'+e.replace(escapable,function(e){var t=meta[e];return typeof t==="string"?t:"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}function str(e,t){var n,r,i,s,o=gap,u,a=t[e];if(a&&typeof a==="object"&&typeof a.toJSON==="function"){a=a.toJSON(e)}if(typeof rep==="function"){a=rep.call(t,e,a)}switch(typeof a){case"string":return quote(a);case"number":return isFinite(a)?String(a):"null";case"boolean":case"null":return String(a);case"object":if(!a){return"null"}gap+=indent;u=[];if(Object.prototype.toString.apply(a)==="[object Array]"){s=a.length;for(n=0;n<s;n+=1){u[n]=str(n,a)||"null"}i=u.length===0?"[]":gap?"[\n"+gap+u.join(",\n"+gap)+"\n"+o+"]":"["+u.join(",")+"]";gap=o;return i}if(rep&&typeof rep==="object"){s=rep.length;for(n=0;n<s;n+=1){if(typeof rep[n]==="string"){r=rep[n];i=str(r,a);if(i){u.push(quote(r)+(gap?": ":":")+i)}}}}else{for(r in a){if(Object.prototype.hasOwnProperty.call(a,r)){i=str(r,a);if(i){u.push(quote(r)+(gap?": ":":")+i)}}}}i=u.length===0?"{}":gap?"{\n"+gap+u.join(",\n"+gap)+"\n"+o+"}":"{"+u.join(",")+"}";gap=o;return i}}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;if(typeof JSON.stringify!=="function"){JSON.stringify=function(e,t,n){var r;gap="";indent="";if(typeof n==="number"){for(r=0;r<n;r+=1){indent+=" "}}else if(typeof n==="string"){indent=n}rep=t;if(t&&typeof t!=="function"&&(typeof t!=="object"||typeof t.length!=="number")){throw new Error("JSON.stringify")}return str("",{"":e})}}if(typeof JSON.parse!=="function"){JSON.parse=function(text,reviver){function walk(e,t){var n,r,i=e[t];if(i&&typeof i==="object"){for(n in i){if(Object.prototype.hasOwnProperty.call(i,n)){r=walk(i,n);if(r!==undefined){i[n]=r}else{delete i[n]}}}}return reviver.call(e,t,i)}var j;text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(e){return"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)})}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,""))){j=eval("("+text+")");return typeof reviver==="function"?walk({"":j},""):j}throw new SyntaxError("JSON.parse")}}})()
     2 No newline at end of file