Skip to content

Commit

Permalink
hygiene
Browse files Browse the repository at this point in the history
  • Loading branch information
douglascrockford committed Oct 20, 2011
1 parent 36df833 commit 47a9882
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions json2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
json2.js
2011-08-30
http://www.JSON.org/json2.js
2011-10-19
Public Domain.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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 + '"';
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 47a9882

Please sign in to comment.