Skip to content

Commit 9772195

Browse files
billouboqdarrachequesne
authored andcommittedDec 17, 2016
[refactor] Use strict equality when possible (#52)
1 parent 64455b4 commit 9772195

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed
 

‎binary.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ exports.deconstructPacket = function(packet){
3434
newData[i] = _deconstructPacket(data[i]);
3535
}
3636
return newData;
37-
} else if ('object' == typeof data && !(data instanceof Date)) {
37+
} else if (typeof data === 'object' && !(data instanceof Date)) {
3838
var newData = {};
3939
for (var key in data) {
4040
newData[key] = _deconstructPacket(data[key]);
@@ -71,7 +71,7 @@ exports.reconstructPacket = function(packet, buffers) {
7171
data[i] = _reconstructPacket(data[i]);
7272
}
7373
return data;
74-
} else if (data && 'object' == typeof data) {
74+
} else if (data && 'object' === typeof data) {
7575
for (var key in data) {
7676
data[key] = _reconstructPacket(data[key]);
7777
}
@@ -125,7 +125,7 @@ exports.removeBlobs = function(data, callback) {
125125
for (var i = 0; i < obj.length; i++) {
126126
_removeBlobs(obj[i], i, obj);
127127
}
128-
} else if (obj && 'object' == typeof obj && !isBuf(obj)) { // and object
128+
} else if (obj && 'object' === typeof obj && !isBuf(obj)) { // and object
129129
for (var key in obj) {
130130
_removeBlobs(obj[key], key, obj);
131131
}

‎index.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function Encoder() {}
126126
Encoder.prototype.encode = function(obj, callback){
127127
debug('encoding packet %j', obj);
128128

129-
if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) {
129+
if (exports.BINARY_EVENT === obj.type || exports.BINARY_ACK === obj.type) {
130130
encodeAsBinary(obj, callback);
131131
}
132132
else {
@@ -151,14 +151,14 @@ function encodeAsString(obj) {
151151
str += obj.type;
152152

153153
// attachments if we have them
154-
if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) {
154+
if (exports.BINARY_EVENT === obj.type || exports.BINARY_ACK === obj.type) {
155155
str += obj.attachments;
156156
str += '-';
157157
}
158158

159159
// if we have a namespace other than `/`
160160
// we append it followed by a comma `,`
161-
if (obj.nsp && '/' != obj.nsp) {
161+
if (obj.nsp && '/' !== obj.nsp) {
162162
nsp = true;
163163
str += obj.nsp;
164164
}
@@ -233,9 +233,9 @@ Emitter(Decoder.prototype);
233233

234234
Decoder.prototype.add = function(obj) {
235235
var packet;
236-
if ('string' == typeof obj) {
236+
if (typeof obj === 'string') {
237237
packet = decodeString(obj);
238-
if (exports.BINARY_EVENT == packet.type || exports.BINARY_ACK == packet.type) { // binary packet's json
238+
if (exports.BINARY_EVENT === packet.type || exports.BINARY_ACK === packet.type) { // binary packet's json
239239
this.reconstructor = new BinaryReconstructor(packet);
240240

241241
// no attachments, labeled binary but no binary data to follow
@@ -281,24 +281,24 @@ function decodeString(str) {
281281
// look up attachments if type binary
282282
if (exports.BINARY_EVENT == p.type || exports.BINARY_ACK == p.type) {
283283
var buf = '';
284-
while (str.charAt(++i) != '-') {
284+
while (str.charAt(++i) !== '-') {
285285
buf += str.charAt(i);
286286
if (i == str.length) break;
287287
}
288-
if (buf != Number(buf) || str.charAt(i) != '-') {
288+
if (buf != Number(buf) || str.charAt(i) !== '-') {
289289
throw new Error('Illegal attachments');
290290
}
291291
p.attachments = Number(buf);
292292
}
293293

294294
// look up namespace (if any)
295-
if ('/' == str.charAt(i + 1)) {
295+
if ('/' === str.charAt(i + 1)) {
296296
p.nsp = '';
297297
while (++i) {
298298
var c = str.charAt(i);
299-
if (',' == c) break;
299+
if (',' === c) break;
300300
p.nsp += c;
301-
if (i == str.length) break;
301+
if (i === str.length) break;
302302
}
303303
} else {
304304
p.nsp = '/';
@@ -315,7 +315,7 @@ function decodeString(str) {
315315
break;
316316
}
317317
p.id += str.charAt(i);
318-
if (i == str.length) break;
318+
if (i === str.length) break;
319319
}
320320
p.id = Number(p.id);
321321
}
@@ -336,7 +336,7 @@ function tryParse(p, str) {
336336
return error();
337337
}
338338
return p;
339-
};
339+
}
340340

341341
/**
342342
* Deallocates a parser's resources
@@ -377,7 +377,7 @@ function BinaryReconstructor(packet) {
377377

378378
BinaryReconstructor.prototype.takeBinaryData = function(binData) {
379379
this.buffers.push(binData);
380-
if (this.buffers.length == this.reconPack.attachments) { // done with buffer list
380+
if (this.buffers.length === this.reconPack.attachments) { // done with buffer list
381381
var packet = binary.reconstructPacket(this.reconPack, this.buffers);
382382
this.finishedReconstruction();
383383
return packet;

0 commit comments

Comments
 (0)
Please sign in to comment.