Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

hygiene

  • Loading branch information...
commit 47a9882cddeb1e8529e07af9736218075372b8ac 1 parent 36df833
@douglascrockford authored
Showing with 27 additions and 20 deletions.
  1. +27 −20 json2.js
View
47 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.
Please sign in to comment.
Something went wrong with that request. Please try again.