11// json2.js
2- // 2016-10-28
2+ // 2017-06-12
33// Public Domain.
44// NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
5- // See http://www.JSON.org/js.html
6- // This code should be minified before deployment.
7- // See http://javascript.crockford.com/jsmin.html
85
96// USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
107// NOT CONTROL.
113110// a =
114111// /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
115112// if (a) {
116- // return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
117- // +a[5], +a[6]));
113+ // return new Date(Date.UTC(
114+ // +a[1], +a[2] - 1, +a[3], +a[4], +a[5], +a[6]
115+ // ));
118116// }
117+ // return value;
119118// }
120- // return value;
121119// });
122120
123- // myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
124- // var d;
125- // if (typeof value === "string" &&
126- // value.slice(0, 5) === "Date(" &&
127- // value.slice(-1) === ")") {
128- // d = new Date(value.slice(5, -1));
129- // if (d) {
130- // return d;
121+ // myData = JSON.parse(
122+ // "[\"Date(09/09/2001)\"]",
123+ // function (key, value) {
124+ // var d;
125+ // if (
126+ // typeof value === "string"
127+ // && value.slice(0, 5) === "Date("
128+ // && value.slice(-1) === ")"
129+ // ) {
130+ // d = new Date(value.slice(5, -1));
131+ // if (d) {
132+ // return d;
133+ // }
131134// }
135+ // return value;
132136// }
133- // return value;
134- // });
137+ // );
135138
136139// This is a reference implementation. You are free to copy, modify, or
137140// redistribute.
@@ -167,7 +170,7 @@ if (typeof JSON !== "object") {
167170
168171 function f ( n ) {
169172 // Format integers to have at least two digits.
170- return n < 10
173+ return ( n < 10 )
171174 ? "0" + n
172175 : n ;
173176 }
@@ -181,12 +184,20 @@ if (typeof JSON !== "object") {
181184 Date . prototype . toJSON = function ( ) {
182185
183186 return isFinite ( this . valueOf ( ) )
184- ? this . getUTCFullYear ( ) + "-" +
185- f ( this . getUTCMonth ( ) + 1 ) + "-" +
186- f ( this . getUTCDate ( ) ) + "T" +
187- f ( this . getUTCHours ( ) ) + ":" +
188- f ( this . getUTCMinutes ( ) ) + ":" +
189- f ( this . getUTCSeconds ( ) ) + "Z"
187+ ? (
188+ this . getUTCFullYear ( )
189+ + "-"
190+ + f ( this . getUTCMonth ( ) + 1 )
191+ + "-"
192+ + f ( this . getUTCDate ( ) )
193+ + "T"
194+ + f ( this . getUTCHours ( ) )
195+ + ":"
196+ + f ( this . getUTCMinutes ( ) )
197+ + ":"
198+ + f ( this . getUTCSeconds ( ) )
199+ + "Z"
200+ )
190201 : null ;
191202 } ;
192203
@@ -234,8 +245,11 @@ if (typeof JSON !== "object") {
234245
235246// If the value has a toJSON method, call it to obtain a replacement value.
236247
237- if ( value && typeof value === "object" &&
238- typeof value . toJSON === "function" ) {
248+ if (
249+ value
250+ && typeof value === "object"
251+ && typeof value . toJSON === "function"
252+ ) {
239253 value = value . toJSON ( key ) ;
240254 }
241255
@@ -256,7 +270,7 @@ if (typeof JSON !== "object") {
256270
257271// JSON numbers must be finite. Encode non-finite numbers as null.
258272
259- return isFinite ( value )
273+ return ( isFinite ( value ) )
260274 ? String ( value )
261275 : "null" ;
262276
@@ -304,7 +318,14 @@ if (typeof JSON !== "object") {
304318 v = partial . length === 0
305319 ? "[]"
306320 : gap
307- ? "[\n" + gap + partial . join ( ",\n" + gap ) + "\n" + mind + "]"
321+ ? (
322+ "[\n"
323+ + gap
324+ + partial . join ( ",\n" + gap )
325+ + "\n"
326+ + mind
327+ + "]"
328+ )
308329 : "[" + partial . join ( "," ) + "]" ;
309330 gap = mind ;
310331 return v ;
@@ -320,7 +341,7 @@ if (typeof JSON !== "object") {
320341 v = str ( k , value ) ;
321342 if ( v ) {
322343 partial . push ( quote ( k ) + (
323- gap
344+ ( gap )
324345 ? ": "
325346 : ":"
326347 ) + v ) ;
@@ -336,7 +357,7 @@ if (typeof JSON !== "object") {
336357 v = str ( k , value ) ;
337358 if ( v ) {
338359 partial . push ( quote ( k ) + (
339- gap
360+ ( gap )
340361 ? ": "
341362 : ":"
342363 ) + v ) ;
@@ -400,9 +421,10 @@ if (typeof JSON !== "object") {
400421// Otherwise, throw an error.
401422
402423 rep = replacer ;
403- if ( replacer && typeof replacer !== "function" &&
404- ( typeof replacer !== "object" ||
405- typeof replacer . length !== "number" ) ) {
424+ if ( replacer && typeof replacer !== "function" && (
425+ typeof replacer !== "object"
426+ || typeof replacer . length !== "number"
427+ ) ) {
406428 throw new Error ( "JSON.stringify" ) ;
407429 }
408430
@@ -456,8 +478,10 @@ if (typeof JSON !== "object") {
456478 rx_dangerous . lastIndex = 0 ;
457479 if ( rx_dangerous . test ( text ) ) {
458480 text = text . replace ( rx_dangerous , function ( a ) {
459- return "\\u" +
460- ( "0000" + a . charCodeAt ( 0 ) . toString ( 16 ) ) . slice ( - 4 ) ;
481+ return (
482+ "\\u"
483+ + ( "0000" + a . charCodeAt ( 0 ) . toString ( 16 ) ) . slice ( - 4 )
484+ ) ;
461485 } ) ;
462486 }
463487
0 commit comments