Skip to content

Commit 143d8f7

Browse files
authored
Always use strict equality. (#1225)
1 parent 8d52105 commit 143d8f7

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

lib/application.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ module.exports = class Application extends Emitter {
197197
onerror(err) {
198198
if (!(err instanceof Error)) throw new TypeError(util.format('non-error thrown: %j', err));
199199

200-
if (404 == err.status || err.expose) return;
200+
if (404 === err.status || err.expose) return;
201201
if (this.silent) return;
202202

203203
const msg = err.stack || err.toString();
@@ -257,7 +257,7 @@ function respond(ctx) {
257257

258258
// responses
259259
if (Buffer.isBuffer(body)) return res.end(body);
260-
if ('string' == typeof body) return res.end(body);
260+
if ('string' === typeof body) return res.end(body);
261261
if (body instanceof Stream) return body.pipe(res);
262262

263263
// body: json

lib/context.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ const proto = module.exports = {
144144
this.type = 'text';
145145

146146
// ENOENT support
147-
if ('ENOENT' == err.code) err.status = 404;
147+
if ('ENOENT' === err.code) err.status = 404;
148148

149149
// default to 500
150-
if ('number' != typeof err.status || !statuses[err.status]) err.status = 500;
150+
if ('number' !== typeof err.status || !statuses[err.status]) err.status = 500;
151151

152152
// respond
153153
const code = statuses[err.status];

lib/request.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ module.exports = {
272272
get hostname() {
273273
const host = this.host;
274274
if (!host) return '';
275-
if ('[' == host[0]) return this.URL.hostname || ''; // IPv6
275+
if ('[' === host[0]) return this.URL.hostname || ''; // IPv6
276276
return host.split(':', 1)[0];
277277
},
278278

@@ -311,10 +311,10 @@ module.exports = {
311311
const s = this.ctx.status;
312312

313313
// GET or HEAD for weak freshness validation only
314-
if ('GET' != method && 'HEAD' != method) return false;
314+
if ('GET' !== method && 'HEAD' !== method) return false;
315315

316316
// 2xx or 304 as per rfc2616 14.26
317-
if ((s >= 200 && s < 300) || 304 == s) {
317+
if ((s >= 200 && s < 300) || 304 === s) {
318318
return fresh(this.header, this.response.header);
319319
}
320320

@@ -382,7 +382,7 @@ module.exports = {
382382

383383
get length() {
384384
const len = this.get('Content-Length');
385-
if (len == '') return;
385+
if (len === '') return;
386386
return ~~len;
387387
},
388388

@@ -415,7 +415,7 @@ module.exports = {
415415
*/
416416

417417
get secure() {
418-
return 'https' == this.protocol;
418+
return 'https' === this.protocol;
419419
},
420420

421421
/**

lib/response.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ module.exports = {
153153
const setType = !this.has('Content-Type');
154154

155155
// string
156-
if ('string' == typeof val) {
156+
if ('string' === typeof val) {
157157
if (setType) this.type = /^\s*</.test(val) ? 'html' : 'text';
158158
this.length = Buffer.byteLength(val);
159159
return;
@@ -167,12 +167,12 @@ module.exports = {
167167
}
168168

169169
// stream
170-
if ('function' == typeof val.pipe) {
170+
if ('function' === typeof val.pipe) {
171171
onFinish(this.res, destroy.bind(null, val));
172172
ensureErrorHandler(val, err => this.ctx.onerror(err));
173173

174174
// overwriting
175-
if (null != original && original != val) this.remove('Content-Length');
175+
if (null != original && original !== val) this.remove('Content-Length');
176176

177177
if (setType) this.type = 'bin';
178178
return;
@@ -258,7 +258,7 @@ module.exports = {
258258

259259
redirect(url, alt) {
260260
// location
261-
if ('back' == url) url = this.ctx.get('Referrer') || alt || '/';
261+
if ('back' === url) url = this.ctx.get('Referrer') || alt || '/';
262262
this.set('Location', encodeUrl(url));
263263

264264
// status
@@ -325,7 +325,7 @@ module.exports = {
325325
*/
326326

327327
set lastModified(val) {
328-
if ('string' == typeof val) val = new Date(val);
328+
if ('string' === typeof val) val = new Date(val);
329329
this.set('Last-Modified', val.toUTCString());
330330
},
331331

@@ -458,7 +458,7 @@ module.exports = {
458458
set(field, val) {
459459
if (this.headerSent) return;
460460

461-
if (2 == arguments.length) {
461+
if (2 === arguments.length) {
462462
if (Array.isArray(val)) val = val.map(v => typeof v === 'string' ? v : String(v));
463463
else if (typeof val !== 'string') val = String(val);
464464
this.res.setHeader(field, val);

0 commit comments

Comments
 (0)