From 47a9882cddeb1e8529e07af9736218075372b8ac Mon Sep 17 00:00:00 2001 From: Douglas Crockford Date: Thu, 20 Oct 2011 11:52:56 -0700 Subject: [PATCH] hygiene --- json2.js | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/json2.js b/json2.js index eda9e0c..2dbf60d 100755 --- a/json2.js +++ b/json2.js @@ -1,6 +1,6 @@ /* - json2.js - 2011-08-30 + http://www.JSON.org/json2.js + 2011-10-19 Public Domain. @@ -146,7 +146,7 @@ redistribute. */ -/*jslint evil: true, regexp: true, unparam: true */ +/*jslint evil: true, regexp: true */ /*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply, call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, @@ -176,13 +176,14 @@ if (!JSON) { Date.prototype.toJSON = function (key) { - 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; + 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 = @@ -218,8 +219,9 @@ if (!JSON) { escapable.lastIndex = 0; return escapable.test(string) ? '"' + string.replace(escapable, function (a) { var c = meta[a]; - return typeof c === 'string' ? c : - '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); + return typeof c === 'string' + ? c + : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); }) + '"' : '"' + string + '"'; } @@ -303,9 +305,11 @@ if (!JSON) { // Join all of the elements together, separated with commas, and wrap them in // brackets. - v = partial.length === 0 ? '[]' : gap ? - '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : - '[' + partial.join(',') + ']'; + v = partial.length === 0 + ? '[]' + : gap + ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' + : '[' + partial.join(',') + ']'; gap = mind; return v; } @@ -340,9 +344,11 @@ if (!JSON) { // Join all of the member texts together, separated with commas, // and wrap them in braces. - v = partial.length === 0 ? '{}' : gap ? - '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' : - '{' + partial.join(',') + '}'; + v = partial.length === 0 + ? '{}' + : gap + ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' + : '{' + partial.join(',') + '}'; gap = mind; return v; } @@ -468,8 +474,9 @@ if (!JSON) { // In the optional fourth stage, we recursively walk the new structure, passing // each name/value pair to a reviver function for possible transformation. - return typeof reviver === 'function' ? - walk({'': j}, '') : j; + return typeof reviver === 'function' + ? walk({'': j}, '') + : j; } // If the text is not JSON parseable, then a SyntaxError is thrown.