mirror of
https://github.com/donl/JSON-js.git
synced 2026-05-25 22:06:23 -06:00
hygiene
This commit is contained in:
parent
ff55d8d451
commit
e39db4b7e6
3 changed files with 29 additions and 23 deletions
42
json.js
42
json.js
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
json.js
|
||||
2012-10-08
|
||||
2013-05-26
|
||||
|
||||
Public Domain
|
||||
|
||||
|
|
@ -212,13 +212,14 @@ if (typeof JSON !== 'object') {
|
|||
|
||||
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 =
|
||||
|
|
@ -254,8 +255,9 @@ if (typeof JSON !== 'object') {
|
|||
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 + '"';
|
||||
}
|
||||
|
||||
|
|
@ -339,9 +341,11 @@ if (typeof JSON !== 'object') {
|
|||
// 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;
|
||||
}
|
||||
|
|
@ -376,9 +380,10 @@ if (typeof JSON !== 'object') {
|
|||
// 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;
|
||||
}
|
||||
|
|
@ -504,8 +509,9 @@ if (typeof JSON !== 'object') {
|
|||
// 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.
|
||||
|
|
|
|||
6
json2.js
6
json2.js
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
json2.js
|
||||
2012-10-08
|
||||
2013-05-26
|
||||
|
||||
Public Domain.
|
||||
|
||||
|
|
@ -173,7 +173,7 @@ if (typeof JSON !== 'object') {
|
|||
|
||||
if (typeof Date.prototype.toJSON !== 'function') {
|
||||
|
||||
Date.prototype.toJSON = function (key) {
|
||||
Date.prototype.toJSON = function () {
|
||||
|
||||
return isFinite(this.valueOf())
|
||||
? this.getUTCFullYear() + '-' +
|
||||
|
|
@ -187,7 +187,7 @@ if (typeof JSON !== 'object') {
|
|||
|
||||
String.prototype.toJSON =
|
||||
Number.prototype.toJSON =
|
||||
Boolean.prototype.toJSON = function (key) {
|
||||
Boolean.prototype.toJSON = function () {
|
||||
return this.valueOf();
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
json_parse_state.js
|
||||
2012-06-01
|
||||
2013-05-26
|
||||
|
||||
Public Domain.
|
||||
|
||||
|
|
@ -46,7 +46,7 @@
|
|||
NOT CONTROL.
|
||||
*/
|
||||
|
||||
/*jslint regexp: false*/
|
||||
/*jslint regexp: true, unparam: true */
|
||||
|
||||
/*members "", "\"", ",", "\/", ":", "[", "\\", "]", acomma, avalue, b,
|
||||
call, colon, container, exec, f, false, firstavalue, firstokey,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue