Skip to content

Commit

Permalink
Always use strict equality. (#1225)
Browse files Browse the repository at this point in the history
  • Loading branch information
medanat committed May 15, 2020
1 parent 8d52105 commit 143d8f7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/application.js
Expand Up @@ -197,7 +197,7 @@ module.exports = class Application extends Emitter {
onerror(err) {
if (!(err instanceof Error)) throw new TypeError(util.format('non-error thrown: %j', err));

if (404 == err.status || err.expose) return;
if (404 === err.status || err.expose) return;
if (this.silent) return;

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

// responses
if (Buffer.isBuffer(body)) return res.end(body);
if ('string' == typeof body) return res.end(body);
if ('string' === typeof body) return res.end(body);
if (body instanceof Stream) return body.pipe(res);

// body: json
Expand Down
4 changes: 2 additions & 2 deletions lib/context.js
Expand Up @@ -144,10 +144,10 @@ const proto = module.exports = {
this.type = 'text';

// ENOENT support
if ('ENOENT' == err.code) err.status = 404;
if ('ENOENT' === err.code) err.status = 404;

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

// respond
const code = statuses[err.status];
Expand Down
10 changes: 5 additions & 5 deletions lib/request.js
Expand Up @@ -272,7 +272,7 @@ module.exports = {
get hostname() {
const host = this.host;
if (!host) return '';
if ('[' == host[0]) return this.URL.hostname || ''; // IPv6
if ('[' === host[0]) return this.URL.hostname || ''; // IPv6
return host.split(':', 1)[0];
},

Expand Down Expand Up @@ -311,10 +311,10 @@ module.exports = {
const s = this.ctx.status;

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

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

Expand Down Expand Up @@ -382,7 +382,7 @@ module.exports = {

get length() {
const len = this.get('Content-Length');
if (len == '') return;
if (len === '') return;
return ~~len;
},

Expand Down Expand Up @@ -415,7 +415,7 @@ module.exports = {
*/

get secure() {
return 'https' == this.protocol;
return 'https' === this.protocol;
},

/**
Expand Down
12 changes: 6 additions & 6 deletions lib/response.js
Expand Up @@ -153,7 +153,7 @@ module.exports = {
const setType = !this.has('Content-Type');

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

// stream
if ('function' == typeof val.pipe) {
if ('function' === typeof val.pipe) {
onFinish(this.res, destroy.bind(null, val));
ensureErrorHandler(val, err => this.ctx.onerror(err));

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

if (setType) this.type = 'bin';
return;
Expand Down Expand Up @@ -258,7 +258,7 @@ module.exports = {

redirect(url, alt) {
// location
if ('back' == url) url = this.ctx.get('Referrer') || alt || '/';
if ('back' === url) url = this.ctx.get('Referrer') || alt || '/';
this.set('Location', encodeUrl(url));

// status
Expand Down Expand Up @@ -325,7 +325,7 @@ module.exports = {
*/

set lastModified(val) {
if ('string' == typeof val) val = new Date(val);
if ('string' === typeof val) val = new Date(val);
this.set('Last-Modified', val.toUTCString());
},

Expand Down Expand Up @@ -458,7 +458,7 @@ module.exports = {
set(field, val) {
if (this.headerSent) return;

if (2 == arguments.length) {
if (2 === arguments.length) {
if (Array.isArray(val)) val = val.map(v => typeof v === 'string' ? v : String(v));
else if (typeof val !== 'string') val = String(val);
this.res.setHeader(field, val);
Expand Down

0 comments on commit 143d8f7

Please sign in to comment.