Skip to content

Commit

Permalink
Always use strict equality.
Browse files Browse the repository at this point in the history
  • Loading branch information
medanat committed Jul 25, 2018
1 parent 41257aa commit 68ece87
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions lib/application.js
Expand Up @@ -182,7 +182,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 @@ -213,7 +213,7 @@ function respond(ctx) {
return res.end();
}

if ('HEAD' == ctx.method) {
if ('HEAD' === ctx.method) {
if (!res.headersSent && isJSON(body)) {
ctx.length = Buffer.byteLength(JSON.stringify(body));
}
Expand All @@ -232,7 +232,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 @@ -143,10 +143,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 @@ -269,7 +269,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(':')[0];
},

Expand Down Expand Up @@ -310,10 +310,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 @@ -385,7 +385,7 @@ module.exports = {

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

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

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

/**
Expand Down
16 changes: 8 additions & 8 deletions lib/response.js
Expand Up @@ -83,7 +83,7 @@ module.exports = {
set status(code) {
if (this.headerSent) return;

assert('number' == typeof code, 'status code must be a number');
assert('number' === typeof code, 'status code must be a number');
assert(statuses[code], `invalid status code: ${code}`);
this._explicitStatus = true;
this.res.statusCode = code;
Expand Down Expand Up @@ -151,7 +151,7 @@ module.exports = {
const setType = !this.header['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 @@ -165,12 +165,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 @@ -205,7 +205,7 @@ module.exports = {

if (null == len) {
if (!body) return;
if ('string' == typeof body) return Buffer.byteLength(body);
if ('string' === typeof body) return Buffer.byteLength(body);
if (Buffer.isBuffer(body)) return body.length;
if (isJSON(body)) return Buffer.byteLength(JSON.stringify(body));
return;
Expand Down Expand Up @@ -259,7 +259,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', url);

// status
Expand Down Expand Up @@ -326,7 +326,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 @@ -438,7 +438,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 68ece87

Please sign in to comment.