Skip to content

Commit 4982ffb

Browse files
Anticipating new JSLint
1 parent 3d7767b commit 4982ffb

File tree

5 files changed

+181
-134
lines changed

5 files changed

+181
-134
lines changed

cycle.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
cycle.js
3-
2013-02-19
3+
2015-02-25
44
55
Public Domain.
66
@@ -13,9 +13,10 @@
1313
NOT CONTROL.
1414
*/
1515

16-
/*jslint evil: true, regexp: true */
16+
/*jslint eval, for */
1717

18-
/*members $ref, apply, call, decycle, hasOwnProperty, length, prototype, push,
18+
/*property
19+
$ref, apply, call, decycle, hasOwnProperty, length, prototype, push,
1920
retrocycle, stringify, test, toString
2021
*/
2122

@@ -55,9 +56,9 @@ if (typeof JSON.decycle !== 'function') {
5556

5657
if (typeof value === 'object' && value !== null &&
5758
!(value instanceof Boolean) &&
58-
!(value instanceof Date) &&
59-
!(value instanceof Number) &&
60-
!(value instanceof RegExp) &&
59+
!(value instanceof Date) &&
60+
!(value instanceof Number) &&
61+
!(value instanceof RegExp) &&
6162
!(value instanceof String)) {
6263

6364
// If the value is an object or array, look to see if we have already
@@ -90,7 +91,7 @@ if (typeof JSON.decycle !== 'function') {
9091
for (name in value) {
9192
if (Object.prototype.hasOwnProperty.call(value, name)) {
9293
nu[name] = derez(value[name],
93-
path + '[' + JSON.stringify(name) + ']');
94+
path + '[' + JSON.stringify(name) + ']');
9495
}
9596
}
9697
}
@@ -125,8 +126,7 @@ if (typeof JSON.retrocycle !== 'function') {
125126
// return JSON.retrocycle(JSON.parse(s));
126127
// produces an array containing a single element which is the array itself.
127128

128-
var px =
129-
/^\$(?:\[(?:\d+|\"(?:[^\\\"\u0000-\u001f]|\\([\\\"\/bfnrt]|u[0-9a-zA-Z]{4}))*\")\])*$/;
129+
var px = /^\$(?:\[(?:\d+|\"(?:[^\\\"\u0000-\u001f]|\\([\\\"\/bfnrt]|u[0-9a-zA-Z]{4}))*\")\])*$/;
130130

131131
(function rez(value) {
132132

json.js

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
json.js
3-
2014-02-04
3+
2014-02-25
44
55
Public Domain
66
@@ -183,16 +183,15 @@
183183
redistribute.
184184
*/
185185

186-
/*jslint evil: true, regexp: true, unparam: true */
186+
/*jslint eval, for, this */
187187

188-
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
189-
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
188+
/*property
189+
JSON, apply, call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
190190
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
191191
lastIndex, length, parse, parseJSON, prototype, push, replace, slice,
192192
stringify, test, toJSON, toJSONString, toString, valueOf
193193
*/
194194

195-
196195
// Create a JSON object only if one does not already exist. We create the
197196
// methods in a closure to avoid creating global variables.
198197

@@ -205,28 +204,32 @@ if (typeof JSON !== 'object') {
205204

206205
function f(n) {
207206
// Format integers to have at least two digits.
208-
return n < 10 ? '0' + n : n;
207+
return n < 10
208+
? '0' + n
209+
: n;
210+
}
211+
212+
function this_value() {
213+
return this.valueOf();
209214
}
210215

211216
if (typeof Date.prototype.toJSON !== 'function') {
212217

213-
Date.prototype.toJSON = function (key) {
218+
Date.prototype.toJSON = function (ignore) {
214219

215220
return isFinite(this.valueOf())
216-
? this.getUTCFullYear() + '-' +
221+
? this.getUTCFullYear() + '-' +
217222
f(this.getUTCMonth() + 1) + '-' +
218-
f(this.getUTCDate()) + 'T' +
219-
f(this.getUTCHours()) + ':' +
220-
f(this.getUTCMinutes()) + ':' +
221-
f(this.getUTCSeconds()) + 'Z'
222-
: null;
223+
f(this.getUTCDate()) + 'T' +
224+
f(this.getUTCHours()) + ':' +
225+
f(this.getUTCMinutes()) + ':' +
226+
f(this.getUTCSeconds()) + 'Z'
227+
: null;
223228
};
224229

225-
String.prototype.toJSON =
226-
Number.prototype.toJSON =
227-
Boolean.prototype.toJSON = function (key) {
228-
return this.valueOf();
229-
};
230+
Boolean.prototype.toJSON = this_value;
231+
Number.prototype.toJSON = this_value;
232+
String.prototype.toJSON = this_value;
230233
}
231234

232235
var cx,
@@ -245,12 +248,14 @@ if (typeof JSON !== 'object') {
245248
// sequences.
246249

247250
escapable.lastIndex = 0;
248-
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
251+
return escapable.test(string)
252+
? '"' + string.replace(escapable, function (a) {
249253
var c = meta[a];
250254
return typeof c === 'string'
251-
? c
252-
: '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
253-
}) + '"' : '"' + string + '"';
255+
? c
256+
: '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
257+
}) + '"'
258+
: '"' + string + '"';
254259
}
255260

256261

@@ -290,7 +295,9 @@ if (typeof JSON !== 'object') {
290295

291296
// JSON numbers must be finite. Encode non-finite numbers as null.
292297

293-
return isFinite(value) ? String(value) : 'null';
298+
return isFinite(value)
299+
? String(value)
300+
: 'null';
294301

295302
case 'boolean':
296303
case 'null':
@@ -334,10 +341,10 @@ if (typeof JSON !== 'object') {
334341
// brackets.
335342

336343
v = partial.length === 0
337-
? '[]'
338-
: gap
339-
? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
340-
: '[' + partial.join(',') + ']';
344+
? '[]'
345+
: gap
346+
? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
347+
: '[' + partial.join(',') + ']';
341348
gap = mind;
342349
return v;
343350
}
@@ -351,7 +358,9 @@ if (typeof JSON !== 'object') {
351358
if (typeof k === 'string') {
352359
v = str(k, value);
353360
if (v) {
354-
partial.push(quote(k) + (gap ? ': ' : ':') + v);
361+
partial.push(quote(k) + (gap
362+
? ': '
363+
: ':') + v);
355364
}
356365
}
357366
}
@@ -363,7 +372,9 @@ if (typeof JSON !== 'object') {
363372
if (Object.prototype.hasOwnProperty.call(value, k)) {
364373
v = str(k, value);
365374
if (v) {
366-
partial.push(quote(k) + (gap ? ': ' : ':') + v);
375+
partial.push(quote(k) + (gap
376+
? ': '
377+
: ':') + v);
367378
}
368379
}
369380
}
@@ -372,10 +383,11 @@ if (typeof JSON !== 'object') {
372383
// Join all of the member texts together, separated with commas,
373384
// and wrap them in braces.
374385

375-
v = partial.length === 0 ? '{}'
376-
: gap
377-
? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
378-
: '{' + partial.join(',') + '}';
386+
v = partial.length === 0
387+
? '{}'
388+
: gap
389+
? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
390+
: '{' + partial.join(',') + '}';
379391
gap = mind;
380392
return v;
381393
}
@@ -384,14 +396,14 @@ if (typeof JSON !== 'object') {
384396
// If the JSON object does not yet have a stringify method, give it one.
385397

386398
if (typeof JSON.stringify !== 'function') {
387-
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
399+
escapable = /[\\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
388400
meta = { // table of character substitutions
389401
'\b': '\\b',
390402
'\t': '\\t',
391403
'\n': '\\n',
392404
'\f': '\\f',
393405
'\r': '\\r',
394-
'"' : '\\"',
406+
'"': '\\"',
395407
'\\': '\\\\'
396408
};
397409
JSON.stringify = function (value, replacer, space) {
@@ -480,7 +492,7 @@ if (typeof JSON !== 'object') {
480492
if (cx.test(text)) {
481493
text = text.replace(cx, function (a) {
482494
return '\\u' +
483-
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
495+
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
484496
});
485497
}
486498

@@ -497,10 +509,11 @@ if (typeof JSON !== 'object') {
497509
// we look to see that the remaining characters are only whitespace or ']' or
498510
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
499511

500-
if (/^[\],:{}\s]*$/
501-
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
502-
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
503-
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
512+
if (/^[\],:{}\s]*$/.test(
513+
text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
514+
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
515+
.replace(/(?:^|:|,)(?:\s*\[)+/g, '')
516+
)) {
504517

505518
// In the third stage we use the eval function to compile the text into a
506519
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
@@ -513,8 +526,8 @@ if (typeof JSON !== 'object') {
513526
// each name/value pair to a reviver function for possible transformation.
514527

515528
return typeof reviver === 'function'
516-
? walk({'': j}, '')
517-
: j;
529+
? walk({'': j}, '')
530+
: j;
518531
}
519532

520533
// If the text is not JSON parseable, then a SyntaxError is thrown.

0 commit comments

Comments
 (0)